-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
699b7e2
commit afe367d
Showing
9 changed files
with
157 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
title: Child | ||
parentDocSlug: parent | ||
--- | ||
|
||
# Child Body |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
title: Friend | ||
--- | ||
|
||
# Friend Body |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
title: Parent | ||
--- | ||
|
||
# Parent Body |
6 changes: 6 additions & 0 deletions
6
__tests__/__fixtures__/docs/docs-with-parent-ids/with-parent-doc.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
title: With Parent Doc | ||
parentDoc: 1234 | ||
--- | ||
|
||
# With Parent Doc Body |
6 changes: 6 additions & 0 deletions
6
__tests__/__fixtures__/docs/multiple-docs-no-parents/child.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
title: Child | ||
parentDocSlug: parent | ||
--- | ||
|
||
# Child Body |
5 changes: 5 additions & 0 deletions
5
__tests__/__fixtures__/docs/multiple-docs-no-parents/friend.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
title: Friend | ||
--- | ||
|
||
# Friend Body |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,18 +77,99 @@ describe('rdme docs (multiple)', () => { | |
versionMock.done(); | ||
}); | ||
|
||
it('should return an error message when it encounters a cycle', async () => { | ||
const dir = 'multiple-docs-cycle'; | ||
it('should upload docs with parent doc ids first', async () => { | ||
const dir = 'docs-with-parent-ids'; | ||
const slugs = ['child', 'friend', 'with-parent-doc', 'parent']; | ||
let id = 1234; | ||
|
||
const mocks = slugs.flatMap(slug => { | ||
const doc = frontMatter(fs.readFileSync(path.join(fullFixturesDir, `/${dir}/${slug}.md`))); | ||
const hash = hashFileContents(fs.readFileSync(path.join(fullFixturesDir, `/${dir}/${slug}.md`))); | ||
|
||
return [ | ||
getAPIMockWithVersionHeader(version) | ||
.get(`/api/v1/docs/${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 [email protected] and mention log "fake-metrics-uuid".', | ||
}), | ||
getAPIMockWithVersionHeader(version) | ||
.post('/api/v1/docs', { slug, body: doc.content, ...doc.data, lastUpdatedHash: hash }) | ||
.basicAuth({ user: key }) | ||
// eslint-disable-next-line no-plusplus | ||
.reply(201, { slug, _id: id++, body: doc.content, ...doc.data, lastUpdatedHash: hash }), | ||
]; | ||
}); | ||
|
||
const versionMock = getAPIMock().get(`/api/v1/version/${version}`).basicAuth({ user: key }).reply(200, { version }); | ||
|
||
const promise = docs.run({ filePath: `./__tests__/${fixturesBaseDir}/${dir}`, key, version }); | ||
|
||
await expect(promise).resolves.toStrictEqual( | ||
[ | ||
`🌱 successfully created 'with-parent-doc' (ID: 1236) with contents from __tests__/${fixturesBaseDir}/${dir}/with-parent-doc.md`, | ||
`🌱 successfully created 'friend' (ID: 1235) with contents from __tests__/${fixturesBaseDir}/${dir}/friend.md`, | ||
`🌱 successfully created 'parent' (ID: 1237) with contents from __tests__/${fixturesBaseDir}/${dir}/parent.md`, | ||
`🌱 successfully created 'child' (ID: 1234) with contents from __tests__/${fixturesBaseDir}/${dir}/child.md`, | ||
].join('\n'), | ||
); | ||
|
||
mocks.forEach(mock => mock.done()); | ||
versionMock.done(); | ||
}); | ||
|
||
it('should upload child docs without the parent', async () => { | ||
const dir = 'multiple-docs-no-parents'; | ||
const slugs = ['child', 'friend']; | ||
let id = 1234; | ||
|
||
const mocks = slugs.flatMap(slug => { | ||
const doc = frontMatter(fs.readFileSync(path.join(fullFixturesDir, `/${dir}/${slug}.md`))); | ||
const hash = hashFileContents(fs.readFileSync(path.join(fullFixturesDir, `/${dir}/${slug}.md`))); | ||
|
||
return [ | ||
getAPIMockWithVersionHeader(version) | ||
.get(`/api/v1/docs/${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 [email protected] and mention log "fake-metrics-uuid".', | ||
}), | ||
getAPIMockWithVersionHeader(version) | ||
.post('/api/v1/docs', { slug, body: doc.content, ...doc.data, lastUpdatedHash: hash }) | ||
.basicAuth({ user: key }) | ||
// eslint-disable-next-line no-plusplus | ||
.reply(201, { slug, _id: id++, body: doc.content, ...doc.data, lastUpdatedHash: hash }), | ||
]; | ||
}); | ||
|
||
const versionMock = getAPIMock().get(`/api/v1/version/${version}`).basicAuth({ user: key }).reply(200, { version }); | ||
|
||
const promise = docs.run({ filePath: `./__tests__/${fixturesBaseDir}/${dir}`, key, version }); | ||
|
||
await expect(promise).rejects.toStrictEqual( | ||
new Error( | ||
`Unable to resolve docs parent hierarchy. A cycle was found with: __tests__/${fixturesBaseDir}/${dir}/parent.md`, | ||
), | ||
await expect(promise).resolves.toStrictEqual( | ||
[ | ||
`🌱 successfully created 'child' (ID: 1234) with contents from __tests__/${fixturesBaseDir}/${dir}/child.md`, | ||
`🌱 successfully created 'friend' (ID: 1235) with contents from __tests__/${fixturesBaseDir}/${dir}/friend.md`, | ||
].join('\n'), | ||
); | ||
|
||
mocks.forEach(mock => mock.done()); | ||
versionMock.done(); | ||
}); | ||
|
||
it('should return an error message when it encounters a cycle', async () => { | ||
const dir = 'multiple-docs-cycle'; | ||
const versionMock = getAPIMock().get(`/api/v1/version/${version}`).basicAuth({ user: key }).reply(200, { version }); | ||
|
||
const promise = docs.run({ filePath: `./__tests__/${fixturesBaseDir}/${dir}`, key, version }); | ||
|
||
await expect(promise).rejects.toThrow('Cyclic dependency'); | ||
versionMock.done(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters