]> 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/logout.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 / logout.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 URI = 'http://localhost:1337/rewrite'
10 var TOKEN = 'b00b00feed'
11 var PARAMS = {
12   auth: {
13     token: TOKEN
14   }
15 }
16
17 test('logout call contract', function (t) {
18   t.throws(function () {
19     client.logout(undefined, PARAMS, nop)
20   }, 'requires a URI')
21
22   t.throws(function () {
23     client.logout([], PARAMS, nop)
24   }, 'requires URI to be a string')
25
26   t.throws(function () {
27     client.logout(URI, undefined, nop)
28   }, 'requires params object')
29
30   t.throws(function () {
31     client.logout(URI, '', nop)
32   }, 'params must be object')
33
34   t.throws(function () {
35     client.logout(URI, PARAMS, undefined)
36   }, 'requires callback')
37
38   t.throws(function () {
39     client.logout(URI, PARAMS, 'callback')
40   }, 'callback must be function')
41
42   t.throws(
43     function () {
44       var params = {
45         auth: {}
46       }
47       client.logout(URI, params, nop)
48     },
49     { name: 'AssertionError', message: 'can only log out for token auth' },
50     'auth must include token'
51   )
52
53   t.end()
54 })
55
56 test('log out from a token-based registry', function (t) {
57   server.expect('DELETE', '/-/user/token/' + TOKEN, function (req, res) {
58     t.equal(req.method, 'DELETE')
59     t.equal(req.headers.authorization, 'Bearer ' + TOKEN, 'request is authed')
60
61     res.json({message: 'ok'})
62   })
63
64   client.logout(URI, PARAMS, function (er) {
65     t.ifError(er, 'no errors')
66
67     t.end()
68   })
69 })
70
71 test('cleanup', function (t) {
72   server.close()
73   t.end()
74 })