]> 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/unpublish.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 / unpublish.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 var cache = require('./fixtures/underscore/cache.json')
8
9 function nop () {}
10
11 var REV = '/-rev/72-47f2986bfd8e8b55068b204588bbf484'
12 var URI = 'http://localhost:1337/underscore'
13 var TOKEN = 'of-glad-tidings'
14 var VERSION = '1.3.2'
15 var AUTH = {
16   token: TOKEN
17 }
18 var PARAMS = {
19   version: VERSION,
20   auth: AUTH
21 }
22
23 test('unpublish call contract', function (t) {
24   t.throws(function () {
25     client.unpublish(undefined, AUTH, nop)
26   }, 'requires a URI')
27
28   t.throws(function () {
29     client.unpublish([], AUTH, nop)
30   }, 'requires URI to be a string')
31
32   t.throws(function () {
33     client.unpublish(URI, undefined, nop)
34   }, 'requires params object')
35
36   t.throws(function () {
37     client.unpublish(URI, '', nop)
38   }, 'params must be object')
39
40   t.throws(function () {
41     client.unpublish(URI, AUTH, undefined)
42   }, 'requires callback')
43
44   t.throws(function () {
45     client.unpublish(URI, AUTH, 'callback')
46   }, 'callback must be function')
47
48   t.throws(
49     function () {
50       var params = {
51         version: VERSION
52       }
53       client.unpublish(URI, params, nop)
54     },
55     { name: 'AssertionError', message: 'must pass auth to unpublish' },
56     'must pass auth to unpublish'
57   )
58
59   t.end()
60 })
61
62 test('unpublish a package', function (t) {
63   server.expect('GET', '/underscore?write=true', function (req, res) {
64     t.equal(req.method, 'GET')
65
66     res.json(cache)
67   })
68
69   server.expect('PUT', '/underscore' + REV, function (req, res) {
70     t.equal(req.method, 'PUT')
71
72     var b = ''
73     req.setEncoding('utf-8')
74     req.on('data', function (d) {
75       b += d
76     })
77
78     req.on('end', function () {
79       var updated = JSON.parse(b)
80       t.notOk(updated.versions[VERSION])
81     })
82
83     res.json(cache)
84   })
85
86   server.expect('GET', '/underscore', function (req, res) {
87     t.equal(req.method, 'GET')
88
89     res.json(cache)
90   })
91
92   server.expect('DELETE', '/underscore/-/underscore-1.3.2.tgz' + REV, function (req, res) {
93     t.equal(req.method, 'DELETE')
94
95     res.json({ unpublished: true })
96   })
97
98   client.unpublish(URI, PARAMS, function (error) {
99     t.ifError(error, 'no errors')
100
101     server.close()
102     t.end()
103   })
104 })