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()
9 var URI = 'http://localhost:1337/rewrite'
10 var TOKEN = 'b00b00feed'
17 test('logout call contract', function (t) {
18 t.throws(function () {
19 client.logout(undefined, PARAMS, nop)
22 t.throws(function () {
23 client.logout([], PARAMS, nop)
24 }, 'requires URI to be a string')
26 t.throws(function () {
27 client.logout(URI, undefined, nop)
28 }, 'requires params object')
30 t.throws(function () {
31 client.logout(URI, '', nop)
32 }, 'params must be object')
34 t.throws(function () {
35 client.logout(URI, PARAMS, undefined)
36 }, 'requires callback')
38 t.throws(function () {
39 client.logout(URI, PARAMS, 'callback')
40 }, 'callback must be function')
47 client.logout(URI, params, nop)
49 { name: 'AssertionError', message: 'can only log out for token auth' },
50 'auth must include token'
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')
61 res.json({message: 'ok'})
64 client.logout(URI, PARAMS, function (er) {
65 t.ifError(er, 'no errors')
71 test('cleanup', function (t) {