diff --git a/command-snapshot.json b/command-snapshot.json index 84f1bb17..a34ee24e 100644 --- a/command-snapshot.json +++ b/command-snapshot.json @@ -8,7 +8,7 @@ { "command": "env:compute:collaborator:add", "plugin": "@salesforce/plugin-functions", - "flags": ["heroku-user"], + "flags": ["heroku-user", "json"], "alias": [] }, { diff --git a/src/commands/env/compute/collaborator/add.ts b/src/commands/env/compute/collaborator/add.ts index 82d787e7..926047d5 100644 --- a/src/commands/env/compute/collaborator/add.ts +++ b/src/commands/env/compute/collaborator/add.ts @@ -16,8 +16,6 @@ Messages.importMessagesDirectory(__dirname); const messages = Messages.loadMessages('@salesforce/plugin-functions', 'env.compute.collaborator.add'); export default class ComputeCollaboratorAdd extends Command { - static enableJsonFlag = false; - static summary = messages.getMessage('summary'); static examples = messages.getMessages('examples'); @@ -64,7 +62,7 @@ export default class ComputeCollaboratorAdd extends Command { } if (error.message?.includes('404')) { - this.error(`${herokuColor.heroku(herokuUser)} does not exist.`); + this.error(`Couldn't find Heroku user ${herokuColor.heroku(herokuUser)}.`); } this.error(error.message); @@ -74,5 +72,8 @@ export default class ComputeCollaboratorAdd extends Command { this.log( 'For more information about attaching Heroku add-ons to your compute environments, run $ heroku addons:attach --help.' ); + return { + added: [`${herokuUser}`], + }; } } diff --git a/test/commands/env/compute/collaborator/add.test.ts b/test/commands/env/compute/collaborator/add.test.ts index 450423dc..89d48da6 100644 --- a/test/commands/env/compute/collaborator/add.test.ts +++ b/test/commands/env/compute/collaborator/add.test.ts @@ -9,6 +9,14 @@ import herokuColor from '@heroku-cli/color'; const HEROKU_USER = 'rick@morty.com'; +const jsonSuccess = { + status: 0, + result: { + added: [HEROKU_USER], + }, + warnings: [], +}; + describe('sf env compute collaborator add', () => { test .stdout() @@ -33,13 +41,25 @@ describe('sf env compute collaborator add', () => { ); }); + test + .stdout() + .stderr() + .nock('https://api.heroku.com', (api) => api.post('/salesforce-orgs/collaborators').reply(200, {})) + .command(['env:compute:collaborator:add', '-h', HEROKU_USER, '--json']) + .it('will show json output with success', (ctx) => { + const succJSON = JSON.parse(ctx.stdout); + + expect(succJSON.status).to.deep.equal(jsonSuccess.status); + expect(succJSON.result).to.eql(jsonSuccess.result); + }); + test .stdout() .stderr() .nock('https://api.heroku.com', (api) => api.post('/salesforce-orgs/collaborators').reply(404, {})) .command(['env:compute:collaborator:add', '-h', HEROKU_USER]) .catch((error) => { - expect(error.message).contains(`${herokuColor.heroku(HEROKU_USER)} does not exist.`); + expect(error.message).contains(`Couldn't find Heroku user ${herokuColor.heroku(HEROKU_USER)}.`); }) .it('alerts user if user entered does not exist'); });