summaryrefslogtreecommitdiff
path: root/deps/npm/test/tap/owner.js
blob: 4bef1a0d87b2596066b73bcad15579ba9a43a2ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
var mr = require('npm-registry-mock')
var test = require('tap').test

var common = require('../common-tap.js')

var server

var EXEC_OPTS = {}

var jashkenas = {
  name: 'jashkenas',
  email: 'jashkenas@gmail.com'
}

var othiym23 = {
  name: 'othiym23',
  email: 'forrest@npmjs.com'
}

var bcoe = {
  name: 'bcoe',
  email: 'ben@npmjs.com'
}

function shrt (user) {
  return user.name + ' <' + user.email + '>\n'
}

function mocks (server) {
  server.get('/-/user/org.couchdb.user:othiym23')
    .many().reply(200, othiym23)

  // test 1
  server.get('/underscore')
    .reply(200, { _id: 'underscore', _rev: 1, maintainers: [jashkenas] })
  server.put(
    '/underscore/-rev/1',
    { _id: 'underscore', _rev: 1, maintainers: [jashkenas, othiym23] },
    {}
  ).reply(200, { _id: 'underscore', _rev: 2, maintainers: [jashkenas, othiym23] })

  // test 2
  server.get('/@xxx%2fscoped')
    .reply(200, { _id: '@xxx/scoped', _rev: 1, maintainers: [bcoe] })
  server.put(
    '/@xxx%2fscoped/-rev/1',
    { _id: '@xxx/scoped', _rev: 1, maintainers: [bcoe, othiym23] },
    {}
  ).reply(200, { _id: '@xxx/scoped', _rev: 2, maintainers: [bcoe, othiym23] })

  // test 3
  server.get('/underscore')
    .reply(200, { _id: 'underscore', _rev: 2, maintainers: [jashkenas, othiym23] })

  // test 4
  server.get('/underscore')
    .reply(200, { _id: 'underscore', _rev: 2, maintainers: [jashkenas, othiym23] })
  server.put(
    '/underscore/-rev/2',
    { _id: 'underscore', _rev: 2, maintainers: [jashkenas] },
    {}
  ).reply(200, { _id: 'underscore', _rev: 3, maintainers: [jashkenas] })
}

test('setup', function (t) {
  common.npm(
    [
      '--loglevel', 'silent',
      'cache', 'clean'
    ],
    EXEC_OPTS,
    function (err, code) {
      t.ifError(err, 'npm cache clean ran without error')
      t.notOk(code, 'npm cache clean exited cleanly')

      mr({ port: common.port, plugin: mocks }, function (er, s) {
        server = s
        t.end()
      })
    }
  )
})

test('npm owner add', function (t) {
  common.npm(
    [
      '--loglevel', 'silent',
      '--registry', common.registry,
      'owner', 'add', 'othiym23', 'underscore'
    ],
    EXEC_OPTS,
    function (err, code, stdout, stderr) {
      t.ifError(err, 'npm owner add ran without error')
      t.notOk(code, 'npm owner add exited cleanly')
      t.notOk(stderr, 'npm owner add ran silently')
      t.equal(stdout, '+ othiym23 (underscore)\n', 'got expected add output')

      t.end()
    }
  )
})

test('npm owner add (scoped)', function (t) {
  common.npm(
    [
      '--loglevel', 'silent',
      '--registry', common.registry,
      'owner', 'add', 'othiym23', '@xxx/scoped'
    ],
    EXEC_OPTS,
    function (err, code, stdout, stderr) {
      t.ifError(err, 'npm owner add (scoped) ran without error')
      t.notOk(code, 'npm owner add (scoped) exited cleanly')
      t.notOk(stderr, 'npm owner add (scoped) ran silently')
      t.equal(stdout, '+ othiym23 (@xxx/scoped)\n', 'got expected scoped add output')

      t.end()
    }
  )
})

test('npm owner ls', function (t) {
  common.npm(
    [
      '--loglevel', 'silent',
      '--registry', common.registry,
      'owner', 'ls', 'underscore'
    ],
    EXEC_OPTS,
    function (err, code, stdout, stderr) {
      t.ifError(err, 'npm owner ls ran without error')
      t.notOk(code, 'npm owner ls exited cleanly')
      t.notOk(stderr, 'npm owner ls ran silently')
      t.equal(stdout, shrt(jashkenas) + shrt(othiym23), 'got expected ls output')

      t.end()
    }
  )
})

test('npm owner rm', function (t) {
  common.npm(
    [
      '--loglevel', 'silent',
      '--registry', common.registry,
      'owner', 'rm', 'othiym23', 'underscore'
    ],
    EXEC_OPTS,
    function (err, code, stdout, stderr) {
      t.ifError(err, 'npm owner rm ran without error')
      t.notOk(code, 'npm owner rm exited cleanly')
      t.notOk(stderr, 'npm owner rm ran silently')
      t.equal(stdout, '- othiym23 (underscore)\n', 'got expected rm output')

      t.end()
    }
  )
})

test('cleanup', function (t) {
  server.close()
  t.end()
})