From b106e4feed0bddadaaa29a52aaa230903a82f1dc Mon Sep 17 00:00:00 2001 From: Marc Cuva Date: Mon, 4 Oct 2021 17:31:16 -0700 Subject: [PATCH 1/2] fix: allow customers to define the slug in the metadata --- .../__fixtures__/slug-docs/new-doc-slug.md | 7 ++++ __tests__/cmds/docs.test.js | 34 +++++++++++++++++++ src/cmds/docs/index.js | 2 +- 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 __tests__/__fixtures__/slug-docs/new-doc-slug.md diff --git a/__tests__/__fixtures__/slug-docs/new-doc-slug.md b/__tests__/__fixtures__/slug-docs/new-doc-slug.md new file mode 100644 index 000000000..db5979ffe --- /dev/null +++ b/__tests__/__fixtures__/slug-docs/new-doc-slug.md @@ -0,0 +1,7 @@ +--- +category: 5ae122e10fdf4e39bb34db6f +title: This is the document title +slug: marc-actually-wrote-a-test +--- + +Body diff --git a/__tests__/cmds/docs.test.js b/__tests__/cmds/docs.test.js index 32a659097..594ced066 100644 --- a/__tests__/cmds/docs.test.js +++ b/__tests__/cmds/docs.test.js @@ -277,6 +277,40 @@ describe('rdme docs', () => { }); }); }); + + describe('slug metadata', () => { + it('should use provided slug', () => { + const slug = 'new-doc-slug'; + const doc = frontMatter(fs.readFileSync(path.join(fixturesDir, `/slug-docs/${slug}.md`))); + const hash = hashFileContents(fs.readFileSync(path.join(fixturesDir, `/slug-docs/${slug}.md`))); + + const getMock = getNockWithVersionHeader(version) + .get(`/api/v1/docs/${doc.data.slug}`) + .basicAuth({ user: key }) + .reply(404, { + error: 'DOC_NOTFOUND', + message: `The doc with the slug '${slug}' couldn't be found`, + suggestion: '...a suggestion to resolve the issue...', + help: 'If you need help, email support@readme.io and mention log "fake-metrics-uuid".', + }); + + const postMock = getNockWithVersionHeader(version) + .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 }); + + const versionMock = nock(config.host) + .get(`/api/v1/version/${version}`) + .basicAuth({ user: key }) + .reply(200, { version }); + + return docs.run({ folder: './__tests__/__fixtures__/slug-docs', key, version }).then(() => { + getMock.done(); + postMock.done(); + versionMock.done(); + }); + }); + }); }); describe('rdme docs:edit', () => { diff --git a/src/cmds/docs/index.js b/src/cmds/docs/index.js index da9704ef0..52daab7ef 100644 --- a/src/cmds/docs/index.js +++ b/src/cmds/docs/index.js @@ -116,7 +116,7 @@ exports.run = async function (opts) { const matter = frontMatter(file); // Stripping the subdirectories and markdown extension from the filename and lowercasing to get the default slug. - const slug = path.basename(filename).replace(path.extname(filename), '').toLowerCase(); + const slug = matter.data.slug || path.basename(filename).replace(path.extname(filename), '').toLowerCase(); const hash = crypto.createHash('sha1').update(file).digest('hex'); return fetch(`${config.host}/api/v1/docs/${slug}`, { From 2edfe730c9364e294926ecf9f3102a27e1ccfea6 Mon Sep 17 00:00:00 2001 From: Jon Ursenbach Date: Mon, 4 Oct 2021 18:06:32 -0700 Subject: [PATCH 2/2] chore: replacing a real looking category id in a test with a fake one --- __tests__/__fixtures__/slug-docs/new-doc-slug.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/__tests__/__fixtures__/slug-docs/new-doc-slug.md b/__tests__/__fixtures__/slug-docs/new-doc-slug.md index db5979ffe..336e0eaaf 100644 --- a/__tests__/__fixtures__/slug-docs/new-doc-slug.md +++ b/__tests__/__fixtures__/slug-docs/new-doc-slug.md @@ -1,5 +1,5 @@ --- -category: 5ae122e10fdf4e39bb34db6f +category: CATEGORY_ID title: This is the document title slug: marc-actually-wrote-a-test ---