2014-04-13 04:04:48 +02:00
|
|
|
var assert = require('assert')
|
|
|
|
|
|
|
|
function readfile(x) {
|
2014-11-12 12:14:37 +01:00
|
|
|
return require('fs').readFileSync(__dirname + '/' + x)
|
2014-04-13 04:04:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function sha(x) {
|
2014-11-12 12:14:37 +01:00
|
|
|
return require('crypto').createHash('sha1', 'binary').update(x).digest('hex')
|
2014-04-13 04:04:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = function() {
|
2014-11-12 12:14:37 +01:00
|
|
|
var server = process.server
|
|
|
|
var server2 = process.server2
|
|
|
|
var express = process.express
|
2014-04-13 04:04:48 +02:00
|
|
|
|
2014-11-12 12:14:37 +01:00
|
|
|
describe('newnpmreg', function() {
|
2015-04-11 19:11:04 +02:00
|
|
|
before(function () {
|
|
|
|
return server.request({
|
2014-11-12 12:14:37 +01:00
|
|
|
uri: '/testpkg-newnpmreg',
|
|
|
|
headers: {
|
|
|
|
'content-type': 'application/json',
|
|
|
|
},
|
|
|
|
method: 'PUT',
|
|
|
|
json: JSON.parse(readfile('fixtures/newnpmreg.json')),
|
2015-04-11 19:11:04 +02:00
|
|
|
}).status(201)
|
2014-11-12 12:14:37 +01:00
|
|
|
})
|
2014-04-13 04:04:48 +02:00
|
|
|
|
2015-04-11 19:11:04 +02:00
|
|
|
it('add pkg', function () {})
|
2014-04-13 04:04:48 +02:00
|
|
|
|
2015-04-11 19:11:04 +02:00
|
|
|
it('server1 - tarball', function () {
|
|
|
|
return server.get_tarball('testpkg-newnpmreg', 'testpkg-newnpmreg-0.0.0.tgz')
|
|
|
|
.status(200)
|
|
|
|
.then(function (body) {
|
|
|
|
// not real sha due to utf8 conversion
|
2016-07-30 21:02:50 +02:00
|
|
|
assert.strictEqual(sha(body), '8ee7331cbc641581b1a8cecd9d38d744a8feb863')
|
2015-04-11 19:11:04 +02:00
|
|
|
})
|
2014-11-12 12:14:37 +01:00
|
|
|
})
|
2014-04-13 04:04:48 +02:00
|
|
|
|
2015-04-11 19:11:04 +02:00
|
|
|
it('server2 - tarball', function () {
|
|
|
|
return server2.get_tarball('testpkg-newnpmreg', 'testpkg-newnpmreg-0.0.0.tgz')
|
|
|
|
.status(200)
|
|
|
|
.then(function (body) {
|
|
|
|
// not real sha due to utf8 conversion
|
2016-07-30 21:02:50 +02:00
|
|
|
assert.strictEqual(sha(body), '8ee7331cbc641581b1a8cecd9d38d744a8feb863')
|
2015-04-11 19:11:04 +02:00
|
|
|
})
|
2014-11-12 12:14:37 +01:00
|
|
|
})
|
2014-04-13 04:04:48 +02:00
|
|
|
|
2015-04-11 19:11:04 +02:00
|
|
|
it('server1 - package', function () {
|
|
|
|
return server.get_package('testpkg-newnpmreg')
|
|
|
|
.status(200)
|
|
|
|
.then(function (body) {
|
|
|
|
assert.equal(body.name, 'testpkg-newnpmreg')
|
|
|
|
assert.equal(body.versions['0.0.0'].name, 'testpkg-newnpmreg')
|
|
|
|
assert.equal(body.versions['0.0.0'].dist.tarball, 'http://localhost:55551/testpkg-newnpmreg/-/testpkg-newnpmreg-0.0.0.tgz')
|
|
|
|
assert.deepEqual(body['dist-tags'], {foo: '0.0.0', latest: '0.0.0'})
|
|
|
|
})
|
2014-11-12 12:14:37 +01:00
|
|
|
})
|
2014-04-13 04:04:48 +02:00
|
|
|
|
2015-04-11 19:11:04 +02:00
|
|
|
it('server2 - package', function () {
|
|
|
|
return server2.get_package('testpkg-newnpmreg')
|
|
|
|
.status(200)
|
|
|
|
.then(function (body) {
|
|
|
|
assert.equal(body.name, 'testpkg-newnpmreg')
|
|
|
|
assert.equal(body.versions['0.0.0'].name, 'testpkg-newnpmreg')
|
|
|
|
assert.equal(body.versions['0.0.0'].dist.tarball, 'http://localhost:55552/testpkg-newnpmreg/-/testpkg-newnpmreg-0.0.0.tgz')
|
|
|
|
assert.deepEqual(body['dist-tags'], {foo: '0.0.0', latest: '0.0.0'})
|
|
|
|
})
|
2014-11-12 12:14:37 +01:00
|
|
|
})
|
2014-09-25 05:56:31 +02:00
|
|
|
|
2015-04-11 19:11:04 +02:00
|
|
|
it('server1 - readme', function () {
|
|
|
|
return server.request({ uri: '/-/readme/testpkg-newnpmreg' })
|
|
|
|
.status(200)
|
|
|
|
.then(function (body) {
|
|
|
|
assert.equal(body, '<p>blah blah blah</p>\n')
|
|
|
|
})
|
2014-11-12 12:14:37 +01:00
|
|
|
})
|
2014-09-25 05:56:31 +02:00
|
|
|
|
2015-04-11 19:11:04 +02:00
|
|
|
it('server2 - readme', function () {
|
|
|
|
return server2.request({ uri: '/-/readme/testpkg-newnpmreg' })
|
|
|
|
.status(200)
|
|
|
|
.then(function (body) {
|
|
|
|
assert.equal(body, '<p>blah blah blah</p>\n')
|
|
|
|
})
|
2014-11-12 12:14:37 +01:00
|
|
|
})
|
2014-10-02 09:14:59 +02:00
|
|
|
|
2014-11-12 12:14:37 +01:00
|
|
|
describe('search', function() {
|
|
|
|
function check(obj) {
|
2015-04-11 19:11:04 +02:00
|
|
|
obj['testpkg-newnpmreg'].time.modified = '2014-10-02T07:07:51.000Z'
|
|
|
|
assert.deepEqual(obj['testpkg-newnpmreg'],
|
|
|
|
{ name: 'testpkg-newnpmreg',
|
|
|
|
description: '',
|
2015-05-17 00:29:16 +02:00
|
|
|
author: '',
|
|
|
|
license: 'ISC',
|
2015-04-11 19:11:04 +02:00
|
|
|
'dist-tags': { latest: '0.0.0' },
|
|
|
|
maintainers: [ { name: 'alex', email: 'alex@kocharin.ru' } ],
|
|
|
|
readmeFilename: '',
|
|
|
|
time: { modified: '2014-10-02T07:07:51.000Z' },
|
2015-05-17 00:29:16 +02:00
|
|
|
versions: {},
|
2015-04-11 19:11:04 +02:00
|
|
|
repository: { type: 'git', url: '' } })
|
2014-11-12 12:14:37 +01:00
|
|
|
}
|
2014-10-02 09:14:59 +02:00
|
|
|
|
2015-04-11 19:11:04 +02:00
|
|
|
before(function () {
|
2014-11-12 12:14:37 +01:00
|
|
|
express.get('/-/all', function(req, res) {
|
|
|
|
res.send({})
|
|
|
|
})
|
|
|
|
})
|
2014-10-02 09:14:59 +02:00
|
|
|
|
2015-04-11 19:11:04 +02:00
|
|
|
it('server1 - search', function () {
|
|
|
|
return server.request({ uri: '/-/all' })
|
|
|
|
.status(200)
|
|
|
|
.then(check)
|
2014-11-12 12:14:37 +01:00
|
|
|
})
|
2014-10-02 09:14:59 +02:00
|
|
|
|
2015-04-11 19:11:04 +02:00
|
|
|
it('server2 - search', function () {
|
|
|
|
return server2.request({ uri: '/-/all' })
|
|
|
|
.status(200)
|
|
|
|
.then(check)
|
2014-11-12 12:14:37 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2014-04-13 04:04:48 +02:00
|
|
|
}
|