]> 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/deprecate.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 / deprecate.js
1 var test = require('tap').test
2
3 var server = require('./lib/server.js')
4 var common = require('./lib/common.js')
5 var cache = require('./fixtures/underscore/cache.json')
6
7 var client = common.freshClient()
8
9 function nop () {}
10
11 var URI = 'https://npm.registry:8043/rewrite'
12 var VERSION = '1.3.2'
13 var MESSAGE = 'uhhh'
14 var TOKEN = 'lolbutts'
15 var AUTH = {
16   token: TOKEN
17 }
18 var PARAMS = {
19   version: VERSION,
20   message: MESSAGE,
21   auth: AUTH
22 }
23
24 test('deprecate call contract', function (t) {
25   t.throws(function () {
26     client.deprecate(undefined, PARAMS, nop)
27   }, 'requires a URI')
28
29   t.throws(function () {
30     client.deprecate([], PARAMS, nop)
31   }, 'requires URI to be a string')
32
33   t.throws(function () {
34     client.deprecate(URI, undefined, nop)
35   }, 'requires params object')
36
37   t.throws(function () {
38     client.deprecate(URI, '', nop)
39   }, 'params must be object')
40
41   t.throws(function () {
42     client.deprecate(URI, PARAMS, undefined)
43   }, 'requires callback')
44
45   t.throws(function () {
46     client.deprecate(URI, PARAMS, 'callback')
47   }, 'callback must be function')
48
49   t.throws(
50     function () {
51       var params = {
52         message: MESSAGE,
53         auth: AUTH
54       }
55       client.deprecate(URI, params, nop)
56     },
57     { name: 'AssertionError', message: 'must pass version to deprecate' },
58     'params must include version to deprecate'
59   )
60
61   t.throws(
62     function () {
63       var params = {
64         version: VERSION,
65         auth: AUTH
66       }
67       client.deprecate(URI, params, nop)
68     },
69     { name: 'AssertionError', message: 'must pass message to deprecate' },
70     'params must include deprecation message'
71   )
72
73   t.throws(
74     function () {
75       var params = {
76         version: VERSION,
77         message: MESSAGE
78       }
79       client.deprecate(URI, params, nop)
80     },
81     { name: 'AssertionError', message: 'must pass auth to deprecate' },
82     'params must include auth'
83   )
84
85   t.test('malformed semver in deprecation', function (t) {
86     var params = {
87       version: '-9001',
88       message: MESSAGE,
89       auth: AUTH
90     }
91     client.deprecate(URI, params, function (err) {
92       t.equal(
93         err && err.message,
94         'invalid version range: -9001',
95         'got expected semver validation failure'
96       )
97       t.end()
98     })
99   })
100
101   t.end()
102 })
103
104 test('deprecate a package', function (t) {
105   server.expect('GET', '/underscore?write=true', function (req, res) {
106     t.equal(req.method, 'GET')
107
108     res.json(cache)
109   })
110
111   server.expect('PUT', '/underscore', function (req, res) {
112     t.equal(req.method, 'PUT')
113
114     var b = ''
115     req.setEncoding('utf8')
116     req.on('data', function (d) {
117       b += d
118     })
119
120     req.on('end', function () {
121       var updated = JSON.parse(b)
122
123       var undeprecated = [
124         '1.0.3', '1.0.4', '1.1.0', '1.1.1', '1.1.2', '1.1.3', '1.1.4', '1.1.5', '1.1.6',
125         '1.1.7', '1.2.0', '1.2.1', '1.2.2', '1.2.3', '1.2.4', '1.3.0', '1.3.1', '1.3.3'
126       ]
127       for (var i = 0; i < undeprecated.length; i++) {
128         var current = undeprecated[i]
129         t.notEqual(
130           updated.versions[current].deprecated,
131           MESSAGE,
132           current + ' not deprecated'
133         )
134       }
135
136       t.equal(
137         updated.versions[VERSION].deprecated,
138         MESSAGE,
139         VERSION + ' deprecated'
140       )
141       res.statusCode = 201
142       res.json({ deprecated: true })
143     })
144   })
145
146   client.deprecate(
147     common.registry + '/underscore',
148     PARAMS,
149     function (er, data) {
150       t.ifError(er)
151       t.ok(data.deprecated, 'was deprecated')
152
153       t.end()
154     }
155   )
156 })
157
158 test('deprecate a scoped package', function (t) {
159   server.expect('GET', '/@test%2funderscore?write=true', function (req, res) {
160     t.equal(req.method, 'GET')
161
162     res.json(cache)
163   })
164
165   server.expect('PUT', '/@test%2funderscore', function (req, res) {
166     t.equal(req.method, 'PUT')
167
168     var b = ''
169     req.setEncoding('utf8')
170     req.on('data', function (d) {
171       b += d
172     })
173
174     req.on('end', function () {
175       var updated = JSON.parse(b)
176
177       var undeprecated = [
178         '1.0.3', '1.0.4', '1.1.0', '1.1.1', '1.1.2', '1.1.3', '1.1.4', '1.1.5', '1.1.6',
179         '1.1.7', '1.2.0', '1.2.1', '1.2.2', '1.2.3', '1.2.4', '1.3.0', '1.3.1', '1.3.3'
180       ]
181       for (var i = 0; i < undeprecated.length; i++) {
182         var current = undeprecated[i]
183         t.notEqual(
184           updated.versions[current].deprecated,
185           MESSAGE,
186           current + ' not deprecated'
187         )
188       }
189
190       t.equal(
191         updated.versions[VERSION].deprecated,
192         MESSAGE,
193         VERSION + ' deprecated'
194       )
195       res.statusCode = 201
196       res.json({ deprecated: true })
197     })
198   })
199
200   client.deprecate(
201     common.registry + '/@test%2funderscore',
202     PARAMS,
203     function (er, data) {
204       t.ifError(er)
205       t.ok(data.deprecated, 'was deprecated')
206
207       t.end()
208     }
209   )
210 })
211
212 test('cleanup', function (t) {
213   server.close()
214   t.ok(true)
215   t.end()
216 })