Skip to content

Commit

Permalink
fix(docs): use correct _id param (#616)
Browse files Browse the repository at this point in the history
  • Loading branch information
kanadgupta authored Sep 20, 2022
1 parent c071bc1 commit 7175537
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 31 deletions.
4 changes: 2 additions & 2 deletions __tests__/cmds/changelogs/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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`
Expand Down
4 changes: 2 additions & 2 deletions __tests__/cmds/changelogs/single.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down Expand Up @@ -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 })
Expand Down
6 changes: 3 additions & 3 deletions __tests__/cmds/custompages/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -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`
Expand Down
6 changes: 3 additions & 3 deletions __tests__/cmds/custompages/single.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down Expand Up @@ -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 })
Expand Down Expand Up @@ -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 })
Expand Down
6 changes: 3 additions & 3 deletions __tests__/cmds/docs/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
Expand Down Expand Up @@ -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}`)
Expand Down Expand Up @@ -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]);
Expand Down
4 changes: 2 additions & 2 deletions __tests__/cmds/docs/single.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
Expand Down Expand Up @@ -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}`)
Expand Down
1 change: 1 addition & 0 deletions src/lib/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
35 changes: 19 additions & 16 deletions src/lib/pushDoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 7175537

Please sign in to comment.