Skip to content

Commit

Permalink
fix: replace request-promise-native with node-fetch (#352)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
rahulhegdee and erunion authored Aug 18, 2021
1 parent 31cc6f2 commit 74bad7d
Show file tree
Hide file tree
Showing 15 changed files with 317 additions and 719 deletions.
35 changes: 23 additions & 12 deletions __tests__/cmds/docs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ describe('rdme docs', () => {
...simpleDoc.doc.data,
})
.basicAuth({ user: key })
.reply(200)
.reply(200, {
category,
slug: simpleDoc.slug,
body: simpleDoc.doc.content,
})
.put('/api/v1/docs/another-doc', {
category,
slug: anotherDoc.slug,
Expand All @@ -96,17 +100,24 @@ describe('rdme docs', () => {
...anotherDoc.doc.data,
})
.basicAuth({ user: key })
.reply(200);
.reply(200, { category, slug: anotherDoc.slug, body: anotherDoc.doc.content });

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

return docs.run({ folder: './__tests__/__fixtures__/existing-docs', key, version }).then(skippedDocs => {
return docs.run({ folder: './__tests__/__fixtures__/existing-docs', key, version }).then(updatedDocs => {
// All docs should have been updated because their hashes from the GET request were different from what they
// are currently.
expect(skippedDocs).toHaveLength(0);
expect(updatedDocs).toStrictEqual([
{
category,
slug: simpleDoc.slug,
body: simpleDoc.doc.content,
},
{ category, slug: anotherDoc.slug, body: anotherDoc.doc.content },
]);

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

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

const postMocks = getNockWithVersionHeader(version)
.post('/api/v1/docs', { slug, body: doc.content, ...doc.data, lastUpdatedHash: hash })
.basicAuth({ user: key })
.reply(400, {
error: 'DOC_INVALID',
message: "We couldn't save this doc (Path `category` is required.).",
})
.post('/api/v1/docs', { slug: slugTwo, body: docTwo.content, ...docTwo.data, lastUpdatedHash: hashTwo })
.basicAuth({ user: key })
.reply(201, {
Expand All @@ -230,6 +235,12 @@ describe('rdme docs', () => {
slug: slugTwo,
body: 'Body',
category,
})
.post('/api/v1/docs', { slug, body: doc.content, ...doc.data, lastUpdatedHash: hash })
.basicAuth({ user: key })
.reply(400, {
error: 'DOC_INVALID',
message: "We couldn't save this doc (Path `category` is required.).",
});

const versionMock = nock(config.host)
Expand Down Expand Up @@ -305,7 +316,7 @@ describe('rdme docs:edit', () => {
body: `${body}${edits}`,
})
.basicAuth({ user: key })
.reply(200);
.reply(200, { category, slug });

const versionMock = nock(config.host)
.get(`/api/v1/version/${version}`)
Expand Down
24 changes: 17 additions & 7 deletions __tests__/cmds/openapi.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const promptHandler = require('../../src/lib/prompts');
const swagger = require('../../src/cmds/swagger');
const openapi = require('../../src/cmds/openapi');

const key = 'Xmw4bGctRVIQz7R7dQXqH9nQe5d0SPQs';
const key = 'API_KEY';
const version = '1.0.0';

jest.mock('../../src/lib/prompts');
Expand Down Expand Up @@ -87,9 +87,14 @@ describe('rdme openapi', () => {
help: 'If you need help, email [email protected] and mention log "fake-metrics-uuid".',
});

return expect(openapi.run({ spec: './__tests__/__fixtures__/swagger.json', key, version }))
.rejects.toThrow('The version you specified')
.then(() => mock.done());
return openapi.run({ spec: './__tests__/__fixtures__/swagger.json', key, version }).then(() => {
expect(console.log).toHaveBeenCalledTimes(1);

const output = getCommandOutput();
expect(output).toMatch(/The version you specified/);

mock.done();
});
});

it('should POST to the swagger api if no id provided', () => {
Expand Down Expand Up @@ -135,9 +140,14 @@ describe('rdme openapi', () => {
help: 'If you need help, email [email protected] and mention log "fake-metrics-uuid".',
});

return expect(openapi.run({ spec: './__tests__/__fixtures__/invalid-swagger.json', key, version }))
.rejects.toThrow('README VALIDATION ERROR "x-samples-languages" must be of type "Array"')
.then(() => mock.done());
return openapi.run({ spec: './__tests__/__fixtures__/invalid-swagger.json', key, version }).then(() => {
expect(console.log).toHaveBeenCalledTimes(1);

const output = getCommandOutput();
expect(output).toMatch(/Unknown error \(README VALIDATION ERROR "x-samples-languages" /);

mock.done();
});
});

it.todo('should return a 404 if version flag not found');
Expand Down
2 changes: 1 addition & 1 deletion __tests__/cmds/versions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const createVersion = require('../../src/cmds/versions/create');
const deleteVersion = require('../../src/cmds/versions/delete');
const updateVersion = require('../../src/cmds/versions/update');

const key = 'Xmw4bGctRVIQz7R7dQXqH9nQe5d0SPQs';
const key = 'API_KEY';
const version = '1.0.0';
const version2 = '2.0.0';

Expand Down
Loading

0 comments on commit 74bad7d

Please sign in to comment.