-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'prerelease/9.0.0-alpha' into jw/certs-v5/migrate-genera…
…te-command
- Loading branch information
Showing
10 changed files
with
114 additions
and
267 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import color from '@heroku-cli/color' | ||
import {Command, flags} from '@heroku-cli/command' | ||
import {ux} from '@oclif/core' | ||
import * as Heroku from '@heroku-cli/schema' | ||
|
||
export default class Leave extends Command { | ||
static topic = 'apps' | ||
static aliases = ['leave']; | ||
static description = 'remove yourself from a team app' | ||
static example = 'heroku apps:leave -a APP' | ||
static flags = { | ||
app: flags.app({required: true}), | ||
remote: flags.remote(), | ||
} | ||
|
||
public async run(): Promise<void> { | ||
const {flags} = await this.parse(Leave) | ||
const {app} = flags | ||
const request = await this.heroku.get<Heroku.Account>('/account') | ||
ux.action.start(`Leaving ${color.cyan(app)}`) | ||
const {body: account} = request | ||
await this.heroku.delete(`/apps/${app}/collaborators/${encodeURIComponent(account.email as string)}`) | ||
ux.action.stop() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import {stdout, stderr} from 'stdout-stderr' | ||
import Cmd from '../../../../src/commands/apps/leave' | ||
import runCommand from '../../../helpers/runCommand' | ||
import * as nock from 'nock' | ||
import {expect} from '@oclif/test' | ||
|
||
function mockUserAccount(email = 'raulb@heroku.com') { | ||
return nock('https://api.heroku.com:443') | ||
.get('/account') | ||
.reply(200, {email}) | ||
} | ||
|
||
function mockCollaboratorsPersonalApp(app: string, email: string) { | ||
return nock('https://api.heroku.com:443', {}) | ||
.delete(`/apps/${app}/collaborators/${encodeURIComponent(email)}`) | ||
.reply(200, {}) | ||
} | ||
|
||
function mockCollaboratorsPersonalAppDeleteFailure(app: string, email: string) { | ||
return nock('https://api.heroku.com:443', {}) | ||
.delete(`/apps/${app}/collaborators/${encodeURIComponent(email)}`).reply(404, {}) | ||
} | ||
|
||
describe('heroku apps:leave', () => { | ||
let apiGetUserAccount: ReturnType<typeof mockUserAccount> | ||
let apiDeletePersonalAppCollaborator: ReturnType<typeof mockCollaboratorsPersonalApp> | ||
|
||
beforeEach(() => { | ||
apiGetUserAccount = mockUserAccount() | ||
apiDeletePersonalAppCollaborator = mockCollaboratorsPersonalApp('myapp', 'raulb@heroku.com') | ||
}) | ||
|
||
afterEach(() => nock.cleanAll()) | ||
|
||
context('when it is an org app', () => { | ||
it('leaves the app', async () => { | ||
await runCommand(Cmd, [ | ||
'--app', | ||
'myapp', | ||
]) | ||
expect('').to.eq(stdout.output) | ||
expect(stderr.output).to.eq('Leaving myapp...\nLeaving myapp... done\n') | ||
apiGetUserAccount.done() | ||
apiDeletePersonalAppCollaborator.done() | ||
}) | ||
}) | ||
|
||
context('when it is not an org app', () => { | ||
it('leaves the app', async () => { | ||
await runCommand(Cmd, [ | ||
'--app', | ||
'myapp', | ||
]) | ||
expect('').to.eq(stdout.output) | ||
expect(stderr.output).to.eq('Leaving myapp...\nLeaving myapp... done\n') | ||
apiGetUserAccount.done() | ||
apiDeletePersonalAppCollaborator.done() | ||
}) | ||
}) | ||
|
||
describe('when the user tries to leave the app', () => { | ||
before(() => { | ||
apiGetUserAccount = mockUserAccount() | ||
apiDeletePersonalAppCollaborator = mockCollaboratorsPersonalAppDeleteFailure('myapp', 'raulb@heroku.com') | ||
}) | ||
|
||
after(() => nock.cleanAll()) | ||
|
||
it('shows an error if the heroku.delete() operation returns an error', async () => { | ||
try { | ||
await runCommand(Cmd, [ | ||
'--app', | ||
'myapp', | ||
]) | ||
apiGetUserAccount.done() | ||
apiDeletePersonalAppCollaborator.done() | ||
} catch (error) { | ||
expect(error).to.be.an.instanceof(Error) | ||
} | ||
}) | ||
}) | ||
}) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 0 additions & 59 deletions
59
packages/orgs-v5/test/unit/commands/apps/leave.unit.test.js
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.