• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1var mr = require('npm-registry-mock')
2var test = require('tap').test
3
4var common = require('../common-tap.js')
5var basedir = common.pkg
6var cachedir = common.cache
7
8var server
9
10var EXEC_OPTS = {
11  cwd: basedir,
12  stdio: [0, 'pipe', 2],
13  env: common.newEnv().extend({
14    npm_config_cache: cachedir
15  })
16}
17
18var jashkenas = {
19  name: 'jashkenas',
20  email: 'jashkenas@gmail.com'
21}
22
23var othiym23 = {
24  name: 'othiym23',
25  email: 'forrest@npmjs.com'
26}
27
28var bcoe = {
29  name: 'bcoe',
30  email: 'ben@npmjs.com'
31}
32
33function shrt (user) {
34  return user.name + ' <' + user.email + '>\n'
35}
36
37function mocks (server) {
38  server.get('/-/user/org.couchdb.user:othiym23')
39    .many().reply(200, othiym23)
40
41  // test 1
42  server.get('/underscore')
43    .reply(200, { _id: 'underscore', _rev: 1, maintainers: [jashkenas] })
44  server.put(
45    '/underscore/-rev/1',
46    { _id: 'underscore', _rev: 1, maintainers: [jashkenas, othiym23] },
47    {}
48  ).reply(200, { _id: 'underscore', _rev: 2, maintainers: [jashkenas, othiym23] })
49
50  // test 2
51  server.get('/@xxx%2fscoped')
52    .reply(200, { _id: '@xxx/scoped', _rev: 1, maintainers: [bcoe] })
53  server.put(
54    '/@xxx%2fscoped/-rev/1',
55    { _id: '@xxx/scoped', _rev: 1, maintainers: [bcoe, othiym23] },
56    {}
57  ).reply(200, { _id: '@xxx/scoped', _rev: 2, maintainers: [bcoe, othiym23] })
58
59  // test 3
60  server.get('/underscore')
61    .reply(200, { _id: 'underscore', _rev: 2, maintainers: [jashkenas, othiym23] })
62
63  // test 4
64  server.get('/underscore')
65    .reply(200, { _id: 'underscore', _rev: 2, maintainers: [jashkenas, othiym23] })
66  server.put(
67    '/underscore/-rev/2',
68    { _id: 'underscore', _rev: 2, maintainers: [jashkenas] },
69    {}
70  ).reply(200, { _id: 'underscore', _rev: 3, maintainers: [jashkenas] })
71}
72
73test('setup', function (t) {
74  mr({ port: common.port, plugin: mocks }, function (er, s) {
75    server = s
76    t.end()
77  })
78})
79
80test('npm owner add', function (t) {
81  common.npm(
82    [
83      '--loglevel', 'warn',
84      '--registry', common.registry,
85      'owner', 'add', 'othiym23', 'underscore'
86    ],
87    EXEC_OPTS,
88    function (err, code, stdout, stderr) {
89      t.ifError(err, 'npm owner add ran without error')
90      t.notOk(code, 'npm owner add exited cleanly')
91      t.notOk(stderr, 'npm owner add ran silently')
92      t.equal(stdout, '+ othiym23 (underscore)\n', 'got expected add output')
93
94      t.end()
95    }
96  )
97})
98
99test('npm owner add (scoped)', function (t) {
100  common.npm(
101    [
102      '--loglevel', 'silent',
103      '--registry', common.registry,
104      'owner', 'add', 'othiym23', '@xxx/scoped'
105    ],
106    EXEC_OPTS,
107    function (err, code, stdout, stderr) {
108      t.ifError(err, 'npm owner add (scoped) ran without error')
109      t.notOk(code, 'npm owner add (scoped) exited cleanly')
110      t.notOk(stderr, 'npm owner add (scoped) ran silently')
111      t.equal(stdout, '+ othiym23 (@xxx/scoped)\n', 'got expected scoped add output')
112
113      t.end()
114    }
115  )
116})
117
118test('npm owner ls', function (t) {
119  common.npm(
120    [
121      '--loglevel', 'silent',
122      '--registry', common.registry,
123      'owner', 'ls', 'underscore'
124    ],
125    EXEC_OPTS,
126    function (err, code, stdout, stderr) {
127      t.ifError(err, 'npm owner ls ran without error')
128      t.notOk(code, 'npm owner ls exited cleanly')
129      t.notOk(stderr, 'npm owner ls ran silently')
130      t.equal(stdout, shrt(jashkenas) + shrt(othiym23), 'got expected ls output')
131
132      t.end()
133    }
134  )
135})
136
137test('npm owner rm', function (t) {
138  common.npm(
139    [
140      '--loglevel', 'silent',
141      '--registry', common.registry,
142      'owner', 'rm', 'othiym23', 'underscore'
143    ],
144    EXEC_OPTS,
145    function (err, code, stdout, stderr) {
146      t.ifError(err, 'npm owner rm ran without error')
147      t.notOk(code, 'npm owner rm exited cleanly')
148      t.notOk(stderr, 'npm owner rm ran silently')
149      t.equal(stdout, '- othiym23 (underscore)\n', 'got expected rm output')
150
151      t.end()
152    }
153  )
154})
155
156test('cleanup', function (t) {
157  server.close()
158  t.end()
159})
160