From 7175537380e98147896f1d1412446455d62274bc Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Tue, 20 Sep 2022 14:10:37 -0500 Subject: [PATCH] fix(docs): use correct `_id` param (#616) --- __tests__/cmds/changelogs/index.test.ts | 4 +-- __tests__/cmds/changelogs/single.test.ts | 4 +-- __tests__/cmds/custompages/index.test.ts | 6 ++-- __tests__/cmds/custompages/single.test.ts | 6 ++-- __tests__/cmds/docs/index.test.ts | 6 ++-- __tests__/cmds/docs/single.test.ts | 4 +-- src/lib/fetch.ts | 1 + src/lib/pushDoc.ts | 35 ++++++++++++----------- 8 files changed, 35 insertions(+), 31 deletions(-) diff --git a/__tests__/cmds/changelogs/index.test.ts b/__tests__/cmds/changelogs/index.test.ts index eb10dfe90..a167c621e 100644 --- a/__tests__/cmds/changelogs/index.test.ts +++ b/__tests__/cmds/changelogs/index.test.ts @@ -212,7 +212,7 @@ describe('rdme changelogs', () => { const postMock = getAPIMock() .post('/api/v1/changelogs', { slug, body: doc.content, ...doc.data, lastUpdatedHash: hash }) .basicAuth({ user: key }) - .reply(201, { slug, id, body: doc.content, ...doc.data, lastUpdatedHash: hash }); + .reply(201, { slug, _id: id, body: doc.content, ...doc.data, lastUpdatedHash: hash }); await expect(changelogs.run({ folder: `./__tests__/${fixturesBaseDir}/new-docs`, key })).resolves.toBe( `🌱 successfully created 'new-doc' (ID: 1234) with contents from __tests__/${fixturesBaseDir}/new-docs/new-doc.md` @@ -332,7 +332,7 @@ describe('rdme changelogs', () => { const postMock = getAPIMock() .post('/api/v1/changelogs', { slug, body: doc.content, ...doc.data, lastUpdatedHash: hash }) .basicAuth({ user: key }) - .reply(201, { slug: doc.data.slug, id, body: doc.content, ...doc.data, lastUpdatedHash: hash }); + .reply(201, { slug: doc.data.slug, _id: id, body: doc.content, ...doc.data, lastUpdatedHash: hash }); await expect(changelogs.run({ folder: `./__tests__/${fixturesBaseDir}/slug-docs`, key })).resolves.toBe( `🌱 successfully created 'marc-actually-wrote-a-test' (ID: 1234) with contents from __tests__/${fixturesBaseDir}/slug-docs/new-doc-slug.md` diff --git a/__tests__/cmds/changelogs/single.test.ts b/__tests__/cmds/changelogs/single.test.ts index a25ecda00..b808bdade 100644 --- a/__tests__/cmds/changelogs/single.test.ts +++ b/__tests__/cmds/changelogs/single.test.ts @@ -65,7 +65,7 @@ describe('rdme changelogs:single', () => { const postMock = getAPIMock() .post('/api/v1/changelogs', { slug, body: doc.content, ...doc.data, lastUpdatedHash: hash }) .basicAuth({ user: key }) - .reply(201, { slug, id, body: doc.content, ...doc.data }); + .reply(201, { slug, _id: id, body: doc.content, ...doc.data }); await expect( changelogsSingle.run({ filePath: `./__tests__/${fixturesBaseDir}/new-docs/new-doc.md`, key }) @@ -195,7 +195,7 @@ describe('rdme changelogs:single', () => { const postMock = getAPIMock() .post('/api/v1/changelogs', { slug, body: doc.content, ...doc.data, lastUpdatedHash: hash }) .basicAuth({ user: key }) - .reply(201, { slug: doc.data.slug, id, body: doc.content, ...doc.data, lastUpdatedHash: hash }); + .reply(201, { slug: doc.data.slug, _id: id, body: doc.content, ...doc.data, lastUpdatedHash: hash }); await expect( changelogsSingle.run({ filePath: `./__tests__/${fixturesBaseDir}/slug-docs/new-doc-slug.md`, key }) diff --git a/__tests__/cmds/custompages/index.test.ts b/__tests__/cmds/custompages/index.test.ts index 12c0ddf9f..375bd7b26 100644 --- a/__tests__/cmds/custompages/index.test.ts +++ b/__tests__/cmds/custompages/index.test.ts @@ -215,7 +215,7 @@ describe('rdme custompages', () => { const postMock = getAPIMock() .post('/api/v1/custompages', { slug, body: doc.content, ...doc.data, lastUpdatedHash: hash }) .basicAuth({ user: key }) - .reply(201, { slug, id, body: doc.content, ...doc.data, lastUpdatedHash: hash }); + .reply(201, { slug, _id: id, body: doc.content, ...doc.data, lastUpdatedHash: hash }); await expect(custompages.run({ folder: `./__tests__/${fixturesBaseDir}/new-docs`, key })).resolves.toBe( `🌱 successfully created 'new-doc' (ID: 1234) with contents from __tests__/${fixturesBaseDir}/new-docs/new-doc.md` @@ -244,7 +244,7 @@ describe('rdme custompages', () => { const postMock = getAPIMock() .post('/api/v1/custompages', { slug, html: doc.content, htmlmode: true, ...doc.data, lastUpdatedHash: hash }) .basicAuth({ user: key }) - .reply(201, { slug, id, html: doc.content, htmlmode: true, ...doc.data, lastUpdatedHash: hash }); + .reply(201, { slug, _id: id, html: doc.content, htmlmode: true, ...doc.data, lastUpdatedHash: hash }); await expect(custompages.run({ folder: `./__tests__/${fixturesBaseDir}/new-docs-html`, key })).resolves.toBe( `🌱 successfully created 'new-doc' (ID: 1234) with contents from __tests__/${fixturesBaseDir}/new-docs-html/new-doc.html` @@ -370,7 +370,7 @@ describe('rdme custompages', () => { const postMock = getAPIMock() .post('/api/v1/custompages', { slug, body: doc.content, ...doc.data, lastUpdatedHash: hash }) .basicAuth({ user: key }) - .reply(201, { slug: doc.data.slug, id, body: doc.content, ...doc.data, lastUpdatedHash: hash }); + .reply(201, { slug: doc.data.slug, _id: id, body: doc.content, ...doc.data, lastUpdatedHash: hash }); await expect(custompages.run({ folder: `./__tests__/${fixturesBaseDir}/slug-docs`, key })).resolves.toBe( `🌱 successfully created 'marc-actually-wrote-a-test' (ID: 1234) with contents from __tests__/${fixturesBaseDir}/slug-docs/new-doc-slug.md` diff --git a/__tests__/cmds/custompages/single.test.ts b/__tests__/cmds/custompages/single.test.ts index a0d723e1d..b7c880c47 100644 --- a/__tests__/cmds/custompages/single.test.ts +++ b/__tests__/cmds/custompages/single.test.ts @@ -65,7 +65,7 @@ describe('rdme custompages:single', () => { const postMock = getAPIMock() .post('/api/v1/custompages', { slug, body: doc.content, ...doc.data, lastUpdatedHash: hash }) .basicAuth({ user: key }) - .reply(201, { slug, id, body: doc.content, ...doc.data }); + .reply(201, { slug, _id: id, body: doc.content, ...doc.data }); await expect( customPagesSingle.run({ filePath: `./__tests__/${fixturesBaseDir}/new-docs/new-doc.md`, key }) @@ -96,7 +96,7 @@ describe('rdme custompages:single', () => { const postMock = getAPIMock() .post('/api/v1/custompages', { slug, html: doc.content, htmlmode: true, ...doc.data, lastUpdatedHash: hash }) .basicAuth({ user: key }) - .reply(201, { slug, id, html: doc.content, htmlmode: true, ...doc.data }); + .reply(201, { slug, _id: id, html: doc.content, htmlmode: true, ...doc.data }); await expect( customPagesSingle.run({ filePath: `./__tests__/${fixturesBaseDir}/new-docs-html/new-doc.html`, key }) @@ -226,7 +226,7 @@ describe('rdme custompages:single', () => { const postMock = getAPIMock() .post('/api/v1/custompages', { slug, body: doc.content, ...doc.data, lastUpdatedHash: hash }) .basicAuth({ user: key }) - .reply(201, { slug: doc.data.slug, id, body: doc.content, ...doc.data, lastUpdatedHash: hash }); + .reply(201, { slug: doc.data.slug, _id: id, body: doc.content, ...doc.data, lastUpdatedHash: hash }); await expect( customPagesSingle.run({ filePath: `./__tests__/${fixturesBaseDir}/slug-docs/new-doc-slug.md`, key }) diff --git a/__tests__/cmds/docs/index.test.ts b/__tests__/cmds/docs/index.test.ts index 8c884efcb..19039aac1 100644 --- a/__tests__/cmds/docs/index.test.ts +++ b/__tests__/cmds/docs/index.test.ts @@ -255,7 +255,7 @@ describe('rdme docs', () => { const postMock = getAPIMockWithVersionHeader(version) .post('/api/v1/docs', { slug, body: doc.content, ...doc.data, lastUpdatedHash: hash }) .basicAuth({ user: key }) - .reply(201, { slug, id, body: doc.content, ...doc.data, lastUpdatedHash: hash }); + .reply(201, { slug, _id: id, body: doc.content, ...doc.data, lastUpdatedHash: hash }); const versionMock = getAPIMock() .get(`/api/v1/version/${version}`) @@ -519,7 +519,7 @@ describe('rdme docs', () => { const postMock = getAPIMock() .post('/api/v1/docs', { slug, body: doc.content, ...doc.data, lastUpdatedHash: hash }) .basicAuth({ user: key }) - .reply(201, { slug: doc.data.slug, id, body: doc.content, ...doc.data, lastUpdatedHash: hash }); + .reply(201, { slug: doc.data.slug, _id: id, body: doc.content, ...doc.data, lastUpdatedHash: hash }); const versionMock = getAPIMock() .get(`/api/v1/version/${version}`) @@ -586,7 +586,7 @@ describe('rdme docs', () => { const postMock = getAPIMockWithVersionHeader(altVersion) .post('/api/v1/docs', { slug, body: doc.content, ...doc.data, lastUpdatedHash: hash }) .basicAuth({ user: key }) - .reply(201, { id, slug, body: doc.content, ...doc.data, lastUpdatedHash: hash }); + .reply(201, { _id: id, slug, body: doc.content, ...doc.data, lastUpdatedHash: hash }); const fileName = 'docs-test-file'; prompts.inject([altVersion, true, 'docs-test-branch', fileName]); diff --git a/__tests__/cmds/docs/single.test.ts b/__tests__/cmds/docs/single.test.ts index 13fdd5fe4..8b3ae719c 100644 --- a/__tests__/cmds/docs/single.test.ts +++ b/__tests__/cmds/docs/single.test.ts @@ -70,7 +70,7 @@ describe('rdme docs:single', () => { const postMock = getAPIMockWithVersionHeader(version) .post('/api/v1/docs', { slug, body: doc.content, ...doc.data, lastUpdatedHash: hash }) .basicAuth({ user: key }) - .reply(201, { slug, id, body: doc.content, ...doc.data, lastUpdatedHash: hash }); + .reply(201, { slug, _id: id, body: doc.content, ...doc.data, lastUpdatedHash: hash }); const versionMock = getAPIMock() .get(`/api/v1/version/${version}`) @@ -224,7 +224,7 @@ describe('rdme docs:single', () => { const postMock = getAPIMock() .post('/api/v1/docs', { slug, body: doc.content, ...doc.data, lastUpdatedHash: hash }) .basicAuth({ user: key }) - .reply(201, { slug: doc.data.slug, id, body: doc.content, ...doc.data, lastUpdatedHash: hash }); + .reply(201, { slug: doc.data.slug, _id: id, body: doc.content, ...doc.data, lastUpdatedHash: hash }); const versionMock = getAPIMock() .get(`/api/v1/version/${version}`) diff --git a/src/lib/fetch.ts b/src/lib/fetch.ts index a8c43bed4..676216b14 100644 --- a/src/lib/fetch.ts +++ b/src/lib/fetch.ts @@ -74,6 +74,7 @@ async function handleRes(res: Response) { return body; } if (res.status === SUCCESS_NO_CONTENT) { + debug(`received status code ${res.status} from ${res.url} with no content`); return {}; } // If we receive a non-JSON response, it's likely an error. diff --git a/src/lib/pushDoc.ts b/src/lib/pushDoc.ts index 5d4319876..e3cb45e7e 100644 --- a/src/lib/pushDoc.ts +++ b/src/lib/pushDoc.ts @@ -51,22 +51,25 @@ export default async function pushDoc( )}`; } - return fetch(`${config.get('host')}/api/v1/${type}`, { - method: 'post', - headers: cleanHeaders( - key, - new Headers({ - 'x-readme-version': selectedVersion, - 'Content-Type': 'application/json', - }) - ), - body: JSON.stringify({ - slug, - ...payload, - }), - }) - .then(res => handleRes(res)) - .then(res => `🌱 successfully created '${res.slug}' (ID: ${res.id}) with contents from ${filepath}`); + return ( + fetch(`${config.get('host')}/api/v1/${type}`, { + method: 'post', + headers: cleanHeaders( + key, + new Headers({ + 'x-readme-version': selectedVersion, + 'Content-Type': 'application/json', + }) + ), + body: JSON.stringify({ + slug, + ...payload, + }), + }) + .then(res => handleRes(res)) + // eslint-disable-next-line no-underscore-dangle + .then(res => `🌱 successfully created '${res.slug}' (ID: ${res._id}) with contents from ${filepath}`) + ); } function updateDoc(existingDoc: typeof payload) {