Skip to content

Commit 6fcb3a4

Browse files
authored
fix: show correct error message for Essential-tier (W-21653472) (#3614)
Fix error message for Essential-tier databases
1 parent 85c2224 commit 6fcb3a4

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

src/commands/data/pg/credentials/destroy.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
import {color, hux, utils} from '@heroku/heroku-cli-util'
21
import {flags as Flags} from '@heroku-cli/command'
32
import {AddOnAttachment} from '@heroku-cli/schema'
3+
import * as color from '@heroku/heroku-cli-util/color'
4+
import {confirmCommand} from '@heroku/heroku-cli-util/hux'
5+
import {
6+
AddonResolver, getAddonService, isAdvancedDatabase, isEssentialDatabase, isLegacyEssentialDatabase,
7+
} from '@heroku/heroku-cli-util/utils'
48
import {Args, ux} from '@oclif/core'
59

610
import type {CredentialInfo, CredentialsInfo} from '../../../../lib/data/types.js'
@@ -33,10 +37,11 @@ export default class DataPgCredentialsDestroy extends BaseCommand {
3337
const {app, confirm, name} = flags
3438
const {database} = args
3539

36-
const addonResolver = new utils.AddonResolver(this.heroku)
37-
const addon = await addonResolver.resolve(database, app, utils.pg.addonService())
38-
const isEssentialTier = utils.pg.isEssentialDatabase(addon) || utils.pg.isLegacyEssentialDatabase(addon)
39-
const isAdvancedTier = utils.pg.isAdvancedDatabase(addon)
40+
const addonResolver = new AddonResolver(this.heroku)
41+
const addon = await addonResolver.resolve(database, app, getAddonService())
42+
const isEssentialTier = isEssentialDatabase(addon)
43+
const isLegacyEssentialTier = isLegacyEssentialDatabase(addon)
44+
const isAdvancedTier = isAdvancedDatabase(addon)
4045
let credAttachments: Required<AddOnAttachment>[] = []
4146

4247
if (isAdvancedTier) {
@@ -50,7 +55,9 @@ export default class DataPgCredentialsDestroy extends BaseCommand {
5055
}
5156

5257
credAttachments = attachments.filter(a => a.namespace === `role:${name}`)
53-
} else if (isEssentialTier || name === 'default') {
58+
} else if (isEssentialTier) {
59+
ux.error('You can\'t destroy custom credentials on Essential-tier databases.')
60+
} else if (isLegacyEssentialTier || name === 'default') {
5461
ux.error('You can\'t destroy the default credential.')
5562
} else {
5663
const {body: attachments} = await this.heroku.get<Required<AddOnAttachment>[]>(
@@ -68,7 +75,7 @@ export default class DataPgCredentialsDestroy extends BaseCommand {
6875
)
6976
}
7077

71-
await hux.confirmCommand({comparison: app, confirmation: confirm})
78+
await confirmCommand({comparison: app, confirmation: confirm})
7279

7380
try {
7481
ux.action.start(`Destroying credential ${color.name(name)}`)

test/unit/commands/data/pg/credentials/destroy.unit.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ describe('data:pg:credentials:destroy', function () {
6060

6161
herokuApi.done()
6262
expect(ansis.strip(err.message)).to.equal(
63-
'You can\'t destroy the default credential.',
63+
'You can\'t destroy custom credentials on Essential-tier databases.',
6464
)
6565
}
6666
})

0 commit comments

Comments
 (0)