Skip to content

Commit

Permalink
Merge branch 'prerelease/9.0.0-alpha' into jw/pg-v5/upgrade-pg-backup…
Browse files Browse the repository at this point in the history
…s-delete
  • Loading branch information
justinwilaby authored Mar 21, 2024
2 parents 5a7cdad + 0ae7fb0 commit 88b4da5
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 111 deletions.
34 changes: 0 additions & 34 deletions packages/certs-v5/commands/certs/remove.js

This file was deleted.

71 changes: 0 additions & 71 deletions packages/certs-v5/test/unit/commands/certs/remove.unit.test.js

This file was deleted.

38 changes: 38 additions & 0 deletions packages/cli/src/commands/certs/remove.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import color from '@heroku-cli/color'
import {Command, flags} from '@heroku-cli/command'
import {ux} from '@oclif/core'
import getEndpoint from '../../lib/certs/flags'
import confirmApp from '../../lib/apps/confirm-app'
import heredoc from 'tsheredoc'

export default class Remove extends Command {
static topic = 'certs';
static description = 'remove an SSL certificate from an app';
static flags = {
confirm: flags.string({hidden: true}),
name: flags.string({description: 'name to remove'}),
endpoint: flags.string({description: 'endpoint to remove'}),
app: flags.app({required: true}),
remote: flags.remote(),
};

public async run(): Promise<void> {
const {flags} = await this.parse(Remove)
const {app, confirm} = flags
const sniEndpoint = await getEndpoint(flags, this.heroku)
await confirmApp(
app,
confirm,
heredoc`
WARNING: Destructive Action - you cannot rollback this change
This command will remove the endpoint ${sniEndpoint.name} from ${color.magenta(app)}.
`,
)
ux.action.start(`Removing SSL certificate ${sniEndpoint.name} from ${color.magenta(app)}`)
await this.heroku.request(
`/apps/${app}/sni-endpoints/${sniEndpoint.name}`,
{method: 'DELETE'},
)
ux.action.stop()
}
}
79 changes: 79 additions & 0 deletions packages/cli/test/unit/commands/certs/remove.unit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import {stdout, stderr} from 'stdout-stderr'
import Cmd from '../../../../src/commands/certs/remove'
import runCommand from '../../../helpers/runCommand'
import heredoc from 'tsheredoc'
import * as nock from 'nock'
import {endpoint} from '../../../helpers/stubs/sni-endpoints'
import sharedSni = require('./shared_sni.unit.test')
import {SniEndpoint} from '../../../../src/lib/types/sni_endpoint'
import {expect} from 'chai'
import stripAnsi = require('strip-ansi')

describe('heroku certs:remove', function () {
afterEach(function () {
nock.cleanAll()
})

it('# deletes the endpoint', async () => {
const api = nock('https://api.heroku.com')
.get('/apps/example/sni-endpoints')
.reply(200, [endpoint])
.delete('/apps/example/sni-endpoints/' + endpoint.name)
.reply(200, [endpoint])

await runCommand(Cmd, [
'--app',
'example',
'--confirm',
'example',
])

api.done()

expect(stderr.output).to.equal(heredoc`
Removing SSL certificate tokyo-1050 from example...
Removing SSL certificate tokyo-1050 from example... done
`)
})

it('# requires confirmation if wrong endpoint on app', async () => {
const api = nock('https://api.heroku.com')
.get('/apps/example/sni-endpoints')
.reply(200, [endpoint])

try {
await runCommand(Cmd, [
'--app',
'example',
'--confirm',
'notexample',
])
} catch (error) {
const {message} = error as Error
expect(stripAnsi(message)).to.equal('Confirmation notexample did not match example. Aborted.')
}

api.done()
expect(stdout.output).to.equal('')
})
})

describe('heroku shared', function () {
const callback = function (err: Error | null, path: string, endpoint: Partial<SniEndpoint>) {
if (err)
throw err

return nock('https://api.heroku.com')
.delete(path)
.reply(200, endpoint)
}

const stderr = function (endpoint: Partial<SniEndpoint>) {
return heredoc(`
Removing SSL certificate ${endpoint.name} from example...
Removing SSL certificate ${endpoint.name} from example... done
`)
}

sharedSni.shouldHandleArgs('certs:remove', Cmd, callback, {stderr}, {confirm: 'example'})
})
20 changes: 14 additions & 6 deletions packages/cli/test/unit/commands/certs/shared_sni.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ import {
import expectOutput from '../../../helpers/utils/expectOutput'
import {SniEndpoint} from '../../../../src/lib/types/sni_endpoint'

export const shouldHandleArgs = function (commandText: string, command: GenericCmd, callback: (err: Error | null, path: string, endpoint: Partial<SniEndpoint>) => any, options: any) {
export const shouldHandleArgs = function (
commandText: string,
command: GenericCmd,
callback: (err: Error | null, path: string, endpoint: Partial<SniEndpoint>) => any,
options: any,
flags: Record<string, unknown> = {},
) {
const stdoutOutput = options.stdout || function () {
return ''
}
Expand All @@ -24,6 +30,8 @@ export const shouldHandleArgs = function (commandText: string, command: GenericC
return ''
}

const additionalFlags = Object.entries(flags).map(([k, v]) => `--${k}=${v}`)

describe(`${commandText}`, function () {
beforeEach(function () {
nock.cleanAll()
Expand All @@ -39,7 +47,7 @@ export const shouldHandleArgs = function (commandText: string, command: GenericC
'example',
'--name',
'tokyo-1050',
])
].concat(additionalFlags))
expectOutput(stderr.output, stderrOutput(endpoint))
expectOutput(stdout.output, stdoutOutput(certificateDetails, endpoint))
})
Expand All @@ -58,7 +66,7 @@ export const shouldHandleArgs = function (commandText: string, command: GenericC
'example',
'--endpoint',
'tokyo-1050.herokussl.com',
]).catch(function (error: Error) {
].concat(additionalFlags)).catch(function (error: Error) {
expect(error.message).to.equal('Must pass --name when more than one endpoint matches --endpoint')
})
})
Expand All @@ -75,7 +83,7 @@ export const shouldHandleArgs = function (commandText: string, command: GenericC
'example',
'--endpoint',
'tokyo-1050.herokussl.com',
])
].concat(additionalFlags))
expectOutput(stderr.output, stderrOutput(endpoint))
expectOutput(stdout.output, stdoutOutput(certificateDetails, endpoint))
})
Expand All @@ -91,7 +99,7 @@ export const shouldHandleArgs = function (commandText: string, command: GenericC
'example',
'--endpoint',
'tokyo-1050.herokussl.com',
]).catch(function (error: Error) {
].concat(additionalFlags)).catch(function (error: Error) {
expect(error.message).to.equal('Record not found.')
})
})
Expand All @@ -105,7 +113,7 @@ export const shouldHandleArgs = function (commandText: string, command: GenericC
'example',
'--name',
'tokyo-1050',
]).catch(function (error: Error) {
].concat(additionalFlags)).catch(function (error: Error) {
expect(error.message).to.equal('More than one endpoint matches tokyo-1050, please file a support ticket')
})
})
Expand Down

0 comments on commit 88b4da5

Please sign in to comment.