Skip to content

Commit

Permalink
feat(docs): Add id to success message response for docs and `docs:s…
Browse files Browse the repository at this point in the history
…ingle` (#583)

* update doc upload success message and test

* Update src/lib/pushDoc.ts

Co-authored-by: Kanad Gupta <[email protected]>

* update test coverage

Co-authored-by: Kanad Gupta <[email protected]>
  • Loading branch information
garrett-wade and kanadgupta authored Sep 6, 2022
1 parent 8516206 commit a9d7099
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 29 deletions.
10 changes: 6 additions & 4 deletions __tests__/cmds/changelogs/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ describe('rdme changelogs', () => {
describe('new changelogs', () => {
it('should create new changelog', async () => {
const slug = 'new-doc';
const id = '1234';
const doc = frontMatter(fs.readFileSync(path.join(fullFixturesDir, `/new-docs/${slug}.md`)));
const hash = hashFileContents(fs.readFileSync(path.join(fullFixturesDir, `/new-docs/${slug}.md`)));

Expand All @@ -211,10 +212,10 @@ describe('rdme changelogs', () => {
const postMock = getAPIMock()
.post('/api/v1/changelogs', { slug, body: doc.content, ...doc.data, lastUpdatedHash: hash })
.basicAuth({ user: key })
.reply(201, { slug, body: doc.content, ...doc.data, lastUpdatedHash: hash });
.reply(201, { slug, id, body: doc.content, ...doc.data, lastUpdatedHash: hash });

await expect(changelogs.run({ folder: `./__tests__/${fixturesBaseDir}/new-docs`, key })).resolves.toBe(
`🌱 successfully created 'new-doc' with contents from __tests__/${fixturesBaseDir}/new-docs/new-doc.md`
`🌱 successfully created 'new-doc' (ID: 1234) with contents from __tests__/${fixturesBaseDir}/new-docs/new-doc.md`
);

getMock.done();
Expand Down Expand Up @@ -314,6 +315,7 @@ describe('rdme changelogs', () => {
describe('slug metadata', () => {
it('should use provided slug', async () => {
const slug = 'new-doc-slug';
const id = '1234';
const doc = frontMatter(fs.readFileSync(path.join(fullFixturesDir, `/slug-docs/${slug}.md`)));
const hash = hashFileContents(fs.readFileSync(path.join(fullFixturesDir, `/slug-docs/${slug}.md`)));

Expand All @@ -330,10 +332,10 @@ 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, body: doc.content, ...doc.data, lastUpdatedHash: hash });
.reply(201, { slug: doc.data.slug, 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' with contents from __tests__/${fixturesBaseDir}/slug-docs/new-doc-slug.md`
`🌱 successfully created 'marc-actually-wrote-a-test' (ID: 1234) with contents from __tests__/${fixturesBaseDir}/slug-docs/new-doc-slug.md`
);

getMock.done();
Expand Down
10 changes: 6 additions & 4 deletions __tests__/cmds/changelogs/single.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ describe('rdme changelogs:single', () => {
describe('new changelogs', () => {
it('should create new changelog', async () => {
const slug = 'new-doc';
const id = '1234';
const doc = frontMatter(fs.readFileSync(path.join(fullFixturesDir, `/new-docs/${slug}.md`)));
const hash = hashFileContents(fs.readFileSync(path.join(fullFixturesDir, `/new-docs/${slug}.md`)));

Expand All @@ -64,12 +65,12 @@ 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, body: doc.content, ...doc.data });
.reply(201, { slug, id, body: doc.content, ...doc.data });

await expect(
changelogsSingle.run({ filePath: `./__tests__/${fixturesBaseDir}/new-docs/new-doc.md`, key })
).resolves.toBe(
`🌱 successfully created 'new-doc' with contents from ./__tests__/${fixturesBaseDir}/new-docs/new-doc.md`
`🌱 successfully created 'new-doc' (ID: 1234) with contents from ./__tests__/${fixturesBaseDir}/new-docs/new-doc.md`
);

getMock.done();
Expand Down Expand Up @@ -177,6 +178,7 @@ describe('rdme changelogs:single', () => {
describe('slug metadata', () => {
it('should use provided slug', async () => {
const slug = 'new-doc-slug';
const id = '1234';
const doc = frontMatter(fs.readFileSync(path.join(fullFixturesDir, `/slug-docs/${slug}.md`)));
const hash = hashFileContents(fs.readFileSync(path.join(fullFixturesDir, `/slug-docs/${slug}.md`)));

Expand All @@ -193,12 +195,12 @@ 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, body: doc.content, ...doc.data, lastUpdatedHash: hash });
.reply(201, { slug: doc.data.slug, id, body: doc.content, ...doc.data, lastUpdatedHash: hash });

await expect(
changelogsSingle.run({ filePath: `./__tests__/${fixturesBaseDir}/slug-docs/new-doc-slug.md`, key })
).resolves.toBe(
`🌱 successfully created 'marc-actually-wrote-a-test' with contents from ./__tests__/${fixturesBaseDir}/slug-docs/new-doc-slug.md`
`🌱 successfully created 'marc-actually-wrote-a-test' (ID: 1234) with contents from ./__tests__/${fixturesBaseDir}/slug-docs/new-doc-slug.md`
);

getMock.done();
Expand Down
15 changes: 9 additions & 6 deletions __tests__/cmds/custompages/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ describe('rdme custompages', () => {
describe('new custompages', () => {
it('should create new custom page', async () => {
const slug = 'new-doc';
const id = '1234';
const doc = frontMatter(fs.readFileSync(path.join(fullFixturesDir, `/new-docs/${slug}.md`)));
const hash = hashFileContents(fs.readFileSync(path.join(fullFixturesDir, `/new-docs/${slug}.md`)));

Expand All @@ -214,10 +215,10 @@ describe('rdme custompages', () => {
const postMock = getAPIMock()
.post('/api/v1/custompages', { slug, body: doc.content, ...doc.data, lastUpdatedHash: hash })
.basicAuth({ user: key })
.reply(201, { slug, body: doc.content, ...doc.data, lastUpdatedHash: hash });
.reply(201, { slug, id, body: doc.content, ...doc.data, lastUpdatedHash: hash });

await expect(custompages.run({ folder: `./__tests__/${fixturesBaseDir}/new-docs`, key })).resolves.toBe(
`🌱 successfully created 'new-doc' with contents from __tests__/${fixturesBaseDir}/new-docs/new-doc.md`
`🌱 successfully created 'new-doc' (ID: 1234) with contents from __tests__/${fixturesBaseDir}/new-docs/new-doc.md`
);

getMock.done();
Expand All @@ -226,6 +227,7 @@ describe('rdme custompages', () => {

it('should create new HTML custom page', async () => {
const slug = 'new-doc';
const id = '1234';
const doc = frontMatter(fs.readFileSync(path.join(fullFixturesDir, `/new-docs-html/${slug}.html`)));
const hash = hashFileContents(fs.readFileSync(path.join(fullFixturesDir, `/new-docs-html/${slug}.html`)));

Expand All @@ -242,10 +244,10 @@ 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, html: doc.content, htmlmode: true, ...doc.data, lastUpdatedHash: hash });
.reply(201, { slug, 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' with contents from __tests__/${fixturesBaseDir}/new-docs-html/new-doc.html`
`🌱 successfully created 'new-doc' (ID: 1234) with contents from __tests__/${fixturesBaseDir}/new-docs-html/new-doc.html`
);

getMock.done();
Expand Down Expand Up @@ -351,6 +353,7 @@ describe('rdme custompages', () => {
describe('slug metadata', () => {
it('should use provided slug', async () => {
const slug = 'new-doc-slug';
const id = '1234';
const doc = frontMatter(fs.readFileSync(path.join(fullFixturesDir, `/slug-docs/${slug}.md`)));
const hash = hashFileContents(fs.readFileSync(path.join(fullFixturesDir, `/slug-docs/${slug}.md`)));

Expand All @@ -367,10 +370,10 @@ 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, body: doc.content, ...doc.data, lastUpdatedHash: hash });
.reply(201, { slug: doc.data.slug, 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' with contents from __tests__/${fixturesBaseDir}/slug-docs/new-doc-slug.md`
`🌱 successfully created 'marc-actually-wrote-a-test' (ID: 1234) with contents from __tests__/${fixturesBaseDir}/slug-docs/new-doc-slug.md`
);

getMock.done();
Expand Down
15 changes: 9 additions & 6 deletions __tests__/cmds/custompages/single.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ describe('rdme custompages:single', () => {
describe('new custompages', () => {
it('should create new custom page', async () => {
const slug = 'new-doc';
const id = '1234';
const doc = frontMatter(fs.readFileSync(path.join(fullFixturesDir, `/new-docs/${slug}.md`)));
const hash = hashFileContents(fs.readFileSync(path.join(fullFixturesDir, `/new-docs/${slug}.md`)));

Expand All @@ -64,12 +65,12 @@ 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, body: doc.content, ...doc.data });
.reply(201, { slug, id, body: doc.content, ...doc.data });

await expect(
customPagesSingle.run({ filePath: `./__tests__/${fixturesBaseDir}/new-docs/new-doc.md`, key })
).resolves.toBe(
`🌱 successfully created 'new-doc' with contents from ./__tests__/${fixturesBaseDir}/new-docs/new-doc.md`
`🌱 successfully created 'new-doc' (ID: 1234) with contents from ./__tests__/${fixturesBaseDir}/new-docs/new-doc.md`
);

getMock.done();
Expand All @@ -78,6 +79,7 @@ describe('rdme custompages:single', () => {

it('should create new HTML custom page', async () => {
const slug = 'new-doc';
const id = '1234';
const doc = frontMatter(fs.readFileSync(path.join(fullFixturesDir, `/new-docs-html/${slug}.html`)));
const hash = hashFileContents(fs.readFileSync(path.join(fullFixturesDir, `/new-docs-html/${slug}.html`)));

Expand All @@ -94,12 +96,12 @@ 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, html: doc.content, htmlmode: true, ...doc.data });
.reply(201, { slug, id, html: doc.content, htmlmode: true, ...doc.data });

await expect(
customPagesSingle.run({ filePath: `./__tests__/${fixturesBaseDir}/new-docs-html/new-doc.html`, key })
).resolves.toBe(
`🌱 successfully created 'new-doc' with contents from ./__tests__/${fixturesBaseDir}/new-docs-html/new-doc.html`
`🌱 successfully created 'new-doc' (ID: 1234) with contents from ./__tests__/${fixturesBaseDir}/new-docs-html/new-doc.html`
);

getMock.done();
Expand Down Expand Up @@ -207,6 +209,7 @@ describe('rdme custompages:single', () => {
describe('slug metadata', () => {
it('should use provided slug', async () => {
const slug = 'new-doc-slug';
const id = '1234';
const doc = frontMatter(fs.readFileSync(path.join(fullFixturesDir, `/slug-docs/${slug}.md`)));
const hash = hashFileContents(fs.readFileSync(path.join(fullFixturesDir, `/slug-docs/${slug}.md`)));

Expand All @@ -223,12 +226,12 @@ 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, body: doc.content, ...doc.data, lastUpdatedHash: hash });
.reply(201, { slug: doc.data.slug, id, body: doc.content, ...doc.data, lastUpdatedHash: hash });

await expect(
customPagesSingle.run({ filePath: `./__tests__/${fixturesBaseDir}/slug-docs/new-doc-slug.md`, key })
).resolves.toBe(
`🌱 successfully created 'marc-actually-wrote-a-test' with contents from ./__tests__/${fixturesBaseDir}/slug-docs/new-doc-slug.md`
`🌱 successfully created 'marc-actually-wrote-a-test' (ID: 1234) with contents from ./__tests__/${fixturesBaseDir}/slug-docs/new-doc-slug.md`
);

getMock.done();
Expand Down
10 changes: 6 additions & 4 deletions __tests__/cmds/docs/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ describe('rdme docs', () => {
describe('new docs', () => {
it('should create new doc', async () => {
const slug = 'new-doc';
const id = '1234';
const doc = frontMatter(fs.readFileSync(path.join(fullFixturesDir, `/new-docs/${slug}.md`)));
const hash = hashFileContents(fs.readFileSync(path.join(fullFixturesDir, `/new-docs/${slug}.md`)));

Expand All @@ -248,15 +249,15 @@ 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, body: doc.content, ...doc.data, lastUpdatedHash: hash });
.reply(201, { slug, id, body: doc.content, ...doc.data, lastUpdatedHash: hash });

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

await expect(docs.run({ folder: `./__tests__/${fixturesBaseDir}/new-docs`, key, version })).resolves.toBe(
`🌱 successfully created 'new-doc' with contents from __tests__/${fixturesBaseDir}/new-docs/new-doc.md`
`🌱 successfully created 'new-doc' (ID: 1234) with contents from __tests__/${fixturesBaseDir}/new-docs/new-doc.md`
);

getMock.done();
Expand Down Expand Up @@ -377,6 +378,7 @@ describe('rdme docs', () => {
describe('slug metadata', () => {
it('should use provided slug', async () => {
const slug = 'new-doc-slug';
const id = '1234';
const doc = frontMatter(fs.readFileSync(path.join(fullFixturesDir, `/slug-docs/${slug}.md`)));
const hash = hashFileContents(fs.readFileSync(path.join(fullFixturesDir, `/slug-docs/${slug}.md`)));

Expand All @@ -393,15 +395,15 @@ 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, body: doc.content, ...doc.data, lastUpdatedHash: hash });
.reply(201, { slug: doc.data.slug, id, body: doc.content, ...doc.data, lastUpdatedHash: hash });

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

await expect(docs.run({ folder: `./__tests__/${fixturesBaseDir}/slug-docs`, key, version })).resolves.toBe(
`🌱 successfully created 'marc-actually-wrote-a-test' with contents from __tests__/${fixturesBaseDir}/slug-docs/new-doc-slug.md`
`🌱 successfully created 'marc-actually-wrote-a-test' (ID: 1234) with contents from __tests__/${fixturesBaseDir}/slug-docs/new-doc-slug.md`
);

getMock.done();
Expand Down
10 changes: 6 additions & 4 deletions __tests__/cmds/docs/single.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ describe('rdme docs:single', () => {
describe('new docs', () => {
it('should create new doc', async () => {
const slug = 'new-doc';
const id = '1234';
const doc = frontMatter(fs.readFileSync(path.join(fullFixturesDir, `/new-docs/${slug}.md`)));
const hash = hashFileContents(fs.readFileSync(path.join(fullFixturesDir, `/new-docs/${slug}.md`)));

Expand All @@ -69,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, body: doc.content, ...doc.data, lastUpdatedHash: hash });
.reply(201, { slug, id, body: doc.content, ...doc.data, lastUpdatedHash: hash });

const versionMock = getAPIMock()
.get(`/api/v1/version/${version}`)
Expand All @@ -79,7 +80,7 @@ describe('rdme docs:single', () => {
await expect(
docsSingle.run({ filePath: `./__tests__/${fixturesBaseDir}/new-docs/new-doc.md`, key, version })
).resolves.toBe(
`🌱 successfully created 'new-doc' with contents from ./__tests__/${fixturesBaseDir}/new-docs/new-doc.md`
`🌱 successfully created 'new-doc' (ID: 1234) with contents from ./__tests__/${fixturesBaseDir}/new-docs/new-doc.md`
);

getMock.done();
Expand Down Expand Up @@ -206,6 +207,7 @@ describe('rdme docs:single', () => {
describe('slug metadata', () => {
it('should use provided slug', async () => {
const slug = 'new-doc-slug';
const id = '1234';
const doc = frontMatter(fs.readFileSync(path.join(fullFixturesDir, `/slug-docs/${slug}.md`)));
const hash = hashFileContents(fs.readFileSync(path.join(fullFixturesDir, `/slug-docs/${slug}.md`)));

Expand All @@ -222,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, body: doc.content, ...doc.data, lastUpdatedHash: hash });
.reply(201, { slug: doc.data.slug, id, body: doc.content, ...doc.data, lastUpdatedHash: hash });

const versionMock = getAPIMock()
.get(`/api/v1/version/${version}`)
Expand All @@ -232,7 +234,7 @@ describe('rdme docs:single', () => {
await expect(
docsSingle.run({ filePath: `./__tests__/${fixturesBaseDir}/slug-docs/new-doc-slug.md`, key, version })
).resolves.toBe(
`🌱 successfully created 'marc-actually-wrote-a-test' with contents from ./__tests__/${fixturesBaseDir}/slug-docs/new-doc-slug.md`
`🌱 successfully created 'marc-actually-wrote-a-test' (ID: 1234) with contents from ./__tests__/${fixturesBaseDir}/slug-docs/new-doc-slug.md`
);

getMock.done();
Expand Down
2 changes: 1 addition & 1 deletion src/lib/pushDoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export default async function pushDoc(
}),
})
.then(res => handleRes(res))
.then(res => `🌱 successfully created '${res.slug}' with contents from ${filepath}`);
.then(res => `🌱 successfully created '${res.slug}' (ID: ${res.id}) with contents from ${filepath}`);
}

function updateDoc(existingDoc: typeof data) {
Expand Down

0 comments on commit a9d7099

Please sign in to comment.