Skip to content

Commit

Permalink
migeate(W-14169209): spaces: Upgrade spaces:transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
justinwilaby committed Apr 25, 2024
1 parent f4f1c41 commit 7bdaad7
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 90 deletions.
29 changes: 29 additions & 0 deletions packages/cli/src/commands/spaces/transfer.ts
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()
}
}
51 changes: 51 additions & 0 deletions packages/cli/test/unit/commands/transfer.unit.test.ts
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()
})
})
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 @@ -19,7 +19,6 @@ exports.commands = [
require('./commands/vpn/destroy'),
require('./commands/vpn/update'),
require('./commands/ps'),
require('./commands/transfer'),
require('./commands/drains/get'),
require('./commands/drains/set'),
require('./commands/trusted-ips'),
Expand Down
53 changes: 0 additions & 53 deletions packages/spaces/test/unit/commands/transfer.unit.test.js

This file was deleted.

0 comments on commit 7bdaad7

Please sign in to comment.