]> 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/stars.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 / stars.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 function nop () {}
8
9 var URI = 'https://npm.registry:8043/rewrite'
10 var USERNAME = 'sample'
11 var PASSWORD = '%1234@asdf%'
12 var EMAIL = 'i@izs.me'
13 var AUTH = {
14   username: USERNAME,
15   password: PASSWORD,
16   email: EMAIL
17 }
18 var PARAMS = {
19   username: USERNAME,
20   auth: AUTH
21 }
22 var USERS = [
23   'benjamincoe',
24   'seldo',
25   'ceejbot'
26 ]
27
28 test('stars call contract', function (t) {
29   t.throws(function () {
30     client.stars(undefined, PARAMS, nop)
31   }, 'requires a URI')
32
33   t.throws(function () {
34     client.stars([], PARAMS, nop)
35   }, 'requires URI to be a string')
36
37   t.throws(function () {
38     client.stars(URI, undefined, nop)
39   }, 'requires params object')
40
41   t.throws(function () {
42     client.stars(URI, '', nop)
43   }, 'params must be object')
44
45   t.throws(function () {
46     client.stars(URI, PARAMS, undefined)
47   }, 'requires callback')
48
49   t.throws(function () {
50     client.stars(URI, PARAMS, 'callback')
51   }, 'callback must be function')
52
53   t.test('no username anywhere', function (t) {
54     var params = {}
55     client.stars(URI, params, function (err) {
56       t.equal(
57         err && err.message,
58         'must pass either username or auth to stars',
59         'username must not be empty')
60       t.end()
61     })
62   })
63
64   t.end()
65 })
66
67 test('get the stars for a package', function (t) {
68   server.expect('GET', '/-/_view/starredByUser?key=%22sample%22', function (req, res) {
69     t.equal(req.method, 'GET')
70
71     res.json(USERS)
72   })
73
74   client.stars('http://localhost:1337/', PARAMS, function (er, info) {
75     t.ifError(er, 'no errors')
76     t.deepEqual(info, USERS, 'got the list of users')
77
78     server.close()
79     t.end()
80   })
81 })