forked from readmeio/rdme
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add version selection to all relevant commands (readmeio#344)
* fix: add version selection to all relevant commands * fix: add version selection for version commands * test: update version tests * refactor: rename from swagger to project * test: add mock.done to test
- Loading branch information
1 parent
a7a5caa
commit d797d09
Showing
10 changed files
with
149 additions
and
100 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 |
---|---|---|
|
@@ -36,11 +36,6 @@ describe('rdme docs', () => { | |
return expect(docs.run({})).rejects.toThrow('No project API key provided. Please use `--key`.'); | ||
}); | ||
|
||
it('should error if no version provided', () => { | ||
expect.assertions(1); | ||
return expect(docs.run({ key })).rejects.toThrow('No project version provided. Please use `--version`.'); | ||
}); | ||
|
||
it('should error if no folder provided', () => { | ||
expect.assertions(1); | ||
return expect(docs.run({ key, version: '1.0.0' })).rejects.toThrow( | ||
|
@@ -103,13 +98,19 @@ describe('rdme docs', () => { | |
.basicAuth({ user: key }) | ||
.reply(200); | ||
|
||
const versionMock = nock(config.host) | ||
.get(`/api/v1/version/${version}`) | ||
.basicAuth({ user: key }) | ||
.reply(200, { version }); | ||
|
||
return docs.run({ folder: './__tests__/__fixtures__/existing-docs', key, version }).then(skippedDocs => { | ||
// All docs should have been updated because their hashes from the GET request were different from what they | ||
// are currently. | ||
expect(skippedDocs).toHaveLength(0); | ||
|
||
getMocks.done(); | ||
updateMocks.done(); | ||
versionMock.done(); | ||
}); | ||
}); | ||
|
||
|
@@ -124,13 +125,19 @@ describe('rdme docs', () => { | |
.basicAuth({ user: key }) | ||
.reply(200, { category, slug: anotherDoc.slug, lastUpdatedHash: anotherDoc.hash }); | ||
|
||
const versionMock = nock(config.host) | ||
.get(`/api/v1/version/${version}`) | ||
.basicAuth({ user: key }) | ||
.reply(200, { version }); | ||
|
||
return docs.run({ folder: './__tests__/__fixtures__/existing-docs', key, version }).then(skippedDocs => { | ||
expect(skippedDocs).toStrictEqual([ | ||
'`simple-doc` was not updated because there were no changes.', | ||
'`another-doc` was not updated because there were no changes.', | ||
]); | ||
|
||
getMocks.done(); | ||
versionMock.done(); | ||
}); | ||
}); | ||
}); | ||
|
@@ -156,9 +163,15 @@ describe('rdme docs', () => { | |
.basicAuth({ user: key }) | ||
.reply(201); | ||
|
||
const versionMock = nock(config.host) | ||
.get(`/api/v1/version/${version}`) | ||
.basicAuth({ user: key }) | ||
.reply(200, { version }); | ||
|
||
return docs.run({ folder: './__tests__/__fixtures__/new-docs', key, version }).then(() => { | ||
getMock.done(); | ||
postMock.done(); | ||
versionMock.done(); | ||
}); | ||
}); | ||
|
||
|
@@ -219,6 +232,11 @@ describe('rdme docs', () => { | |
category, | ||
}); | ||
|
||
const versionMock = nock(config.host) | ||
.get(`/api/v1/version/${version}`) | ||
.basicAuth({ user: key }) | ||
.reply(200, { version }); | ||
|
||
return docs.run({ folder: './__tests__/__fixtures__/failure-docs', key, version }).then(message => { | ||
expect(console.log).toHaveBeenCalledTimes(1); | ||
expect(message).toStrictEqual([ | ||
|
@@ -242,6 +260,7 @@ describe('rdme docs', () => { | |
|
||
getMocks.done(); | ||
postMocks.done(); | ||
versionMock.done(); | ||
|
||
console.log.mockRestore(); | ||
}); | ||
|
@@ -262,10 +281,6 @@ describe('rdme docs:edit', () => { | |
return expect(docsEdit.run({})).rejects.toThrow('No project API key provided. Please use `--key`.'); | ||
}); | ||
|
||
it('should error if no version provided', () => { | ||
return expect(docsEdit.run({ key })).rejects.toThrow('No project version provided. Please use `--version`.'); | ||
}); | ||
|
||
it('should error if no slug provided', () => { | ||
return expect(docsEdit.run({ key, version: '1.0.0' })).rejects.toThrow( | ||
'No slug provided. Usage `rdme docs:edit <slug> [options]`.' | ||
|
@@ -292,6 +307,11 @@ describe('rdme docs:edit', () => { | |
.basicAuth({ user: key }) | ||
.reply(200); | ||
|
||
const versionMock = nock(config.host) | ||
.get(`/api/v1/version/${version}`) | ||
.basicAuth({ user: key }) | ||
.reply(200, { version }); | ||
|
||
function mockEditor(filename, cb) { | ||
expect(filename).toBe(`${slug}.md`); | ||
expect(fs.existsSync(filename)).toBe(true); | ||
|
@@ -301,6 +321,7 @@ describe('rdme docs:edit', () => { | |
return docsEdit.run({ slug, key, version: '1.0.0', mockEditor }).then(() => { | ||
getMock.done(); | ||
putMock.done(); | ||
versionMock.done(); | ||
expect(fs.existsSync(`${slug}.md`)).toBe(false); | ||
|
||
expect(console.log).toHaveBeenCalledWith('Doc successfully updated. Cleaning up local file.'); | ||
|
@@ -320,8 +341,14 @@ describe('rdme docs:edit', () => { | |
help: 'If you need help, email [email protected] and mention log "fake-metrics-uuid".', | ||
}); | ||
|
||
const versionMock = nock(config.host) | ||
.get(`/api/v1/version/${version}`) | ||
.basicAuth({ user: key }) | ||
.reply(200, { version }); | ||
|
||
return docsEdit.run({ slug, key, version: '1.0.0' }).catch(err => { | ||
getMock.done(); | ||
versionMock.done(); | ||
expect(err.code).toBe('DOC_NOTFOUND'); | ||
expect(err.message).toContain("The doc with the slug 'no-such-doc' couldn't be found"); | ||
}); | ||
|
@@ -341,6 +368,11 @@ describe('rdme docs:edit', () => { | |
help: 'If you need help, email [email protected] and mention log "fake-metrics-uuid".', | ||
}); | ||
|
||
const versionMock = nock(config.host) | ||
.get(`/api/v1/version/${version}`) | ||
.basicAuth({ user: key }) | ||
.reply(200, { version }); | ||
|
||
function mockEditor(filename, cb) { | ||
return cb(0); | ||
} | ||
|
@@ -349,6 +381,7 @@ describe('rdme docs:edit', () => { | |
expect(err.code).toBe('DOC_INVALID'); | ||
getMock.done(); | ||
putMock.done(); | ||
versionMock.done(); | ||
expect(fs.existsSync(`${slug}.md`)).toBe(true); | ||
fs.unlinkSync(`${slug}.md`); | ||
}); | ||
|
@@ -359,13 +392,19 @@ describe('rdme docs:edit', () => { | |
const slug = 'getting-started'; | ||
const body = 'abcdef'; | ||
|
||
nock(config.host).get(`/api/v1/docs/${slug}`).reply(200, { body }); | ||
const getMock = nock(config.host) | ||
.get(`/api/v1/docs/${slug}`) | ||
.reply(200, { body }) | ||
.get(`/api/v1/version/${version}`) | ||
.basicAuth({ user: key }) | ||
.reply(200, { version }); | ||
|
||
function mockEditor(filename, cb) { | ||
return cb(1); | ||
} | ||
|
||
return docsEdit.run({ slug, key, version: '1.0.0', mockEditor }).catch(err => { | ||
getMock.done(); | ||
expect(err.message).toBe('Non zero exit code from $EDITOR'); | ||
fs.unlinkSync(`${slug}.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 |
---|---|---|
|
@@ -102,13 +102,6 @@ describe('rdme versions*', () => { | |
}); | ||
}); | ||
|
||
it('should error if no version provided', () => { | ||
expect.assertions(1); | ||
return createVersion.run({ key }).catch(err => { | ||
expect(err.message).toBe('Please specify a semantic version. See `rdme help versions:create` for help.'); | ||
}); | ||
}); | ||
|
||
it('should get a specific version object', () => { | ||
promptHandler.createVersionPrompt.mockResolvedValue({ | ||
is_stable: true, | ||
|
@@ -158,29 +151,34 @@ describe('rdme versions*', () => { | |
}); | ||
}); | ||
|
||
it('should error if no version provided', () => { | ||
expect.assertions(1); | ||
return deleteVersion.run({ key }).catch(err => { | ||
expect(err.message).toBe('Please specify a semantic version. See `rdme help versions:delete` for help.'); | ||
}); | ||
}); | ||
|
||
it('should delete a specific version', () => { | ||
const mockRequest = nock(config.host).delete(`/api/v1/version/${version}`).basicAuth({ user: key }).reply(200); | ||
const mockRequest = nock(config.host) | ||
.delete(`/api/v1/version/${version}`) | ||
.basicAuth({ user: key }) | ||
.reply(200) | ||
.get(`/api/v1/version/${version}`) | ||
.basicAuth({ user: key }) | ||
.reply(200, { version }); | ||
|
||
return deleteVersion.run({ key, version }).then(() => { | ||
mockRequest.done(); | ||
}); | ||
}); | ||
|
||
it('should catch any request errors', () => { | ||
const mockRequest = nock(config.host).delete(`/api/v1/version/${version}`).basicAuth({ user: key }).reply(404, { | ||
error: 'VERSION_NOTFOUND', | ||
message: | ||
"The version you specified ({version}) doesn't match any of the existing versions ({versions_list}) in ReadMe.", | ||
suggestion: '...a suggestion to resolve the issue...', | ||
help: 'If you need help, email [email protected] and mention log "fake-metrics-uuid".', | ||
}); | ||
const mockRequest = nock(config.host) | ||
.delete(`/api/v1/version/${version}`) | ||
.basicAuth({ user: key }) | ||
.reply(404, { | ||
error: 'VERSION_NOTFOUND', | ||
message: | ||
"The version you specified ({version}) doesn't match any of the existing versions ({versions_list}) in ReadMe.", | ||
suggestion: '...a suggestion to resolve the issue...', | ||
help: 'If you need help, email [email protected] and mention log "fake-metrics-uuid".', | ||
}) | ||
.get(`/api/v1/version/${version}`) | ||
.basicAuth({ user: key }) | ||
.reply(200, { version }); | ||
|
||
return deleteVersion.run({ key, version }).catch(err => { | ||
expect(err.message).toContain('The version you specified'); | ||
|
@@ -197,13 +195,6 @@ describe('rdme versions*', () => { | |
}); | ||
}); | ||
|
||
it('should error if no version provided', () => { | ||
expect.assertions(1); | ||
return updateVersion.run({ key }).catch(err => { | ||
expect(err.message).toBe('Please specify a semantic version. See `rdme help versions:update` for help.'); | ||
}); | ||
}); | ||
|
||
it('should update a specific version object', () => { | ||
promptHandler.createVersionPrompt.mockResolvedValue({ | ||
is_stable: false, | ||
|
@@ -217,7 +208,10 @@ describe('rdme versions*', () => { | |
.reply(200, { version }) | ||
.put(`/api/v1/version/${version}`) | ||
.basicAuth({ user: key }) | ||
.reply(201, { version }); | ||
.reply(201, { version }) | ||
.get(`/api/v1/version/${version}`) | ||
.basicAuth({ user: key }) | ||
.reply(200, { version }); | ||
|
||
return updateVersion.run({ key, version }).then(() => { | ||
mockRequest.done(); | ||
|
@@ -242,7 +236,10 @@ describe('rdme versions*', () => { | |
message: "You can't make a stable version non-stable", | ||
suggestion: '...a suggestion to resolve the issue...', | ||
help: 'If you need help, email [email protected] and mention log "fake-metrics-uuid".', | ||
}); | ||
}) | ||
.get(`/api/v1/version/${version}`) | ||
.basicAuth({ user: key }) | ||
.reply(200, { version }); | ||
|
||
return updateVersion.run({ key, version }).catch(err => { | ||
expect(err.message).toContain("You can't make a stable version non-stable"); | ||
|
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
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
Oops, something went wrong.