-
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: login issue when user doesn't pass in API key (#714)
- Loading branch information
1 parent
d197242
commit 9561f7c
Showing
2 changed files
with
32 additions
and
2 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 |
---|---|---|
|
@@ -10,6 +10,7 @@ import prompts from 'prompts'; | |
import DocsCommand from '../../../src/cmds/docs'; | ||
import GuidesCommand from '../../../src/cmds/guides'; | ||
import APIError from '../../../src/lib/apiError'; | ||
import configstore from '../../../src/lib/configstore'; | ||
import getAPIMock, { getAPIMockWithVersionHeader } from '../../helpers/get-api-mock'; | ||
import { after, before } from '../../helpers/get-gha-setup'; | ||
import hashFileContents from '../../helpers/hash-file-contents'; | ||
|
@@ -39,6 +40,35 @@ describe('rdme docs', () => { | |
consoleInfoSpy.mockRestore(); | ||
}); | ||
|
||
it('should successfully log in user via prompts if API key is not provided', async () => { | ||
const email = '[email protected]'; | ||
const password = 'pass123'; | ||
const project = 'proj1'; | ||
|
||
const consoleInfoSpy = jest.spyOn(console, 'info').mockImplementation(); | ||
const getCommandOutput = () => { | ||
return [consoleInfoSpy.mock.calls.join('\n\n')].filter(Boolean).join('\n\n'); | ||
}; | ||
|
||
prompts.inject([email, password, project]); | ||
|
||
const mock = getAPIMock() | ||
.post('/api/v1/login', { email, password, project }) | ||
.reply(200, { apiKey: key }) | ||
.get('/api/v1/version') | ||
.basicAuth({ user: key }) | ||
.reply(200, [{ version }]); | ||
|
||
await expect(docs.run({})).rejects.toStrictEqual( | ||
new Error('No path provided. Usage `rdme docs <path> [options]`.') | ||
); | ||
expect(getCommandOutput()).toContain("Looks like you're missing a ReadMe API key, let's fix that! 🦉"); | ||
expect(getCommandOutput()).toContain('Successfully logged in as [email protected] to the proj1 project.'); | ||
mock.done(); | ||
configstore.clear(); | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
it('should error in CI if no API key provided', async () => { | ||
process.env.TEST_RDME_CI = 'true'; | ||
await expect(docs.run({})).rejects.toStrictEqual(new Error('No project API key provided. Please use `--key`.')); | ||
|
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