From 11e6cc94326da83caa24188c6ac668b463bb1364 Mon Sep 17 00:00:00 2001 From: Santosh Heigrujam Date: Wed, 15 Feb 2023 02:15:23 +0530 Subject: [PATCH] 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. --- workspaces/libnpmteam/lib/index.js | 12 ++++++---- workspaces/libnpmteam/test/index.js | 34 ++++++++++++++++++----------- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/workspaces/libnpmteam/lib/index.js b/workspaces/libnpmteam/lib/index.js index 4b257ea850d6e..9925d2c5c3bfd 100644 --- a/workspaces/libnpmteam/lib/index.js +++ b/workspaces/libnpmteam/lib/index.js @@ -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 = {}) => { @@ -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 } cmd.lsTeams = (...args) => cmd.lsTeams.stream(...args).collect() diff --git a/workspaces/libnpmteam/test/index.js b/workspaces/libnpmteam/test/index.js index fd02666e014f6..6a05519e3f71a 100644 --- a/workspaces/libnpmteam/test/index.js +++ b/workspaces/libnpmteam/test/index.js @@ -52,9 +52,11 @@ 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 => { @@ -62,10 +64,12 @@ test('destroy - no options', async t => { // 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 => { @@ -73,7 +77,7 @@ test('add', async t => { '/-/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 => { @@ -90,9 +94,11 @@ 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 => { @@ -100,10 +106,12 @@ test('rm - no options', async t => { // 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 => {