-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: change docs command to always update all valid docs (#338)
* fix: change swagger command to always update all valid docs * test: update test to fit docs update
- Loading branch information
1 parent
5503c04
commit 792a2b2
Showing
4 changed files
with
133 additions
and
3 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 @@ | ||
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,6 @@ | ||
--- | ||
category: 5ae122e10fdf4e39bb34db6f | ||
title: This is the document title | ||
--- | ||
|
||
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 |
---|---|---|
|
@@ -138,6 +138,115 @@ describe('rdme docs', () => { | |
postMock.done(); | ||
}); | ||
}); | ||
|
||
it('should create only valid docs', () => { | ||
console.log = jest.fn(); | ||
expect.assertions(2); | ||
const slug = 'fail-doc'; | ||
const slugTwo = 'new-doc'; | ||
const doc = frontMatter(fs.readFileSync(path.join(fixturesDir, `/failure-docs/${slug}.md`))); | ||
const docTwo = frontMatter(fs.readFileSync(path.join(fixturesDir, `/failure-docs/${slugTwo}.md`))); | ||
const hash = crypto | ||
.createHash('sha1') | ||
.update(fs.readFileSync(path.join(fixturesDir, `/failure-docs/${slug}.md`))) | ||
.digest('hex'); | ||
|
||
const hashTwo = crypto | ||
.createHash('sha1') | ||
.update(fs.readFileSync(path.join(fixturesDir, `/failure-docs/${slugTwo}.md`))) | ||
.digest('hex'); | ||
|
||
const getMock = nock(config.host, { | ||
reqheaders: { | ||
'x-readme-version': 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".', | ||
}); | ||
|
||
const getMockTwo = nock(config.host, { | ||
reqheaders: { | ||
'x-readme-version': version, | ||
}, | ||
}) | ||
.get(`/api/v1/docs/${slugTwo}`) | ||
.basicAuth({ user: key }) | ||
.reply(404, { | ||
error: 'DOC_NOTFOUND', | ||
message: `The doc with the slug '${slugTwo}' 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".', | ||
}); | ||
|
||
const postMock = nock(config.host, { | ||
reqheaders: { | ||
'x-readme-version': version, | ||
}, | ||
}) | ||
.post(`/api/v1/docs`, { slug, body: doc.content, ...doc.data, lastUpdatedHash: hash }) | ||
.basicAuth({ user: key }) | ||
.reply(400, { | ||
error: 'DOC_INVALID', | ||
message: "We couldn't save this doc (Path `category` is required.).", | ||
}); | ||
|
||
const postMockTwo = nock(config.host, { | ||
reqheaders: { | ||
'x-readme-version': version, | ||
}, | ||
}) | ||
.post(`/api/v1/docs`, { slug: slugTwo, body: docTwo.content, ...docTwo.data, lastUpdatedHash: hashTwo }) | ||
.basicAuth({ user: key }) | ||
.reply(201, { | ||
metadata: { image: [], title: '', description: '' }, | ||
api: { | ||
method: 'post', | ||
url: '', | ||
auth: 'required', | ||
params: [], | ||
apiSetting: '60ddf83e30681022753e27af', | ||
}, | ||
title: 'This is the document title', | ||
updates: [], | ||
type: 'endpoint', | ||
slug: slugTwo, | ||
body: 'Body', | ||
category: '5ae122e10fdf4e39bb34db6f', | ||
}); | ||
|
||
return docs.run({ folder: './__tests__/__fixtures__/failure-docs', key, version }).then(message => { | ||
expect(console.log).toHaveBeenCalledTimes(1); | ||
expect(message).toStrictEqual([ | ||
{ | ||
metadata: { image: [], title: '', description: '' }, | ||
api: { | ||
method: 'post', | ||
url: '', | ||
auth: 'required', | ||
params: [], | ||
apiSetting: '60ddf83e30681022753e27af', | ||
}, | ||
title: 'This is the document title', | ||
updates: [], | ||
type: 'endpoint', | ||
slug: slugTwo, | ||
body: 'Body', | ||
category: '5ae122e10fdf4e39bb34db6f', | ||
}, | ||
]); | ||
getMock.done(); | ||
getMockTwo.done(); | ||
postMock.done(); | ||
postMockTwo.done(); | ||
console.log.mockRestore(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
|
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