1 var test = require('tap').test
3 var server = require('./lib/server.js')
4 var common = require('./lib/common.js')
5 var cache = require('./fixtures/underscore/cache.json')
7 var client = common.freshClient()
11 var URI = 'https://npm.registry:8043/rewrite'
14 var TOKEN = 'lolbutts'
24 test('deprecate call contract', function (t) {
25 t.throws(function () {
26 client.deprecate(undefined, PARAMS, nop)
29 t.throws(function () {
30 client.deprecate([], PARAMS, nop)
31 }, 'requires URI to be a string')
33 t.throws(function () {
34 client.deprecate(URI, undefined, nop)
35 }, 'requires params object')
37 t.throws(function () {
38 client.deprecate(URI, '', nop)
39 }, 'params must be object')
41 t.throws(function () {
42 client.deprecate(URI, PARAMS, undefined)
43 }, 'requires callback')
45 t.throws(function () {
46 client.deprecate(URI, PARAMS, 'callback')
47 }, 'callback must be function')
55 client.deprecate(URI, params, nop)
57 { name: 'AssertionError', message: 'must pass version to deprecate' },
58 'params must include version to deprecate'
67 client.deprecate(URI, params, nop)
69 { name: 'AssertionError', message: 'must pass message to deprecate' },
70 'params must include deprecation message'
79 client.deprecate(URI, params, nop)
81 { name: 'AssertionError', message: 'must pass auth to deprecate' },
82 'params must include auth'
85 t.test('malformed semver in deprecation', function (t) {
91 client.deprecate(URI, params, function (err) {
94 'invalid version range: -9001',
95 'got expected semver validation failure'
104 test('deprecate a package', function (t) {
105 server.expect('GET', '/underscore?write=true', function (req, res) {
106 t.equal(req.method, 'GET')
111 server.expect('PUT', '/underscore', function (req, res) {
112 t.equal(req.method, 'PUT')
115 req.setEncoding('utf8')
116 req.on('data', function (d) {
120 req.on('end', function () {
121 var updated = JSON.parse(b)
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'
127 for (var i = 0; i < undeprecated.length; i++) {
128 var current = undeprecated[i]
130 updated.versions[current].deprecated,
132 current + ' not deprecated'
137 updated.versions[VERSION].deprecated,
139 VERSION + ' deprecated'
142 res.json({ deprecated: true })
147 common.registry + '/underscore',
149 function (er, data) {
151 t.ok(data.deprecated, 'was deprecated')
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')
165 server.expect('PUT', '/@test%2funderscore', function (req, res) {
166 t.equal(req.method, 'PUT')
169 req.setEncoding('utf8')
170 req.on('data', function (d) {
174 req.on('end', function () {
175 var updated = JSON.parse(b)
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'
181 for (var i = 0; i < undeprecated.length; i++) {
182 var current = undeprecated[i]
184 updated.versions[current].deprecated,
186 current + ' not deprecated'
191 updated.versions[VERSION].deprecated,
193 VERSION + ' deprecated'
196 res.json({ deprecated: true })
201 common.registry + '/@test%2funderscore',
203 function (er, data) {
205 t.ok(data.deprecated, 'was deprecated')
212 test('cleanup', function (t) {