-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migeate(W-14169209): spaces: Upgrade spaces:transfer
- Loading branch information
1 parent
f4f1c41
commit 7bdaad7
Showing
5 changed files
with
80 additions
and
90 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,29 @@ | ||
import color from '@heroku-cli/color' | ||
import {Command, flags} from '@heroku-cli/command' | ||
import {ux} from '@oclif/core' | ||
|
||
export default class Transfer extends Command { | ||
static topic = 'spaces'; | ||
static description = 'transfer a space to another team'; | ||
static help = 'Example:\n\n $ heroku spaces:transfer --space=space-name --team=team-name\n Transferring space-name to team-name... done\n'; | ||
static flags = { | ||
space: flags.string({required: true, description: 'name of space'}), | ||
team: flags.string({required: true, description: 'desired owner of space'}), | ||
}; | ||
|
||
public async run(): Promise<void> { | ||
const {flags} = await this.parse(Transfer) | ||
const space = flags.space | ||
const team = flags.team | ||
|
||
try { | ||
ux.action.start(`Transferring space ${color.yellow(space)} to team ${color.green(team)}`) | ||
await this.heroku.post(`/spaces/${space}/transfer`, {body: {new_owner: team}}) | ||
} catch (error) { | ||
const {body: {message}} = error as {body: {message: string}} | ||
ux.error(message) | ||
} | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import {expect} from '@oclif/test' | ||
import * as nock from 'nock' | ||
import {stderr} from 'stdout-stderr' | ||
import Cmd from '../../../src/commands/spaces/transfer' | ||
import runCommand from '../../helpers/runCommand' | ||
|
||
describe('spaces:transfer', function () { | ||
it('yields success when the API succeeds', async () => { | ||
const space = 'dimension-c137' | ||
const team = 'jerry' | ||
const api = nock('https://api.heroku.com:443') | ||
.post(`/spaces/${space}/transfer`, { | ||
new_owner: team, | ||
}) | ||
.reply(201, { | ||
created_at: '2019-01-09T22:31:33Z', id: '5dd30c44-078f-4424-8585-cb98adf86723', name: space, organization: {id: '12cd6520-b000-4882-a655-8ae84a0132cb', name: team}, team: {id: '12cd6520-b000-4882-a655-8ae84a0132cb', name: team}, region: {id: '3544427c-5b3b-4e1e-b01a-b66362573b26', name: 'virginia'}, shield: false, state: 'allocated', cidr: '10.0.0.0/16', data_cidr: '10.1.0.0/16', updated_at: '2019-07-16T10:19:10Z', | ||
}) | ||
await runCommand(Cmd, [ | ||
'--team', | ||
team, | ||
'--space', | ||
space, | ||
]) | ||
expect(stderr.output).to.contain('done') | ||
api.done() | ||
}) | ||
|
||
it('yields the API error messages when the API fails', async () => { | ||
const space = 'dimension-c137' | ||
const team = 'jerry' | ||
const message = 'rikki tikki tavi!' | ||
const id = 'oops' | ||
const api = nock('https://api.heroku.com:443') | ||
.post(`/spaces/${space}/transfer`, {new_owner: team}) | ||
.reply(500, {id, message}) | ||
|
||
try { | ||
await runCommand(Cmd, [ | ||
'--team', | ||
team, | ||
'--space', | ||
space, | ||
]) | ||
} catch (error) { | ||
const {message} = error as {message: string} | ||
expect(message).to.eq(message) | ||
} | ||
|
||
api.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
This file was deleted.
Oops, something went wrong.