X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.maps.server%2Fnode%2Fnode-v4.8.0-win-x64%2Fnode_modules%2Fnpm%2Fnode_modules%2Fnpm-registry-client%2Ftest%2Fpublish-again.js;fp=org.simantics.maps.server%2Fnode%2Fnode-v4.8.0-win-x64%2Fnode_modules%2Fnpm%2Fnode_modules%2Fnpm-registry-client%2Ftest%2Fpublish-again.js;h=4a895205ea28458ea6d82bedd9ca4fb3b177e958;hb=2529be6d456deeb07c128603ce4971f1dc29b695;hp=0000000000000000000000000000000000000000;hpb=2636fc31c16c23711cf2b06a4ae8537bba9c1d35;p=simantics%2Fdistrict.git diff --git a/org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/node_modules/npm-registry-client/test/publish-again.js b/org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/node_modules/npm-registry-client/test/publish-again.js new file mode 100644 index 00000000..4a895205 --- /dev/null +++ b/org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/node_modules/npm-registry-client/test/publish-again.js @@ -0,0 +1,89 @@ +var tap = require('tap') +var fs = require('fs') + +var server = require('./lib/server.js') +var common = require('./lib/common.js') + +var auth = { + username: 'username', + password: '%1234@asdf%', + email: 'i@izs.me', + alwaysAuth: true +} + +var client = common.freshClient() + +tap.test('publish again', function (t) { + // not really a tarball, but doesn't matter + var bodyPath = require.resolve('../package.json') + var tarball = fs.createReadStream(bodyPath) + var pd = fs.readFileSync(bodyPath) + var pkg = require('../package.json') + var lastTime = null + + server.expect('/npm-registry-client', function (req, res) { + t.equal(req.method, 'PUT') + var b = '' + req.setEncoding('utf8') + req.on('data', function (d) { + b += d + }) + + req.on('end', function () { + var o = lastTime = JSON.parse(b) + t.equal(o._id, 'npm-registry-client') + t.equal(o['dist-tags'].latest, pkg.version) + t.has(o.versions[pkg.version], pkg) + t.same(o.maintainers, [ { name: 'username', email: 'i@izs.me' } ]) + var att = o._attachments[ pkg.name + '-' + pkg.version + '.tgz' ] + t.same(att.data, pd.toString('base64')) + res.statusCode = 409 + res.json({reason: 'must supply latest _rev to update existing package'}) + }) + }) + + server.expect('/npm-registry-client?write=true', function (req, res) { + t.equal(req.method, 'GET') + t.ok(lastTime) + for (var i in lastTime.versions) { + var v = lastTime.versions[i] + delete lastTime.versions[i] + lastTime.versions['0.0.2'] = v + lastTime['dist-tags'] = { latest: '0.0.2' } + } + lastTime._rev = 'asdf' + res.json(lastTime) + }) + + server.expect('/npm-registry-client', function (req, res) { + t.equal(req.method, 'PUT') + t.ok(lastTime) + + var b = '' + req.setEncoding('utf8') + req.on('data', function (d) { + b += d + }) + + req.on('end', function () { + var o = JSON.parse(b) + t.equal(o._rev, 'asdf') + t.deepEqual(o.versions['0.0.2'], o.versions[pkg.version]) + res.statusCode = 201 + res.json({created: true}) + }) + }) + + var params = { + metadata: pkg, + access: 'public', + body: tarball, + auth: auth + } + client.publish('http://localhost:1337/', params, function (er, data) { + if (er) throw er + t.deepEqual(data, { created: true }) + server.close() + t.end() + }) +})