diff options
Diffstat (limited to 'test/lib/commands/whoami.js')
-rw-r--r-- | test/lib/commands/whoami.js | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/test/lib/commands/whoami.js b/test/lib/commands/whoami.js index f483bd46d..ad7c22388 100644 --- a/test/lib/commands/whoami.js +++ b/test/lib/commands/whoami.js @@ -5,7 +5,7 @@ const MockRegistry = require('../../fixtures/mock-registry.js') const username = 'foo' const auth = { '//registry.npmjs.org/:_authToken': 'test-auth-token' } -t.test('npm whoami', async (t) => { +t.test('npm whoami', async t => { const { npm, joinedOutput } = await loadMockNpm(t, { config: auth }) const registry = new MockRegistry({ tap: t, @@ -17,7 +17,7 @@ t.test('npm whoami', async (t) => { t.equal(joinedOutput(), username, 'should print username') }) -t.test('npm whoami --json', async (t) => { +t.test('npm whoami --json', async t => { const { npm, joinedOutput } = await loadMockNpm(t, { config: { json: true, @@ -33,3 +33,23 @@ t.test('npm whoami --json', async (t) => { await npm.exec('whoami', []) t.equal(JSON.parse(joinedOutput()), username, 'should print username') }) + +t.test('credentials from token', async t => { + const { npm, joinedOutput } = await loadMockNpm(t, { + config: { + '//registry.npmjs.org/:username': username, + '//registry.npmjs.org/:_password': 'hunter2', + }, + }) + await npm.exec('whoami', []) + t.equal(joinedOutput(), username, 'should print username') +}) + +t.test('not logged in', async t => { + const { npm } = await loadMockNpm(t, { + config: { + json: true, + }, + }) + await t.rejects(npm.exec('whoami', []), { code: 'ENEEDAUTH' }) +}) |