1 var test = require('tap').test
3 var server = require('./lib/server.js')
4 var common = require('./lib/common.js')
5 var client = common.freshClient()
10 var TOKEN = 'not-bad-meaning-bad-but-bad-meaning-wombat'
11 var AUTH = { token: TOKEN }
12 var PARAMS = { auth: AUTH }
14 test('whoami call contract', function (t) {
15 t.throws(function () {
16 client.whoami(undefined, AUTH, nop)
19 t.throws(function () {
20 client.whoami([], AUTH, nop)
21 }, 'requires URI to be a string')
23 t.throws(function () {
24 client.whoami(common.registry, undefined, nop)
25 }, 'requires params object')
27 t.throws(function () {
28 client.whoami(common.registry, '', nop)
29 }, 'params must be object')
31 t.throws(function () {
32 client.whoami(common.registry, AUTH, undefined)
33 }, 'requires callback')
35 t.throws(function () {
36 client.whoami(common.registry, AUTH, 'callback')
37 }, 'callback must be function')
42 client.whoami(common.registry, params, nop)
44 { name: 'AssertionError', message: 'must pass auth to whoami' },
45 'must pass auth to whoami'
51 test('whoami', function (t) {
52 server.expect('GET', '/-/whoami', function (req, res) {
53 t.equal(req.method, 'GET')
54 // only available for token-based auth for now
56 req.headers.authorization,
57 'Bearer not-bad-meaning-bad-but-bad-meaning-wombat'
60 res.json({ username: WHOIAM })
63 client.whoami(common.registry, PARAMS, function (error, wombat) {
64 t.ifError(error, 'no errors')
65 t.equal(wombat, WHOIAM, 'im a wombat')