1var mr = require('npm-registry-mock') 2 3var test = require('tap').test 4var common = require('../common-tap.js') 5 6var server 7 8test('setup', function (t) { 9 mr({port: common.port}, function (err, s) { 10 t.ifError(err, 'registry mocked successfully') 11 server = s 12 t.end() 13 }) 14}) 15 16test('team create basic', function (t) { 17 var teamData = { 18 name: 'test', 19 scope_id: 1234, 20 created: '2015-07-23T18:07:49.959Z', 21 updated: '2015-07-23T18:07:49.959Z', 22 deleted: null 23 } 24 server.put('/-/org/myorg/team', JSON.stringify({ 25 name: teamData.name, 26 description: null 27 })).reply(200, teamData) 28 common.npm([ 29 'team', 'create', 'myorg:' + teamData.name, 30 '--registry', common.registry, 31 '--loglevel', 'error', 32 '--json' 33 ], {}, function (err, code, stdout, stderr) { 34 t.ifError(err, 'npm team') 35 t.equal(code, 0, 'exited OK') 36 t.equal(stderr, '', 'no error output') 37 t.same(JSON.parse(stdout), {created: true, team: `myorg:${teamData.name}`}) 38 t.end() 39 }) 40}) 41 42test('team create (allow optional @ prefix on scope)', function (t) { 43 var teamData = { 44 name: 'test', 45 scope_id: 1234, 46 created: '2015-07-23T18:07:49.959Z', 47 updated: '2015-07-23T18:07:49.959Z', 48 deleted: null 49 } 50 server.put('/-/org/myorg/team', JSON.stringify({ 51 name: teamData.name, 52 description: null 53 })).reply(200, teamData) 54 common.npm([ 55 'team', 'create', '@myorg:' + teamData.name, 56 '--registry', common.registry, 57 '--loglevel', 'silent', 58 '--json' 59 ], {}, function (err, code, stdout, stderr) { 60 t.ifError(err, 'npm team') 61 t.equal(code, 0, 'exited OK') 62 t.equal(stderr, '', 'no error output') 63 t.same(JSON.parse(stdout), {created: true, team: `myorg:${teamData.name}`}) 64 t.end() 65 }) 66}) 67 68test('team destroy', function (t) { 69 var teamData = { 70 name: 'myteam', 71 scope_id: 1234, 72 created: '2015-07-23T18:07:49.959Z', 73 updated: '2015-07-23T18:07:49.959Z', 74 deleted: '2015-07-23T18:27:27.178Z' 75 } 76 server.delete('/-/team/myorg/' + teamData.name).reply(200, teamData) 77 common.npm([ 78 'team', 'destroy', 'myorg:' + teamData.name, 79 '--registry', common.registry, 80 '--loglevel', 'silent', 81 '--json' 82 ], {}, function (err, code, stdout, stderr) { 83 t.ifError(err, 'npm team') 84 t.equal(code, 0, 'exited OK') 85 t.equal(stderr, '', 'no error output') 86 t.same(JSON.parse(stdout), {deleted: true, team: `myorg:${teamData.name}`}) 87 t.end() 88 }) 89}) 90 91test('team destroy is not allowed for the default developers team', (t) => { 92 const teamData = { 93 name: 'developers', 94 scope_id: 1234, 95 created: '2015-07-23T18:07:49.959Z', 96 updated: '2015-07-23T18:07:49.959Z', 97 deleted: '2015-07-23T18:27:27.178Z' 98 } 99 server.delete('/-/team/myorg/' + teamData.name).reply(405, teamData) 100 common.npm([ 101 'team', 'destroy', 'myorg:' + teamData.name, 102 '--registry', common.registry, 103 '--loglevel', 'silent', 104 '--json' 105 ], {}, function (err, code, stdout, stderr) { 106 t.ifError(err, 'npm team') 107 t.equal(code, 1, 'exited with code 1') 108 t.equal(stderr, '', 'no error output') 109 t.match(JSON.parse(stdout), {error: {code: 'E405'}}) 110 t.end() 111 }) 112}) 113 114test('team add', function (t) { 115 var user = 'zkat' 116 server.put('/-/team/myorg/myteam/user', JSON.stringify({ 117 user: user 118 })).reply(200, {}) 119 common.npm([ 120 'team', 'add', 'myorg:myteam', user, 121 '--registry', common.registry, 122 '--loglevel', 'error', 123 '--json' 124 ], {}, function (err, code, stdout, stderr) { 125 t.ifError(err, 'npm team') 126 t.equal(code, 0, 'exited OK') 127 t.equal(stderr, '', 'no error output') 128 t.end() 129 }) 130}) 131 132test('team rm', function (t) { 133 var user = 'zkat' 134 server.delete('/-/team/myorg/myteam/user', JSON.stringify({ 135 user: user 136 })).reply(200, {}) 137 common.npm([ 138 'team', 'rm', 'myorg:myteam', user, 139 '--registry', common.registry, 140 '--loglevel', 'silent', 141 '--json' 142 ], {}, function (err, code, stdout, stderr) { 143 t.ifError(err, 'npm team') 144 t.equal(code, 0, 'exited OK') 145 t.equal(stderr, '', 'no error output') 146 t.end() 147 }) 148}) 149 150test('team ls (on org)', function (t) { 151 var teams = ['myorg:team1', 'myorg:team2', 'myorg:team3'] 152 server.get('/-/org/myorg/team?format=cli').reply(200, teams) 153 common.npm([ 154 'team', 'ls', 'myorg', 155 '--registry', common.registry, 156 '--loglevel', 'silent', 157 '--json' 158 ], {}, function (err, code, stdout, stderr) { 159 t.ifError(err, 'npm team') 160 t.equal(code, 0, 'exited OK') 161 t.equal(stderr, '', 'no error output') 162 t.same(JSON.parse(stdout), teams) 163 t.end() 164 }) 165}) 166 167test('team ls (on team)', function (t) { 168 var users = ['zkat', 'bcoe'] 169 server.get('/-/team/myorg/myteam/user?format=cli').reply(200, users) 170 common.npm([ 171 'team', 'ls', 'myorg:myteam', 172 '--registry', common.registry, 173 '--loglevel', 'silent', 174 '--json' 175 ], {}, function (err, code, stdout, stderr) { 176 t.ifError(err, 'npm team') 177 t.equal(code, 0, 'exited OK') 178 t.equal(stderr, '', 'no error output') 179 t.same(JSON.parse(stdout).sort(), users.sort()) 180 t.end() 181 }) 182}) 183 184test('cleanup', function (t) { 185 t.pass('cleaned up') 186 server.done() 187 server.close() 188 t.end() 189}) 190