Skip to content
This repository was archived by the owner on Jan 19, 2022. It is now read-only.

Commit ea19e24

Browse files
author
Michael Perrotte
committedFeb 27, 2020
test: added tests; 100% code coverage ✅💯
1 parent 9e95457 commit ea19e24

File tree

3 files changed

+105
-1
lines changed

3 files changed

+105
-1
lines changed
 

‎index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const validate = require('aproba')
66

77
const cmd = module.exports = {}
88

9-
cmd.create = (entity, opts = { description: undefined }) => {
9+
cmd.create = (entity, opts = {}) => {
1010
return Promise.resolve().then(() => {
1111
const { scope, team } = splitEntity(entity)
1212
validate('SSO', [scope, team, opts])

‎test/fixtures/tnock.js

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
const nock = require('nock')
44

5+
nock.disableNetConnect()
6+
57
module.exports = tnock
68
function tnock (t, host) {
79
const server = nock(host)

‎test/index.js

+102
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@ test('create', t => {
1919
})
2020
})
2121

22+
test('create - no options', t => {
23+
// NOTE: mocking real url, because no opts variable means `registry` value
24+
// will be defauled to real registry url in `npm-registry-fetch`
25+
tnock(t, 'https://registry.npmjs.org')
26+
.put('/-/org/foo/team', { name: 'cli' })
27+
.reply(201, { name: 'cli' })
28+
29+
return team.create('@foo:cli')
30+
.then(ret => {
31+
t.deepEqual(ret, { name: 'cli' })
32+
})
33+
})
34+
2235
test('create bad entity name', t => {
2336
return team.create('go away', OPTS).then(
2437
() => { throw new Error('should not succeed') },
@@ -55,6 +68,18 @@ test('destroy', t => {
5568
})
5669
})
5770

71+
test('destroy - no options', t => {
72+
// NOTE: mocking real url, because no opts variable means `registry` value
73+
// will be defauled to real registry url in `npm-registry-fetch`
74+
tnock(t, 'https://registry.npmjs.org')
75+
.delete('/-/team/foo/cli')
76+
.reply(204, {})
77+
78+
return team.destroy('@foo:cli').then(ret => {
79+
t.deepEqual(ret, {}, 'request succeeded')
80+
})
81+
})
82+
5883
test('add', t => {
5984
tnock(t, REG).put(
6085
'/-/team/foo/cli/user', { user: 'zkat' }
@@ -64,6 +89,18 @@ test('add', t => {
6489
})
6590
})
6691

92+
test('add - no options', t => {
93+
// NOTE: mocking real url, because no opts variable means `registry` value
94+
// will be defauled to real registry url in `npm-registry-fetch`
95+
tnock(t, 'https://registry.npmjs.org')
96+
.put('/-/team/foo/cli/user', { user: 'zkat' })
97+
.reply(201, {})
98+
99+
return team.add('zkat', '@foo:cli').then(ret => {
100+
t.deepEqual(ret, {}, 'request succeeded')
101+
})
102+
})
103+
67104
test('rm', t => {
68105
tnock(t, REG).delete(
69106
'/-/team/foo/cli/user', { user: 'zkat' }
@@ -73,6 +110,18 @@ test('rm', t => {
73110
})
74111
})
75112

113+
test('rm - no options', t => {
114+
// NOTE: mocking real url, because no opts variable means `registry` value
115+
// will be defauled to real registry url in `npm-registry-fetch`
116+
tnock(t, 'https://registry.npmjs.org')
117+
.delete('/-/team/foo/cli/user', { user: 'zkat' })
118+
.reply(204, {})
119+
120+
return team.rm('zkat', '@foo:cli').then(ret => {
121+
t.deepEqual(ret, {}, 'request succeeded')
122+
})
123+
})
124+
76125
test('lsTeams', t => {
77126
tnock(t, REG).get(
78127
'/-/org/foo/team?format=cli'
@@ -82,6 +131,18 @@ test('lsTeams', t => {
82131
})
83132
})
84133

134+
test('lsTeams - no options', t => {
135+
// NOTE: mocking real url, because no opts variable means `registry` value
136+
// will be defauled to real registry url in `npm-registry-fetch`
137+
tnock(t, 'https://registry.npmjs.org')
138+
.get('/-/org/foo/team?format=cli')
139+
.reply(200, ['foo:bar', 'foo:cli'])
140+
141+
return team.lsTeams('foo').then(ret => {
142+
t.deepEqual(ret, ['foo:bar', 'foo:cli'], 'got teams')
143+
})
144+
})
145+
85146
test('lsTeams error', t => {
86147
tnock(t, REG).get(
87148
'/-/org/foo/team?format=cli'
@@ -103,6 +164,20 @@ test('lsTeams.stream', t => {
103164
})
104165
})
105166

167+
test('lsTeams.stream - no options', t => {
168+
// NOTE: mocking real url, because no opts variable means `registry` value
169+
// will be defauled to real registry url in `npm-registry-fetch`
170+
tnock(t, 'https://registry.npmjs.org')
171+
.get('/-/org/foo/team?format=cli')
172+
.reply(200, ['foo:bar', 'foo:cli'])
173+
174+
return team.lsTeams.stream('foo')
175+
.collect()
176+
.then(ret => {
177+
t.deepEqual(ret, ['foo:bar', 'foo:cli'], 'got teams')
178+
})
179+
})
180+
106181
test('lsUsers', t => {
107182
tnock(t, REG).get(
108183
'/-/team/foo/cli/user?format=cli'
@@ -113,6 +188,19 @@ test('lsUsers', t => {
113188
)
114189
})
115190

191+
test('lsUsers - no options', t => {
192+
// NOTE: mocking real url, because no opts variable means `registry` value
193+
// will be defauled to real registry url in `npm-registry-fetch`
194+
tnock(t, 'https://registry.npmjs.org')
195+
.get('/-/team/foo/cli/user?format=cli')
196+
.reply(500)
197+
198+
return team.lsUsers('@foo:cli').then(
199+
() => { throw new Error('should not succeed') },
200+
err => { t.equal(err.code, 'E500', 'got error code') }
201+
)
202+
})
203+
116204
test('lsUsers error', t => {
117205
tnock(t, REG).get(
118206
'/-/team/foo/cli/user?format=cli'
@@ -133,6 +221,20 @@ test('lsUsers.stream', t => {
133221
})
134222
})
135223

224+
test('lsUsers.stream - no options', t => {
225+
// NOTE: mocking real url, because no opts variable means `registry` value
226+
// will be defauled to real registry url in `npm-registry-fetch`
227+
tnock(t, 'https://registry.npmjs.org')
228+
.get('/-/team/foo/cli/user?format=cli')
229+
.reply(200, ['iarna', 'zkat'])
230+
231+
return team.lsUsers.stream('@foo:cli')
232+
.collect()
233+
.then(ret => {
234+
t.deepEqual(ret, ['iarna', 'zkat'], 'got team members')
235+
})
236+
})
237+
136238
test('edit', t => {
137239
t.throws(() => {
138240
team.edit()

0 commit comments

Comments
 (0)
This repository has been archived.