-
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.
- Loading branch information
Showing
6 changed files
with
67 additions
and
4 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const config = require('config'); | ||
const configStore = require('../lib/configstore'); | ||
const loginCmd = require('./login'); | ||
|
||
exports.command = 'whoami'; | ||
exports.usage = 'whoami'; | ||
exports.description = 'Displays the current user and project authenticated with ReadMe.'; | ||
exports.category = 'admin'; | ||
exports.weight = 2; | ||
|
||
exports.args = []; | ||
|
||
exports.run = () => { | ||
if (!configStore.has('email') || !configStore.has('project')) { | ||
return Promise.reject(new Error(`Please login using \`${config.cli} ${loginCmd.command}\`.`)); | ||
} | ||
|
||
return Promise.resolve( | ||
`You are currently logged in as ${configStore.get('email').green} to the ${ | ||
configStore.get('project').blue | ||
} project.`, | ||
); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const assert = require('assert'); | ||
const config = require('config'); | ||
const configStore = require('../../lib/configstore'); | ||
const cmd = require('../../cmds/whoami'); | ||
const loginCmd = require('../../cmds/login'); | ||
|
||
describe('whoami command', () => { | ||
it('should error if user is not authenticate', done => { | ||
configStore.delete('email'); | ||
configStore.delete('project'); | ||
|
||
cmd | ||
.run({}) | ||
.then(() => { | ||
assert.ok(false, 'unauthenticated error message not displayed'); | ||
}) | ||
.catch(err => { | ||
assert.equal(err.message, `Please login using \`${config.cli} ${loginCmd.command}\`.`); | ||
return done(); | ||
}); | ||
}); | ||
|
||
it('should return the authenticated user', done => { | ||
configStore.set('email', '[email protected]'); | ||
configStore.set('project', 'subdomain'); | ||
|
||
cmd | ||
.run({}) | ||
.then(() => { | ||
assert.ok(true); | ||
return done(); | ||
}) | ||
.catch(err => { | ||
assert.ok(false, err); | ||
return done(); | ||
}); | ||
}); | ||
}); |