]> 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/dist-tags-fetch.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 / dist-tags-fetch.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 BASE_URL = 'http://localhost:1337/'
10 var URI = '/-/package/underscore/dist-tags'
11 var TOKEN = 'foo'
12 var AUTH = {
13   token: TOKEN
14 }
15 var PACKAGE = 'underscore'
16 var PARAMS = {
17   'package': PACKAGE,
18   auth: AUTH
19 }
20
21 test('distTags.fetch call contract', function (t) {
22   t.throws(function () {
23     client.distTags.fetch(undefined, AUTH, nop)
24   }, 'requires a URI')
25
26   t.throws(function () {
27     client.distTags.fetch([], PARAMS, nop)
28   }, 'requires URI to be a string')
29
30   t.throws(function () {
31     client.distTags.fetch(BASE_URL, undefined, nop)
32   }, 'requires params object')
33
34   t.throws(function () {
35     client.distTags.fetch(BASE_URL, '', nop)
36   }, 'params must be object')
37
38   t.throws(function () {
39     client.distTags.fetch(BASE_URL, PARAMS, undefined)
40   }, 'requires callback')
41
42   t.throws(function () {
43     client.distTags.fetch(BASE_URL, PARAMS, 'callback')
44   }, 'callback must be function')
45
46   t.throws(
47     function () {
48       var params = {
49         auth: AUTH
50       }
51       client.distTags.fetch(BASE_URL, params, nop)
52     },
53     {
54       name: 'AssertionError',
55       message: 'must pass package name to distTags.fetch'
56     },
57     'distTags.fetch must include package name'
58   )
59
60   t.throws(
61     function () {
62       var params = {
63         'package': PACKAGE
64       }
65       client.distTags.fetch(BASE_URL, params, nop)
66     },
67     { name: 'AssertionError', message: 'must pass auth to distTags.fetch' },
68     'distTags.fetch must include auth'
69   )
70
71   t.end()
72 })
73
74 test('fetch dist-tags for a package', function (t) {
75   server.expect('GET', URI, function (req, res) {
76     t.equal(req.method, 'GET')
77
78     var b = ''
79     req.setEncoding('utf8')
80     req.on('data', function (d) {
81       b += d
82     })
83
84     req.on('end', function () {
85       t.notOk(b, 'no request body')
86
87       res.statusCode = 200
88       res.json({ a: '1.0.0', b: '2.0.0', _etag: 'xxx' })
89     })
90   })
91
92   client.distTags.fetch(BASE_URL, PARAMS, function (error, data) {
93     t.ifError(error, 'no errors')
94     t.same(data, { a: '1.0.0', b: '2.0.0' }, 'etag filtered from response')
95
96     server.close()
97     t.end()
98   })
99 })