Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: replace request-promise-native with node-fetch #352

Merged
merged 13 commits into from
Aug 18, 2021
Merged
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