Skip to content

Commit 74bad7d

Browse files
rahulhegdeeerunion
andauthored
fix: replace request-promise-native with node-fetch (#352)
* fix: add version selection to all relevant commands * fix: add version selection for version commands * test: update version tests * refactor: rename from swagger to project * fix: convert all react-promise-native to node-fetch * fix: fixed transition to node-fetch for versions commands * refactor: fix duplicate code * fix: revert for failing tests * fix: delete swagger.json * fix: delete applytoreadme.md * fix: uninstall request and request-promise-native' * chore: changing some test keys that looks real Co-authored-by: Jon Ursenbach <jon@ursenba.ch>
1 parent 31cc6f2 commit 74bad7d

15 files changed

Lines changed: 317 additions & 719 deletions

File tree

‎__tests__/cmds/docs.test.js‎

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,11 @@ describe('rdme docs', () => {
8787
...simpleDoc.doc.data,
8888
})
8989
.basicAuth({ user: key })
90-
.reply(200)
90+
.reply(200, {
91+
category,
92+
slug: simpleDoc.slug,
93+
body: simpleDoc.doc.content,
94+
})
9195
.put('/api/v1/docs/another-doc', {
9296
category,
9397
slug: anotherDoc.slug,
@@ -96,17 +100,24 @@ describe('rdme docs', () => {
96100
...anotherDoc.doc.data,
97101
})
98102
.basicAuth({ user: key })
99-
.reply(200);
103+
.reply(200, { category, slug: anotherDoc.slug, body: anotherDoc.doc.content });
100104

101105
const versionMock = nock(config.host)
102106
.get(`/api/v1/version/${version}`)
103107
.basicAuth({ user: key })
104108
.reply(200, { version });
105109

106-
return docs.run({ folder: './__tests__/__fixtures__/existing-docs', key, version }).then(skippedDocs => {
110+
return docs.run({ folder: './__tests__/__fixtures__/existing-docs', key, version }).then(updatedDocs => {
107111
// All docs should have been updated because their hashes from the GET request were different from what they
108112
// are currently.
109-
expect(skippedDocs).toHaveLength(0);
113+
expect(updatedDocs).toStrictEqual([
114+
{
115+
category,
116+
slug: simpleDoc.slug,
117+
body: simpleDoc.doc.content,
118+
},
119+
{ category, slug: anotherDoc.slug, body: anotherDoc.doc.content },
120+
]);
110121

111122
getMocks.done();
112123
updateMocks.done();
@@ -161,7 +172,7 @@ describe('rdme docs', () => {
161172
const postMock = getNockWithVersionHeader(version)
162173
.post(`/api/v1/docs`, { slug, body: doc.content, ...doc.data, lastUpdatedHash: hash })
163174
.basicAuth({ user: key })
164-
.reply(201);
175+
.reply(201, { slug, body: doc.content, ...doc.data, lastUpdatedHash: hash });
165176

166177
const versionMock = nock(config.host)
167178
.get(`/api/v1/version/${version}`)
@@ -207,12 +218,6 @@ describe('rdme docs', () => {
207218
});
208219

209220
const postMocks = getNockWithVersionHeader(version)
210-
.post('/api/v1/docs', { slug, body: doc.content, ...doc.data, lastUpdatedHash: hash })
211-
.basicAuth({ user: key })
212-
.reply(400, {
213-
error: 'DOC_INVALID',
214-
message: "We couldn't save this doc (Path `category` is required.).",
215-
})
216221
.post('/api/v1/docs', { slug: slugTwo, body: docTwo.content, ...docTwo.data, lastUpdatedHash: hashTwo })
217222
.basicAuth({ user: key })
218223
.reply(201, {
@@ -230,6 +235,12 @@ describe('rdme docs', () => {
230235
slug: slugTwo,
231236
body: 'Body',
232237
category,
238+
})
239+
.post('/api/v1/docs', { slug, body: doc.content, ...doc.data, lastUpdatedHash: hash })
240+
.basicAuth({ user: key })
241+
.reply(400, {
242+
error: 'DOC_INVALID',
243+
message: "We couldn't save this doc (Path `category` is required.).",
233244
});
234245

235246
const versionMock = nock(config.host)
@@ -305,7 +316,7 @@ describe('rdme docs:edit', () => {
305316
body: `${body}${edits}`,
306317
})
307318
.basicAuth({ user: key })
308-
.reply(200);
319+
.reply(200, { category, slug });
309320

310321
const versionMock = nock(config.host)
311322
.get(`/api/v1/version/${version}`)

‎__tests__/cmds/openapi.test.js‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const promptHandler = require('../../src/lib/prompts');
55
const swagger = require('../../src/cmds/swagger');
66
const openapi = require('../../src/cmds/openapi');
77

8-
const key = 'Xmw4bGctRVIQz7R7dQXqH9nQe5d0SPQs';
8+
const key = 'API_KEY';
99
const version = '1.0.0';
1010

1111
jest.mock('../../src/lib/prompts');
@@ -87,9 +87,14 @@ describe('rdme openapi', () => {
8787
help: 'If you need help, email support@readme.io and mention log "fake-metrics-uuid".',
8888
});
8989

90-
return expect(openapi.run({ spec: './__tests__/__fixtures__/swagger.json', key, version }))
91-
.rejects.toThrow('The version you specified')
92-
.then(() => mock.done());
90+
return openapi.run({ spec: './__tests__/__fixtures__/swagger.json', key, version }).then(() => {
91+
expect(console.log).toHaveBeenCalledTimes(1);
92+
93+
const output = getCommandOutput();
94+
expect(output).toMatch(/The version you specified/);
95+
96+
mock.done();
97+
});
9398
});
9499

95100
it('should POST to the swagger api if no id provided', () => {
@@ -135,9 +140,14 @@ describe('rdme openapi', () => {
135140
help: 'If you need help, email support@readme.io and mention log "fake-metrics-uuid".',
136141
});
137142

138-
return expect(openapi.run({ spec: './__tests__/__fixtures__/invalid-swagger.json', key, version }))
139-
.rejects.toThrow('README VALIDATION ERROR "x-samples-languages" must be of type "Array"')
140-
.then(() => mock.done());
143+
return openapi.run({ spec: './__tests__/__fixtures__/invalid-swagger.json', key, version }).then(() => {
144+
expect(console.log).toHaveBeenCalledTimes(1);
145+
146+
const output = getCommandOutput();
147+
expect(output).toMatch(/Unknown error \(README VALIDATION ERROR "x-samples-languages" /);
148+
149+
mock.done();
150+
});
141151
});
142152

143153
it.todo('should return a 404 if version flag not found');

‎__tests__/cmds/versions.test.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const createVersion = require('../../src/cmds/versions/create');
77
const deleteVersion = require('../../src/cmds/versions/delete');
88
const updateVersion = require('../../src/cmds/versions/update');
99

10-
const key = 'Xmw4bGctRVIQz7R7dQXqH9nQe5d0SPQs';
10+
const key = 'API_KEY';
1111
const version = '1.0.0';
1212
const version2 = '2.0.0';
1313

0 commit comments

Comments
 (0)