Skip to content

Commit 11e6cc9

Browse files
authored
fix: use npmFetch() instead of npmFetch.json() for team destroy command (#6161)
The registry returns a 204 status and an empty body on success for the team destroy command. Using npmFetch.json() makes the CLI error out on completion even though the action was completed successfully in the registry.
1 parent fef6ca0 commit 11e6cc9

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

workspaces/libnpmteam/lib/index.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,17 @@ cmd.create = (entity, opts = {}) => {
2020
})
2121
}
2222

23-
cmd.destroy = (entity, opts = {}) => {
23+
cmd.destroy = async (entity, opts = {}) => {
2424
const { scope, team } = splitEntity(entity)
2525
validate('SSO', [scope, team, opts])
2626
const uri = `/-/team/${eu(scope)}/${eu(team)}`
27-
return npmFetch.json(uri, {
27+
await npmFetch(uri, {
2828
...opts,
2929
method: 'DELETE',
3030
scope,
31+
ignoreBody: true,
3132
})
33+
return true
3234
}
3335

3436
cmd.add = (user, entity, opts = {}) => {
@@ -43,16 +45,18 @@ cmd.add = (user, entity, opts = {}) => {
4345
})
4446
}
4547

46-
cmd.rm = (user, entity, opts = {}) => {
48+
cmd.rm = async (user, entity, opts = {}) => {
4749
const { scope, team } = splitEntity(entity)
4850
validate('SSO', [scope, team, opts])
4951
const uri = `/-/team/${eu(scope)}/${eu(team)}/user`
50-
return npmFetch.json(uri, {
52+
await npmFetch(uri, {
5153
...opts,
5254
method: 'DELETE',
5355
scope,
5456
body: { user },
57+
ignoreBody: true,
5558
})
59+
return true
5660
}
5761

5862
cmd.lsTeams = (...args) => cmd.lsTeams.stream(...args).collect()

workspaces/libnpmteam/test/index.js

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,28 +52,32 @@ test('create w/ description', async t => {
5252
test('destroy', async t => {
5353
tnock(t, REG).delete(
5454
'/-/team/foo/cli'
55-
).reply(204, {})
56-
const ret = await team.destroy('@foo:cli', OPTS)
57-
t.same(ret, {}, 'request succeeded')
55+
).reply(204)
56+
await t.resolves(
57+
team.destroy('@foo:cli', OPTS),
58+
'request succeeded'
59+
)
5860
})
5961

6062
test('destroy - no options', async t => {
6163
// NOTE: mocking real url, because no opts variable means `registry` value
6264
// will be defauled to real registry url in `npm-registry-fetch`
6365
tnock(t, 'https://registry.npmjs.org')
6466
.delete('/-/team/foo/cli')
65-
.reply(204, {})
67+
.reply(204)
6668

67-
const ret = await team.destroy('@foo:cli')
68-
t.same(ret, {}, 'request succeeded')
69+
await t.resolves(
70+
team.destroy('@foo:cli'),
71+
'request succeeded'
72+
)
6973
})
7074

7175
test('add', async t => {
7276
tnock(t, REG).put(
7377
'/-/team/foo/cli/user', { user: 'zkat' }
7478
).reply(201, {})
7579
const ret = await team.add('zkat', '@foo:cli', OPTS)
76-
t.same(ret, {}, 'request succeeded')
80+
t.ok(ret, 'request succeeded')
7781
})
7882

7983
test('add - no options', async t => {
@@ -90,20 +94,24 @@ test('add - no options', async t => {
9094
test('rm', async t => {
9195
tnock(t, REG).delete(
9296
'/-/team/foo/cli/user', { user: 'zkat' }
93-
).reply(204, {})
94-
const ret = await team.rm('zkat', '@foo:cli', OPTS)
95-
t.same(ret, {}, 'request succeeded')
97+
).reply(204)
98+
await t.resolves(
99+
team.rm('zkat', '@foo:cli', OPTS),
100+
'request succeeded'
101+
)
96102
})
97103

98104
test('rm - no options', async t => {
99105
// NOTE: mocking real url, because no opts variable means `registry` value
100106
// will be defauled to real registry url in `npm-registry-fetch`
101107
tnock(t, 'https://registry.npmjs.org')
102108
.delete('/-/team/foo/cli/user', { user: 'zkat' })
103-
.reply(204, {})
109+
.reply(204)
104110

105-
const ret = await team.rm('zkat', '@foo:cli')
106-
t.same(ret, {}, 'request succeeded')
111+
await t.resolves(
112+
team.rm('zkat', '@foo:cli'),
113+
'request succeeded'
114+
)
107115
})
108116

109117
test('lsTeams', async t => {

0 commit comments

Comments
 (0)