@@ -10,6 +10,7 @@ import prompts from 'prompts';
10
10
import DocsCommand from '../../../src/cmds/docs' ;
11
11
import GuidesCommand from '../../../src/cmds/guides' ;
12
12
import APIError from '../../../src/lib/apiError' ;
13
+ import configstore from '../../../src/lib/configstore' ;
13
14
import getAPIMock , { getAPIMockWithVersionHeader } from '../../helpers/get-api-mock' ;
14
15
import { after , before } from '../../helpers/get-gha-setup' ;
15
16
import hashFileContents from '../../helpers/hash-file-contents' ;
@@ -39,6 +40,35 @@ describe('rdme docs', () => {
39
40
consoleInfoSpy . mockRestore ( ) ;
40
41
} ) ;
41
42
43
+ it ( 'should successfully log in user via prompts if API key is not provided' , async ( ) => {
44
+ const email = 'owlbert@readme.io' ;
45
+ const password = 'pass123' ;
46
+ const project = 'proj1' ;
47
+
48
+ const consoleInfoSpy = jest . spyOn ( console , 'info' ) . mockImplementation ( ) ;
49
+ const getCommandOutput = ( ) => {
50
+ return [ consoleInfoSpy . mock . calls . join ( '\n\n' ) ] . filter ( Boolean ) . join ( '\n\n' ) ;
51
+ } ;
52
+
53
+ prompts . inject ( [ email , password , project ] ) ;
54
+
55
+ const mock = getAPIMock ( )
56
+ . post ( '/api/v1/login' , { email, password, project } )
57
+ . reply ( 200 , { apiKey : key } )
58
+ . get ( '/api/v1/version' )
59
+ . basicAuth ( { user : key } )
60
+ . reply ( 200 , [ { version } ] ) ;
61
+
62
+ await expect ( docs . run ( { } ) ) . rejects . toStrictEqual (
63
+ new Error ( 'No path provided. Usage `rdme docs <path> [options]`.' )
64
+ ) ;
65
+ expect ( getCommandOutput ( ) ) . toContain ( "Looks like you're missing a ReadMe API key, let's fix that! 🦉" ) ;
66
+ expect ( getCommandOutput ( ) ) . toContain ( 'Successfully logged in as owlbert@readme.io to the proj1 project.' ) ;
67
+ mock . done ( ) ;
68
+ configstore . clear ( ) ;
69
+ jest . resetAllMocks ( ) ;
70
+ } ) ;
71
+
42
72
it ( 'should error in CI if no API key provided' , async ( ) => {
43
73
process . env . TEST_RDME_CI = 'true' ;
44
74
await expect ( docs . run ( { } ) ) . rejects . toStrictEqual ( new Error ( 'No project API key provided. Please use `--key`.' ) ) ;
0 commit comments