]> 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-add.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-add.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/test'
11 var TOKEN = 'foo'
12 var AUTH = {
13   token: TOKEN
14 }
15 var PACKAGE = 'underscore'
16 var DIST_TAG = 'test'
17 var VERSION = '3.1.3'
18 var PARAMS = {
19   'package': PACKAGE,
20   distTag: DIST_TAG,
21   version: VERSION,
22   auth: AUTH
23 }
24
25 test('distTags.add call contract', function (t) {
26   t.throws(function () {
27     client.distTags.add(undefined, AUTH, nop)
28   }, 'requires a URI')
29
30   t.throws(function () {
31     client.distTags.add([], PARAMS, nop)
32   }, 'requires URI to be a string')
33
34   t.throws(function () {
35     client.distTags.add(BASE_URL, undefined, nop)
36   }, 'requires params object')
37
38   t.throws(function () {
39     client.distTags.add(BASE_URL, '', nop)
40   }, 'params must be object')
41
42   t.throws(function () {
43     client.distTags.add(BASE_URL, PARAMS, undefined)
44   }, 'requires callback')
45
46   t.throws(function () {
47     client.distTags.add(BASE_URL, PARAMS, 'callback')
48   }, 'callback must be function')
49
50   t.throws(
51     function () {
52       var params = {
53         distTag: DIST_TAG,
54         version: VERSION,
55         auth: AUTH
56       }
57       client.distTags.add(BASE_URL, params, nop)
58     },
59     {
60       name: 'AssertionError',
61       message: 'must pass package name to distTags.add'
62     },
63     'distTags.add must include package name'
64   )
65
66   t.throws(
67     function () {
68       var params = {
69         'package': PACKAGE,
70         version: VERSION,
71         auth: AUTH
72       }
73       client.distTags.add(BASE_URL, params, nop)
74     },
75     {
76       name: 'AssertionError',
77       message: 'must pass package distTag name to distTags.add'
78     },
79     'distTags.add must include dist-tag'
80   )
81
82   t.throws(
83     function () {
84       var params = {
85         'package': PACKAGE,
86         distTag: DIST_TAG,
87         auth: AUTH
88       }
89       client.distTags.add(BASE_URL, params, nop)
90     },
91     {
92       name: 'AssertionError',
93       message: 'must pass version to be mapped to distTag to distTags.add'
94     },
95     'distTags.add must include version'
96   )
97
98   t.throws(
99     function () {
100       var params = {
101         'package': PACKAGE,
102         distTag: DIST_TAG,
103         version: VERSION
104       }
105       client.distTags.add(BASE_URL, params, nop)
106     },
107     { name: 'AssertionError', message: 'must pass auth to distTags.add' },
108     'distTags.add must include auth'
109   )
110
111   t.end()
112 })
113
114 test('add a new dist-tag to a package', function (t) {
115   server.expect('PUT', URI, function (req, res) {
116     t.equal(req.method, 'PUT')
117
118     var b = ''
119     req.setEncoding('utf8')
120     req.on('data', function (d) {
121       b += d
122     })
123
124     req.on('end', function () {
125       t.doesNotThrow(function () {
126         var parsed = JSON.parse(b)
127         t.deepEqual(parsed, VERSION)
128
129         res.statusCode = 200
130         res.json({ test: VERSION })
131       }, 'got valid JSON from client')
132     })
133   })
134
135   client.distTags.add(BASE_URL, PARAMS, function (error, data) {
136     t.ifError(error, 'no errors')
137     t.ok(data.test, 'dist-tag added')
138
139     server.close()
140     t.end()
141   })
142 })