-
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.
refactor: migrate apps:join to oclif/core (#2689)
* refactor: migrate apps:join command to oclif/core * refactor: initial test conversion * refactor: migrate stubs/post and update apps:join tests * refactor: remove v5 apps:join files and tests * refactor: update apps:join test structure * refactor: update types and test helper function * refactor: remove unnecessary params from test helper function * refactor: replace param in test helper function
- Loading branch information
Showing
7 changed files
with
74 additions
and
79 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 AppsJoin extends Command { | ||
static topic = 'apps'; | ||
static description = 'add yourself to a team app'; | ||
static aliases = ['join'] | ||
static flags = { | ||
app: flags.app({required: true}), | ||
remote: flags.remote({char: 'r'}), | ||
}; | ||
|
||
public async run(): Promise<void> { | ||
const {flags} = await this.parse(AppsJoin) | ||
const {app} = flags | ||
ux.action.start(`Joining ${color.cyan(app)}`) | ||
const {body: user} = await this.heroku.get<Heroku.Account>('/account') | ||
await this.heroku.post<Heroku.TeamAppCollaborator>(`/teams/apps/${app}/collaborators`, { | ||
body: {user: user.email}, | ||
}) | ||
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,46 @@ | ||
import {stdout, stderr} from 'stdout-stderr' | ||
import * as nock from 'nock' | ||
import {expect} from 'chai' | ||
import Cmd from '../../../../src/commands/apps/join' | ||
import runCommand from '../../../helpers/runCommand' | ||
import expectOutput from '../../../helpers/utils/expectOutput' | ||
import {userAccount} from '../../../helpers/stubs/get' | ||
import {teamAppCollaborators} from '../../../helpers/stubs/post' | ||
|
||
describe('heroku apps:join', () => { | ||
let apiGetUserAccount: nock.Scope | ||
let apiPostCollaborators: nock.Scope | ||
beforeEach(() => { | ||
apiGetUserAccount = userAccount('raulb@heroku.com') | ||
}) | ||
afterEach(() => nock.cleanAll()) | ||
it('joins the app', async () => { | ||
apiPostCollaborators = teamAppCollaborators('raulb@heroku.com') | ||
await runCommand(Cmd, [ | ||
'--app', | ||
'myapp', | ||
]) | ||
expectOutput(stdout.output, '') | ||
expectOutput(stderr.output, 'Joining myapp...\nJoining myapp... done\n') | ||
apiGetUserAccount.done() | ||
apiPostCollaborators.done() | ||
}) | ||
it('is forbidden from joining the app', async () => { | ||
const response = { | ||
code: 403, description: {id: 'forbidden', error: 'You do not have access to the team heroku-tools.'}, | ||
} | ||
apiPostCollaborators = teamAppCollaborators('raulb@heroku.com', [], response) | ||
let thrown = false | ||
await runCommand(Cmd, [ | ||
'--app', | ||
'myapp', | ||
]) | ||
.catch(function (error) { | ||
thrown = true | ||
expect(error.body.error).to.eq('You do not have access to the team heroku-tools.') | ||
}) | ||
expect(thrown).to.eq(true) | ||
apiGetUserAccount.done() | ||
apiPostCollaborators.done() | ||
}) | ||
}) |
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
49 changes: 0 additions & 49 deletions
49
packages/orgs-v5/test/unit/commands/apps/join.unit.test.js
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