8000 fix: use npmFetch() instead of npmFetch.json() for team destroy command by heisantosh · Pull Request #6161 · npm/cli · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: use npmFetch() instead of npmFetch.json() for team destroy command #6161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 14, 2023
Merged
12 changes: 8 additions & 4 deletions workspaces/libnpmteam/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@ cmd.create = (entity, opts = {}) => {
})
}

cmd.destroy = (entity, opts = {}) => {
cmd.destroy = async (entity, opts = {}) => {
const { scope, team } = splitEntity(entity)
validate('SSO', [scope, team, opts])
const uri = `/-/team/${eu(scope)}/${eu(team)}`
return npmFetch.json(uri, {
await npmFetch(uri, {
...opts,
method: 'DELETE',
scope,
ignoreBody: true,
})
return true
}

cmd.add = (user, entity, opts = {}) => {
Expand All @@ -43,16 +45,18 @@ cmd.add = (user, entity, opts = {}) => {
})
}

cmd.rm = (user, entity, opts = {}) => {
cmd.rm = async (user, entity, opts = {}) => {
const { scope, team } = splitEntity(entity)
validate('SSO', [scope, team, opts])
const uri = `/-/team/${eu(scope)}/${eu(team)}/user`
return npmFetch.json(uri, {
await npmFetch(uri, {
...opts,
method: 'DELETE',
scope,
body: { user },
ignoreBody: true,
})
return true< 8000 /td>
}

cmd.lsTeams = (...args) => cmd.lsTeams.stream(...args).collect()
Expand Down
34 changes: 21 additions & 13 deletions workspaces/libnpmteam/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,28 +52,32 @@ test('create w/ description', async t => {
test('destroy', async t => {
tnock(t, REG).delete(
'/-/team/foo/cli'
).reply(204, {})
const ret = await team.destroy('@foo:cli', OPTS)
t.same(ret, {}, 'request succeeded')
).reply(204)
await t.resolves(
team.destroy('@foo:cli', OPTS),
'request succeeded'
)
})

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

const ret = await team.destroy('@foo:cli')
t.same(ret, {}, 'request succeeded')
await t.resolves(
team.destroy('@foo:cli'),
'request succeeded'
)
})

test('add', async t => {
tnock(t, REG).put(
'/-/team/foo/cli/user', { user: 'zkat' }
).reply(201, {})
const ret = await team.add('zkat', '@foo:cli', OPTS)
t.same(ret, {}, 'request succeeded')
t.ok(ret, 'request succeeded')
})

test('add - no options', async t => {
Expand All @@ -90,20 +94,24 @@ test('add - no options', async t => {
test('rm', async t => {
tnock(t, REG).delete(
'/-/team/foo/cli/user', { user: 'zkat' }
).reply(204, {})
const ret = await team.rm('zkat', '@foo:cli', OPTS)
t.same(ret, {}, 'request succeeded')
).reply(204)
await t.resolves(
team.rm('zkat', '@foo:cli', OPTS),
'request succeeded'
)
})

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

const ret = await team.rm('zkat', '@foo:cli')
t.same(ret, {}, 'request succeeded')
await t.resolves(
team.rm('zkat', '@foo:cli'),
'request succeeded'
)
})

test('lsTeams', async t => {
Expand Down
0