]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/node_modules/npm-registry-client/test/whoami.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / node_modules / npm-registry-client / test / whoami.js
1 var test = require('tap').test
2
3 var server = require('./lib/server.js')
4 var common = require('./lib/common.js')
5 var client = common.freshClient()
6
7 function nop () {}
8
9 var WHOIAM = 'wombat'
10 var TOKEN = 'not-bad-meaning-bad-but-bad-meaning-wombat'
11 var AUTH = { token: TOKEN }
12 var PARAMS = { auth: AUTH }
13
14 test('whoami call contract', function (t) {
15   t.throws(function () {
16     client.whoami(undefined, AUTH, nop)
17   }, 'requires a URI')
18
19   t.throws(function () {
20     client.whoami([], AUTH, nop)
21   }, 'requires URI to be a string')
22
23   t.throws(function () {
24     client.whoami(common.registry, undefined, nop)
25   }, 'requires params object')
26
27   t.throws(function () {
28     client.whoami(common.registry, '', nop)
29   }, 'params must be object')
30
31   t.throws(function () {
32     client.whoami(common.registry, AUTH, undefined)
33   }, 'requires callback')
34
35   t.throws(function () {
36     client.whoami(common.registry, AUTH, 'callback')
37   }, 'callback must be function')
38
39   t.throws(
40     function () {
41       var params = {}
42       client.whoami(common.registry, params, nop)
43     },
44     { name: 'AssertionError', message: 'must pass auth to whoami' },
45     'must pass auth to whoami'
46   )
47
48   t.end()
49 })
50
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
55     t.equal(
56       req.headers.authorization,
57       'Bearer not-bad-meaning-bad-but-bad-meaning-wombat'
58     )
59
60     res.json({ username: WHOIAM })
61   })
62
63   client.whoami(common.registry, PARAMS, function (error, wombat) {
64     t.ifError(error, 'no errors')
65     t.equal(wombat, WHOIAM, 'im a wombat')
66
67     server.close()
68     t.end()
69   })
70 })