-
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.
test: reorganize tests so they don't leak console warnings
- Loading branch information
1 parent
6a1c232
commit b320a97
Showing
1 changed file
with
20 additions
and
18 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 |
---|---|---|
|
@@ -92,32 +92,17 @@ describe('cli', () => { | |
await expect(cli([])).resolves.toContain('OpenAPI / Swagger'); | ||
}); | ||
|
||
it('should add stored apiKey to opts', async () => { | ||
expect.assertions(1); | ||
const key = '123456'; | ||
const version = '1.0.0'; | ||
conf.set('apiKey', key); | ||
|
||
const versionMock = getAPIMock().get(`/api/v1/version/${version}`).basicAuth({ user: key }).reply(200, { version }); | ||
|
||
await expect(cli(['docs', `--version=${version}`])).rejects.toStrictEqual( | ||
new Error('No path provided. Usage `rdme docs <path> [options]`.') | ||
); | ||
|
||
conf.clear(); | ||
versionMock.done(); | ||
}); | ||
|
||
describe('logged-in user notifications', () => { | ||
describe('stored API key', () => { | ||
let consoleInfoSpy; | ||
const key = '123456'; | ||
const getCommandOutput = () => { | ||
return [consoleInfoSpy.mock.calls.join('\n\n')].filter(Boolean).join('\n\n'); | ||
}; | ||
|
||
beforeEach(() => { | ||
conf.set('email', '[email protected]'); | ||
conf.set('project', 'owlbert'); | ||
conf.set('apiKey', '123456'); | ||
conf.set('apiKey', key); | ||
consoleInfoSpy = jest.spyOn(console, 'info').mockImplementation(); | ||
}); | ||
|
||
|
@@ -126,6 +111,23 @@ describe('cli', () => { | |
conf.clear(); | ||
}); | ||
|
||
it('should add stored apiKey to opts', async () => { | ||
expect.assertions(1); | ||
const version = '1.0.0'; | ||
|
||
const versionMock = getAPIMock() | ||
.get(`/api/v1/version/${version}`) | ||
.basicAuth({ user: key }) | ||
.reply(200, { version }); | ||
|
||
await expect(cli(['docs', `--version=${version}`])).rejects.toStrictEqual( | ||
new Error('No path provided. Usage `rdme docs <path> [options]`.') | ||
); | ||
|
||
conf.clear(); | ||
versionMock.done(); | ||
}); | ||
|
||
it('should inform a logged in user which project is being updated', async () => { | ||
await expect(cli(['openapi', '--create', '--update'])).rejects.toThrow( | ||
'The `--create` and `--update` options cannot be used simultaneously. Please use one or the other!' | ||
|