Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate(W-14169209): spaces: Upgrade spaces:transfer #2837

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions packages/cli/src/commands/spaces/transfer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import color from '@heroku-cli/color'
import {Command, flags} from '@heroku-cli/command'
import {ux} from '@oclif/core'
import heredoc from 'tsheredoc'

export default class Transfer extends Command {
static topic = 'spaces'
static description = 'transfer a space to another team'
static examples = [heredoc(`
$ heroku spaces:transfer --space=space-name --team=team-name
Transferring space-name to team-name... done
`)]

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)
} finally {
ux.action.stop()
}
}
}
61 changes: 61 additions & 0 deletions packages/cli/test/unit/commands/spaces/transfer.unit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
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 function () {
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 function () {
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: errorMessage} = error as {message: string}
expect(errorMessage).to.eq(message)
}

api.done()
})
})
36 changes: 0 additions & 36 deletions packages/spaces/commands/transfer.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/spaces/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ exports.commands = [
require('./commands/vpn/wait'),
require('./commands/vpn/destroy'),
require('./commands/vpn/update'),
require('./commands/transfer'),
require('./commands/drains/get'),
require('./commands/trusted-ips'),
require('./commands/trusted-ips/add'),
Expand Down
53 changes: 0 additions & 53 deletions packages/spaces/test/unit/commands/transfer.unit.test.js

This file was deleted.

Loading