]> 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/ping.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 / ping.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 TOKEN = 'not-bad-meaning-bad-but-bad-meaning-wombat'
10 var AUTH = { token: TOKEN }
11 var PARAMS = { auth: AUTH }
12 var DEP_USER = 'username'
13 var HOST = 'localhost'
14
15 test('ping call contract', function (t) {
16   t.throws(function () {
17     client.ping(undefined, AUTH, nop)
18   }, 'requires a URI')
19
20   t.throws(function () {
21     client.ping([], AUTH, nop)
22   }, 'requires URI to be a string')
23
24   t.throws(function () {
25     client.ping(common.registry, undefined, nop)
26   }, 'requires params object')
27
28   t.throws(function () {
29     client.ping(common.registry, '', nop)
30   }, 'params must be object')
31
32   t.throws(function () {
33     client.ping(common.registry, AUTH, undefined)
34   }, 'requires callback')
35
36   t.throws(function () {
37     client.ping(common.registry, AUTH, 'callback')
38   }, 'callback must be function')
39
40   t.throws(
41     function () {
42       var params = {}
43       client.ping(common.registry, params, nop)
44     },
45     { name: 'AssertionError', message: 'must pass auth to ping' },
46     'must pass auth to ping'
47   )
48
49   t.end()
50 })
51
52 test('ping', function (t) {
53   server.expect('GET', '/-/ping?write=true', function (req, res) {
54     t.equal(req.method, 'GET')
55     res.statusCode = 200
56     res.json({
57       ok: true,
58       host: HOST,
59       peer: HOST,
60       username: DEP_USER
61     })
62   })
63
64   client.ping(common.registry, PARAMS, function (error, found) {
65     t.ifError(error, 'no errors')
66     var wanted = {
67       ok: true,
68       host: HOST,
69       peer: HOST,
70       username: DEP_USER
71     }
72     t.same(found, wanted)
73     server.close()
74     t.end()
75   })
76 })