]> 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/publish-again.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 / publish-again.js
1 var tap = require('tap')
2 var fs = require('fs')
3
4 var server = require('./lib/server.js')
5 var common = require('./lib/common.js')
6
7 var auth = {
8   username: 'username',
9   password: '%1234@asdf%',
10   email: 'i@izs.me',
11   alwaysAuth: true
12 }
13
14 var client = common.freshClient()
15
16 tap.test('publish again', function (t) {
17   // not really a tarball, but doesn't matter
18   var bodyPath = require.resolve('../package.json')
19   var tarball = fs.createReadStream(bodyPath)
20   var pd = fs.readFileSync(bodyPath)
21   var pkg = require('../package.json')
22   var lastTime = null
23
24   server.expect('/npm-registry-client', function (req, res) {
25     t.equal(req.method, 'PUT')
26     var b = ''
27     req.setEncoding('utf8')
28     req.on('data', function (d) {
29       b += d
30     })
31
32     req.on('end', function () {
33       var o = lastTime = JSON.parse(b)
34       t.equal(o._id, 'npm-registry-client')
35       t.equal(o['dist-tags'].latest, pkg.version)
36       t.has(o.versions[pkg.version], pkg)
37       t.same(o.maintainers, [ { name: 'username', email: 'i@izs.me' } ])
38       var att = o._attachments[ pkg.name + '-' + pkg.version + '.tgz' ]
39       t.same(att.data, pd.toString('base64'))
40       res.statusCode = 409
41       res.json({reason: 'must supply latest _rev to update existing package'})
42     })
43   })
44
45   server.expect('/npm-registry-client?write=true', function (req, res) {
46     t.equal(req.method, 'GET')
47     t.ok(lastTime)
48     for (var i in lastTime.versions) {
49       var v = lastTime.versions[i]
50       delete lastTime.versions[i]
51       lastTime.versions['0.0.2'] = v
52       lastTime['dist-tags'] = { latest: '0.0.2' }
53     }
54     lastTime._rev = 'asdf'
55     res.json(lastTime)
56   })
57
58   server.expect('/npm-registry-client', function (req, res) {
59     t.equal(req.method, 'PUT')
60     t.ok(lastTime)
61
62     var b = ''
63     req.setEncoding('utf8')
64     req.on('data', function (d) {
65       b += d
66     })
67
68     req.on('end', function () {
69       var o = JSON.parse(b)
70       t.equal(o._rev, 'asdf')
71       t.deepEqual(o.versions['0.0.2'], o.versions[pkg.version])
72       res.statusCode = 201
73       res.json({created: true})
74     })
75   })
76
77   var params = {
78     metadata: pkg,
79     access: 'public',
80     body: tarball,
81     auth: auth
82   }
83   client.publish('http://localhost:1337/', params, function (er, data) {
84     if (er) throw er
85     t.deepEqual(data, { created: true })
86     server.close()
87     t.end()
88   })
89 })