diff --git a/packages/cli/src/commands/pg/connection-pooling/attach.ts b/packages/cli/src/commands/pg/connection-pooling/attach.ts new file mode 100644 index 0000000000..dcaf63904d --- /dev/null +++ b/packages/cli/src/commands/pg/connection-pooling/attach.ts @@ -0,0 +1,51 @@ +import {color} from '@heroku-cli/color' +import {Command, flags} from '@heroku-cli/command' +import {Args, ux} from '@oclif/core' +import * as Heroku from '@heroku-cli/schema' +import tsheredoc from 'tsheredoc' +import {essentialPlan} from '../../../lib/pg/util.js' +import {utils} from '@heroku/heroku-cli-util' +import {nls} from '../../../nls.js' + +const heredoc = tsheredoc.default + +export default class Attach extends Command { + static topic = 'pg' + static description = 'add an attachment to a database using connection pooling' + static examples = [heredoc` + $ heroku pg:connection-pooling:attach postgresql-something-12345 + `] + + static flags = { + as: flags.string({description: 'name for add-on attachment'}), + app: flags.app({required: true}), + remote: flags.remote(), + } + + static args = { + database: Args.string({description: `${nls('pg:database:arg:description')} ${nls('pg:database:arg:description:default:suffix')}`}), + } + + public async run(): Promise { + const {flags, args} = await this.parse(Attach) + const {app} = flags + const dbResolver = new utils.pg.DatabaseResolver(this.heroku) + const {addon: db} = await dbResolver.getAttachment(app, args.database) + + if (essentialPlan(db)) + ux.error('You can’t perform this operation on Essential-tier databases.') + + ux.action.start(`Enabling Connection Pooling on ${color.yellow(db.name)} to ${color.magenta(app)}`) + const {body: attachment} = await this.heroku.post>(`/client/v11/databases/${encodeURIComponent(db.name)}/connection-pooling`, { + body: {name: flags.as, credential: 'default', app}, hostname: utils.pg.host(), + }) + ux.action.stop() + + ux.action.start(`Setting ${color.cyan(attachment.name)} config vars and restarting ${color.magenta(app)}`) + const {body: releases} = await this.heroku.get[]>( + `/apps/${app}/releases`, + {partial: true, headers: {Range: 'version ..; max=1, order=desc'}}, + ) + ux.action.stop(`done, v${releases[0].version}`) + } +} diff --git a/packages/cli/src/commands/pg/credentials/create.ts b/packages/cli/src/commands/pg/credentials/create.ts new file mode 100644 index 0000000000..2803aa395b --- /dev/null +++ b/packages/cli/src/commands/pg/credentials/create.ts @@ -0,0 +1,46 @@ +import {color} from '@heroku-cli/color' +import {Command, flags} from '@heroku-cli/command' +import {Args, ux} from '@oclif/core' +import tsheredoc from 'tsheredoc' +import {utils} from '@heroku/heroku-cli-util' +import {essentialPlan} from '../../../lib/pg/util.js' +import {nls} from '../../../nls.js' + +const heredoc = tsheredoc.default + +export default class Create extends Command { + static topic = 'pg' + static description = 'create credential within database\nExample:\n\n heroku pg:credentials:create postgresql-something-12345 --name new-cred-name\n' + static flags = { + name: flags.string({char: 'n', required: true, description: 'name of the new credential within the database'}), + app: flags.app({required: true}), + remote: flags.remote(), + } + + static args = { + database: Args.string({description: `${nls('pg:database:arg:description')} ${nls('pg:database:arg:description:default:suffix')}`}), + } + + public async run(): Promise { + const {flags, args} = await this.parse(Create) + const {app, name} = flags + const dbResolver = new utils.pg.DatabaseResolver(this.heroku) + const {addon: db} = await dbResolver.getAttachment(app, args.database) + if (essentialPlan(db)) { + throw new Error("You can't create a custom credential on Essential-tier databases.") + } + + const data = {name} + ux.action.start(`Creating credential ${color.cyan.bold(name)}`) + + await this.heroku.post(`/postgres/v0/databases/${db.name}/credentials`, {hostname: utils.pg.host(), body: data}) + ux.action.stop() + + const attachCmd = `heroku addons:attach ${db.name} --credential ${name} -a ${app}` + const psqlCmd = `heroku pg:psql ${db.name} -a ${app}` + ux.stdout(heredoc(` + + Please attach the credential to the apps you want to use it in by running ${color.cyan.bold(attachCmd)}. + Please define the new grants for the credential within Postgres: ${color.cyan.bold(psqlCmd)}.`)) + } +} diff --git a/packages/cli/src/oldCommands/pg/credentials/destroy.ts b/packages/cli/src/commands/pg/credentials/destroy.ts similarity index 74% rename from packages/cli/src/oldCommands/pg/credentials/destroy.ts rename to packages/cli/src/commands/pg/credentials/destroy.ts index 38d3757510..20758f4bfa 100644 --- a/packages/cli/src/oldCommands/pg/credentials/destroy.ts +++ b/packages/cli/src/commands/pg/credentials/destroy.ts @@ -1,27 +1,26 @@ -/* -import color from '@heroku-cli/color' +import {color} from '@heroku-cli/color' import {Command, flags} from '@heroku-cli/command' import {Args, ux} from '@oclif/core' import * as Heroku from '@heroku-cli/schema' -import {essentialPlan} from '../../../lib/pg/util' +import {essentialPlan} from '../../../lib/pg/util.js' import {utils} from '@heroku/heroku-cli-util' -import confirmCommand from '../../../lib/confirmCommand' -import {nls} from '../../../nls' +import ConfirmCommand from '../../../lib/confirmCommand.js' +import {nls} from '../../../nls.js' export default class Destroy extends Command { - static topic = 'pg'; - static description = 'destroy credential within database'; - static example = '$ heroku pg:credentials:destroy postgresql-transparent-56874 --name cred-name -a woodstock-production'; + static topic = 'pg' + static description = 'destroy credential within database' + static example = '$ heroku pg:credentials:destroy postgresql-transparent-56874 --name cred-name -a woodstock-production' static flags = { name: flags.string({char: 'n', required: true, description: 'unique identifier for the credential'}), - confirm: flags.string({char: 'c'}), + confirm: flags.string({char: 'c', description: 'set to app name to bypass confirm prompt'}), app: flags.app({required: true}), remote: flags.remote(), - }; + } static args = { database: Args.string({description: `${nls('pg:database:arg:description')} ${nls('pg:database:arg:description:default:suffix')}`}), - }; + } public async run(): Promise { const {flags, args} = await this.parse(Destroy) @@ -44,12 +43,11 @@ export default class Destroy extends Command { throw new Error(`Credential ${name} must be detached from the app${credAttachmentApps.length > 1 ? 's' : ''} ${credAttachmentApps.map(appName => color.app(appName || '')) .join(', ')} before destroying.`) - await confirmCommand(app, confirm) + await new ConfirmCommand().confirm(app, confirm) ux.action.start(`Destroying credential ${color.cyan.bold(name)}`) await this.heroku.delete(`/postgres/v0/databases/${db.name}/credentials/${encodeURIComponent(name)}`, {hostname: utils.pg.host()}) ux.action.stop() - ux.log(`The credential has been destroyed within ${db.name}.`) - ux.log(`Database objects owned by ${name} will be assigned to the default credential.`) + ux.stdout(`The credential has been destroyed within ${db.name}.`) + ux.stdout(`Database objects owned by ${name} will be assigned to the default credential.`) } } -*/ diff --git a/packages/cli/src/oldCommands/pg/credentials/repair-default.ts b/packages/cli/src/commands/pg/credentials/repair-default.ts similarity index 76% rename from packages/cli/src/oldCommands/pg/credentials/repair-default.ts rename to packages/cli/src/commands/pg/credentials/repair-default.ts index 842b46b303..4c4e0f17a8 100644 --- a/packages/cli/src/oldCommands/pg/credentials/repair-default.ts +++ b/packages/cli/src/commands/pg/credentials/repair-default.ts @@ -1,25 +1,26 @@ -/* import {Command, flags} from '@heroku-cli/command' import {Args, ux} from '@oclif/core' import {utils} from '@heroku/heroku-cli-util' -import {essentialPlan} from '../../../lib/pg/util' -import confirmCommand from '../../../lib/confirmCommand' -import heredoc from 'tsheredoc' -import {nls} from '../../../nls' +import {essentialPlan} from '../../../lib/pg/util.js' +import ConfirmCommand from '../../../lib/confirmCommand.js' +import tsheredoc from 'tsheredoc' +import {nls} from '../../../nls.js' + +const heredoc = tsheredoc.default export default class RepairDefault extends Command { - static topic = 'pg'; - static description = 'repair the permissions of the default credential within database'; - static example = '$ heroku pg:credentials:repair-default postgresql-something-12345'; + static topic = 'pg' + static description = 'repair the permissions of the default credential within database' + static example = '$ heroku pg:credentials:repair-default postgresql-something-12345' static flags = { - confirm: flags.string({char: 'c'}), + confirm: flags.string({char: 'c', description: 'set to app name to bypass confirm prompt'}), app: flags.app({required: true}), remote: flags.remote(), - }; + } static args = { database: Args.string({description: `${nls('pg:database:arg:description')} ${nls('pg:database:arg:description:default:suffix')}`}), - }; + } public async run(): Promise { const {flags, args} = await this.parse(RepairDefault) @@ -29,7 +30,7 @@ export default class RepairDefault extends Command { const {addon: db} = await dbResolver.getAttachment(app, database) if (essentialPlan(db)) throw new Error("You can't perform this operation on Essential-tier databases.") - await confirmCommand(app, confirm, heredoc(` + await new ConfirmCommand().confirm(app, confirm, heredoc(` Destructive Action Ownership of all database objects owned by additional credentials will be transferred to the default credential. This command will also grant the default credential admin option for all additional credentials. @@ -39,4 +40,3 @@ export default class RepairDefault extends Command { ux.action.stop() } } -*/ diff --git a/packages/cli/src/oldCommands/pg/credentials/rotate.ts b/packages/cli/src/commands/pg/credentials/rotate.ts similarity index 88% rename from packages/cli/src/oldCommands/pg/credentials/rotate.ts rename to packages/cli/src/commands/pg/credentials/rotate.ts index 039dee2396..f0136d72d1 100644 --- a/packages/cli/src/oldCommands/pg/credentials/rotate.ts +++ b/packages/cli/src/commands/pg/credentials/rotate.ts @@ -1,13 +1,11 @@ -/* -import color from '@heroku-cli/color' +import {color} from '@heroku-cli/color' import {Command, flags} from '@heroku-cli/command' -import {APIClient} from '@heroku-cli/command/lib/api-client' +import {APIClient} from '@heroku-cli/command' import type {AddOnAttachment} from '@heroku-cli/schema' import {Args, ux} from '@oclif/core' -import confirmCommand from '../../../lib/confirmCommand' +import ConfirmCommand from '../../../lib/confirmCommand.js' import {utils} from '@heroku/heroku-cli-util' -import {legacyEssentialPlan} from '../../../lib/pg/util' -import {nls} from '../../../nls' +import {nls} from '../../../nls.js' export default class Rotate extends Command { static topic = 'pg' @@ -18,7 +16,7 @@ export default class Rotate extends Command { description: 'which credential to rotate (default credentials if not specified and --all is not used)', }), all: flags.boolean({description: 'rotate all credentials', exclusive: ['name']}), - confirm: flags.string({char: 'c'}), + confirm: flags.string({char: 'c', description: 'set to app name to bypass confirm prompt'}), force: flags.boolean({description: 'forces rotating the targeted credentials'}), app: flags.app({required: true}), remote: flags.remote(), @@ -39,7 +37,7 @@ export default class Rotate extends Command { throw new Error('cannot pass both --all and --name') } - if (legacyEssentialPlan(db) && cred !== 'default') { + if (utils.pg.isLegacyEssentialDatabase(db) && cred !== 'default') { throw new Error('Legacy Essential-tier databases do not support named credentials.') } @@ -74,7 +72,7 @@ export default class Rotate extends Command { warnings.push(`This command will affect the app${(attachments.length > 1) ? 's' : ''} ${uniqueAttachments}.`) } - await confirmCommand(app, confirm, `Destructive Action\n${warnings.join('\n')}`) + await new ConfirmCommand().confirm(app, confirm, `Destructive Action\n${warnings.join('\n')}`) const options: APIClient.Options = { hostname: utils.pg.host(), body: {forced: force ?? undefined}, @@ -93,4 +91,3 @@ export default class Rotate extends Command { ux.action.stop() } } -*/ diff --git a/packages/cli/src/oldCommands/pg/credentials/url.ts b/packages/cli/src/commands/pg/credentials/url.ts similarity index 88% rename from packages/cli/src/oldCommands/pg/credentials/url.ts rename to packages/cli/src/commands/pg/credentials/url.ts index 75b6c26dc6..96889b7a24 100644 --- a/packages/cli/src/oldCommands/pg/credentials/url.ts +++ b/packages/cli/src/commands/pg/credentials/url.ts @@ -1,13 +1,13 @@ -/* -import color from '@heroku-cli/color' +import {color} from '@heroku-cli/color' import {Command, flags} from '@heroku-cli/command' import {Args, ux} from '@oclif/core' -import {legacyEssentialPlan} from '../../../lib/pg/util' import {utils} from '@heroku/heroku-cli-util' import {URL} from 'url' -import type {CredentialInfo} from '../../../lib/pg/types' -import heredoc from 'tsheredoc' -import {nls} from '../../../nls' +import type {CredentialInfo} from '../../../lib/pg/types.js' +import tsheredoc from 'tsheredoc' +import {nls} from '../../../nls.js' + +const heredoc = tsheredoc.default export default class Url extends Command { static topic = 'pg' @@ -32,7 +32,7 @@ export default class Url extends Command { const {database} = args const dbResolver = new utils.pg.DatabaseResolver(this.heroku) const {addon: db} = await dbResolver.getAttachment(app, database) - if (legacyEssentialPlan(db) && name !== 'default') { + if (utils.pg.isLegacyEssentialDatabase(db) && name !== 'default') { ux.error('Legacy Essential-tier databases do not support named credentials.') } @@ -62,7 +62,7 @@ export default class Url extends Command { connUrl.password = creds.password } - ux.log(heredoc(` + ux.stdout(heredoc(` Connection information for ${color.yellow(name)} credential. Connection info string: "dbname=${creds.database} host=${creds.host} port=${creds.port} user=${creds.user} password=${creds.password} sslmode=require" @@ -71,4 +71,3 @@ export default class Url extends Command { `)) } } -*/ diff --git a/packages/cli/src/lib/pg/util.ts b/packages/cli/src/lib/pg/util.ts index 21949a57a6..70f7977810 100644 --- a/packages/cli/src/lib/pg/util.ts +++ b/packages/cli/src/lib/pg/util.ts @@ -1,10 +1,13 @@ import {color} from '@heroku-cli/color' import type {AddOnAttachment} from '@heroku-cli/schema' -import {hux} from '@heroku/heroku-cli-util' +import {hux, utils, pg} from '@heroku/heroku-cli-util' import {renderAttachment} from '../../commands/addons/index.js' import {multiSortCompareFn} from '../utils/multisort.js' import type {CredentialsInfo} from './types.js' -import {utils} from '@heroku/heroku-cli-util' + +export function essentialPlan(addon: pg.ExtendedAddonAttachment['addon'] | pg.ExtendedAddon) { + return utils.pg.isEssentialDatabase(addon) || utils.pg.isLegacyEssentialDatabase(addon) +} export function formatResponseWithCommands(response: string): string { return response.replace(/`(.*?)`/g, (_, word) => color.cmd(word)) diff --git a/packages/cli/src/oldCommands/pg/connection-pooling/attach.ts b/packages/cli/src/oldCommands/pg/connection-pooling/attach.ts deleted file mode 100644 index 5141140499..0000000000 --- a/packages/cli/src/oldCommands/pg/connection-pooling/attach.ts +++ /dev/null @@ -1,51 +0,0 @@ -/* -import color from '@heroku-cli/color' -import {Command, flags} from '@heroku-cli/command' -import {Args, ux} from '@oclif/core' -import * as Heroku from '@heroku-cli/schema' -import heredoc from 'tsheredoc' -import {essentialPlan} from '../../../lib/pg/util' -import {utils} from '@heroku/heroku-cli-util' -import {nls} from '../../../nls' - -export default class Attach extends Command { - static topic = 'pg' - static description = 'add an attachment to a database using connection pooling' - static examples = [heredoc` - $ heroku pg:connection-pooling:attach postgresql-something-12345 - `] - - static flags = { - as: flags.string({description: 'name for add-on attachment'}), - app: flags.app({required: true}), - remote: flags.remote(), - } - - static args = { - database: Args.string({description: `${nls('pg:database:arg:description')} ${nls('pg:database:arg:description:default:suffix')}`}), - } - - public async run(): Promise { - const {flags, args} = await this.parse(Attach) - const {app} = flags - const dbResolver = new utils.pg.DatabaseResolver(this.heroku) - const {addon: db} = await dbResolver.getAttachment(app, args.database) - - if (essentialPlan(db)) - ux.error('You can’t perform this operation on Essential-tier databases.') - - ux.action.start(`Enabling Connection Pooling on ${color.yellow(db.name)} to ${color.magenta(app)}`) - const {body: attachment} = await this.heroku.post>(`/client/v11/databases/${encodeURIComponent(db.name)}/connection-pooling`, { - body: {name: flags.as, credential: 'default', app: app}, hostname: utils.pg.host(), - }) - ux.action.stop() - - ux.action.start(`Setting ${color.cyan(attachment.name)} config vars and restarting ${color.magenta(app)}`) - const {body: releases} = await this.heroku.get[]>( - `/apps/${app}/releases`, - {partial: true, headers: {Range: 'version ..; max=1, order=desc'}}, - ) - ux.action.stop(`done, v${releases[0].version}`) - } -} -*/ diff --git a/packages/cli/src/oldCommands/pg/credentials/create.ts b/packages/cli/src/oldCommands/pg/credentials/create.ts deleted file mode 100644 index 4427b02f1b..0000000000 --- a/packages/cli/src/oldCommands/pg/credentials/create.ts +++ /dev/null @@ -1,46 +0,0 @@ -/* -import color from '@heroku-cli/color' -import {Command, flags} from '@heroku-cli/command' -import {Args, ux} from '@oclif/core' -import heredoc from 'tsheredoc' -import {utils} from '@heroku/heroku-cli-util' -import {essentialPlan} from '../../../lib/pg/util' -import {nls} from '../../../nls' - -export default class Create extends Command { - static topic = 'pg' - static description = 'create credential within database\nExample:\n\n heroku pg:credentials:create postgresql-something-12345 --name new-cred-name\n' - static flags = { - name: flags.string({char: 'n', required: true, description: 'name of the new credential within the database'}), - app: flags.app({required: true}), - remote: flags.remote(), - } - - static args = { - database: Args.string({description: `${nls('pg:database:arg:description')} ${nls('pg:database:arg:description:default:suffix')}`}), - } - - public async run(): Promise { - const {flags, args} = await this.parse(Create) - const {app, name} = flags - const dbResolver = new utils.pg.DatabaseResolver(this.heroku) - const {addon: db} = await dbResolver.getAttachment(app, args.database) - if (essentialPlan(db)) { - throw new Error("You can't create a custom credential on Essential-tier databases.") - } - - const data = {name} - ux.action.start(`Creating credential ${color.cyan.bold(name)}`) - - await this.heroku.post(`/postgres/v0/databases/${db.name}/credentials`, {hostname: utils.pg.host(), body: data}) - ux.action.stop() - - const attachCmd = `heroku addons:attach ${db.name} --credential ${name} -a ${app}` - const psqlCmd = `heroku pg:psql ${db.name} -a ${app}` - ux.log(heredoc(` - - Please attach the credential to the apps you want to use it in by running ${color.cyan.bold(attachCmd)}. - Please define the new grants for the credential within Postgres: ${color.cyan.bold(psqlCmd)}.`)) - } -} -*/ diff --git a/packages/cli/test/unit/commands/pg/connection-pooling/attach.unit.test.ts b/packages/cli/test/unit/commands/pg/connection-pooling/attach.unit.test.ts index 928bbe09bc..f20b72cfca 100644 --- a/packages/cli/test/unit/commands/pg/connection-pooling/attach.unit.test.ts +++ b/packages/cli/test/unit/commands/pg/connection-pooling/attach.unit.test.ts @@ -1,10 +1,9 @@ -/* import {stdout, stderr} from 'stdout-stderr' import runCommand from '../../../../helpers/runCommand.js' import {expect} from 'chai' import nock from 'nock' -import Cmd from '../../../../../src/commands/pg/connection-pooling/attach' -import {resolvedAttachments} from '../../../../fixtures/addons/fixtures' +import Cmd from '../../../../../src/commands/pg/connection-pooling/attach.js' +import {resolvedAttachments} from '../../../../fixtures/addons/fixtures.js' describe('pg:connection-pooling:attach', function () { const addon = { @@ -76,5 +75,3 @@ describe('pg:connection-pooling:attach', function () { }) }) }) - -*/ diff --git a/packages/cli/test/unit/commands/pg/credentials/create.unit.test.ts b/packages/cli/test/unit/commands/pg/credentials/create.unit.test.ts index aa86254fec..01206fa2de 100644 --- a/packages/cli/test/unit/commands/pg/credentials/create.unit.test.ts +++ b/packages/cli/test/unit/commands/pg/credentials/create.unit.test.ts @@ -3,9 +3,8 @@ import runCommand from '../../../../helpers/runCommand.js' import {expect} from 'chai' import nock from 'nock' -// import Cmd from '../../../../../src/commands/pg/credentials/create' +import Cmd from '../../../../../src/commands/pg/credentials/create.js' -/* describe('pg:credentials:create', function () { let api: nock.Scope let pg: nock.Scope @@ -40,7 +39,7 @@ describe('pg:credentials:create', function () { 'credname', ]) expect(stdout.output).to.equal('\nPlease attach the credential to the apps you want to use it in by running heroku addons:attach postgres-1 --credential credname -a myapp.\nPlease define the new grants for the credential within Postgres: heroku pg:psql postgres-1 -a myapp.\n') - return expect(stderr.output).to.equal('Creating credential credname...\nCreating credential credname... done\n') + return expect(stderr.output).to.equal('Creating credential credname... done\n') }) it('throws an error when the db is numbered essential plan', async function () { @@ -82,5 +81,3 @@ describe('pg:credentials:create', function () { ]).catch(error => expect(error.message).to.contain(err)) }) }) - -*/ diff --git a/packages/cli/test/unit/commands/pg/credentials/destroy.unit.test.ts b/packages/cli/test/unit/commands/pg/credentials/destroy.unit.test.ts index 8e84e69925..ea431b41d9 100644 --- a/packages/cli/test/unit/commands/pg/credentials/destroy.unit.test.ts +++ b/packages/cli/test/unit/commands/pg/credentials/destroy.unit.test.ts @@ -1,13 +1,14 @@ import {stderr, stdout} from 'stdout-stderr' -// import Cmd from '../../../../../src/commands/pg/credentials/destroy' +import Cmd from '../../../../../src/commands/pg/credentials/destroy.js' import runCommand from '../../../../helpers/runCommand.js' import nock from 'nock' import expectOutput from '../../../../helpers/utils/expectOutput.js' import {expect} from 'chai' -import heredoc from 'tsheredoc' +import tsheredoc from 'tsheredoc' import stripAnsi from 'strip-ansi' -/* +const heredoc = tsheredoc.default + describe('pg:credentials:destroy', function () { const addon = { name: 'postgres-1', plan: {name: 'heroku-postgresql:standard-0'}, @@ -42,7 +43,6 @@ describe('pg:credentials:destroy', function () { 'myapp', ]) expectOutput(stderr.output, heredoc(` - Destroying credential credname... Destroying credential credname... done `)) expectOutput(stdout.output, heredoc(` @@ -53,7 +53,7 @@ describe('pg:credentials:destroy', function () { it('throws an error when the db is starter plan', async function () { const hobbyAddon = { - name: 'postgres-1', plan: {name: 'heroku-postgresql:hobby-dev'}, + name: 'postgres-1', plan: {name: 'heroku-postgresql:mini'}, } nock('https://api.heroku.com') .post('/actions/addon-attachments/resolve') @@ -142,5 +142,3 @@ describe('pg:credentials:destroy', function () { }) }) }) - -*/ diff --git a/packages/cli/test/unit/commands/pg/credentials/repair-default.unit.test.ts b/packages/cli/test/unit/commands/pg/credentials/repair-default.unit.test.ts index c5d008ed62..7265c6c85f 100644 --- a/packages/cli/test/unit/commands/pg/credentials/repair-default.unit.test.ts +++ b/packages/cli/test/unit/commands/pg/credentials/repair-default.unit.test.ts @@ -1,12 +1,13 @@ import {stderr, stdout} from 'stdout-stderr' -// import Cmd from '../../../../../src/commands/pg/credentials/repair-default' +import Cmd from '../../../../../src/commands/pg/credentials/repair-default.js' import runCommand from '../../../../helpers/runCommand.js' import nock from 'nock' -import heredoc from 'tsheredoc' +import tsheredoc from 'tsheredoc' import {expect} from 'chai' import expectOutput from '../../../../helpers/utils/expectOutput.js' -/* +const heredoc = tsheredoc.default + describe('pg:credentials:repair-default', function () { const addon = { name: 'postgres-1', plan: {name: 'heroku-postgresql:standard-0'}, @@ -31,14 +32,13 @@ describe('pg:credentials:repair-default', function () { ]) expectOutput(stdout.output, '') expectOutput(stderr.output, heredoc(` - Resetting permissions and object ownership for default role to factory settings... Resetting permissions and object ownership for default role to factory settings... done `)) }) it('throws an error when the db is essential plan', async function () { const hobbyAddon = { - name: 'postgres-1', plan: {name: 'heroku-postgresql:hobby-dev'}, + name: 'postgres-1', plan: {name: 'heroku-postgresql:mini'}, } nock('https://api.heroku.com') @@ -53,5 +53,3 @@ describe('pg:credentials:repair-default', function () { ]).catch((error: Error) => expect(error.message).to.equal(err)) }) }) - -*/ diff --git a/packages/cli/test/unit/commands/pg/credentials/rotate.unit.test.ts b/packages/cli/test/unit/commands/pg/credentials/rotate.unit.test.ts index bbfa52cb59..e89b42a2a3 100644 --- a/packages/cli/test/unit/commands/pg/credentials/rotate.unit.test.ts +++ b/packages/cli/test/unit/commands/pg/credentials/rotate.unit.test.ts @@ -2,11 +2,14 @@ import {ux} from '@oclif/core' import {expect} from 'chai' import nock from 'nock' import {stdout, stderr} from 'stdout-stderr' -import heredoc from 'tsheredoc' -// import Cmd from '../../../../../src/commands/pg/credentials/rotate' +import tsheredoc from 'tsheredoc' +import Cmd from '../../../../../src/commands/pg/credentials/rotate.js' import runCommand from '../../../../helpers/runCommand.js' import * as sinon from 'sinon' import stripAnsi from 'strip-ansi' +import {hux} from '@heroku/heroku-cli-util' + +const heredoc = tsheredoc.default const addon = { id: 1, name: 'postgres-1', plan: {name: 'heroku-postgresql:standard-0'}, @@ -22,7 +25,6 @@ const attachments = [ }, ] -/* describe('pg:credentials:rotate', function () { let api: nock.Scope let pg: nock.Scope @@ -31,7 +33,7 @@ describe('pg:credentials:rotate', function () { before(function () { uxWarnStub = sinon.stub(ux, 'warn') - uxPromptStub = sinon.stub(ux, 'prompt').resolves('myapp') + uxPromptStub = sinon.stub(hux, 'prompt').resolves('myapp') }) beforeEach(async function () { @@ -75,7 +77,6 @@ describe('pg:credentials:rotate', function () { ]) expect(stdout.output).to.equal('') expect(stderr.output).to.equal(heredoc(` - Rotating my_role on postgres-1... Rotating my_role on postgres-1... done `)) }) @@ -92,7 +93,6 @@ describe('pg:credentials:rotate', function () { ]) expect(stdout.output).to.equal('') expect(stderr.output).to.equal(heredoc(` - Rotating all credentials on postgres-1... Rotating all credentials on postgres-1... done `)) }) @@ -111,7 +111,6 @@ describe('pg:credentials:rotate', function () { ]) expect(stdout.output).to.equal('') expect(stderr.output).to.equal(heredoc(` - Rotating my_role on postgres-1... Rotating my_role on postgres-1... done `)) }) @@ -252,14 +251,13 @@ describe('pg:credentials:rotate', function () { ]) expect(stdout.output).to.equal('') expect(stderr.output).to.equal(heredoc(` - Rotating lucy on postgres-1... Rotating lucy on postgres-1... done `)) }) it('rotates credentials with no --name with starter plan', async function () { const hobbyAddon = { - name: 'postgres-1', plan: {name: 'heroku-postgresql:hobby-dev'}, + name: 'postgres-1', plan: {name: 'heroku-postgresql:mini'}, } api.post('/actions/addon-attachments/resolve', { @@ -278,14 +276,13 @@ describe('pg:credentials:rotate', function () { ]) expect(stdout.output).to.equal('') expect(stderr.output).to.equal(heredoc(` - Rotating default on postgres-1... Rotating default on postgres-1... done `)) }) it('rotates credentials with --all with starter plan', async function () { const hobbyAddon = { - name: 'postgres-1', plan: {name: 'heroku-postgresql:hobby-dev'}, + name: 'postgres-1', plan: {name: 'heroku-postgresql:mini'}, } api.post('/actions/addon-attachments/resolve', { @@ -305,10 +302,7 @@ describe('pg:credentials:rotate', function () { ]) expect(stdout.output).to.equal('') expect(stderr.output).to.equal(heredoc(` - Rotating all credentials on postgres-1... Rotating all credentials on postgres-1... done `)) }) }) - -*/ diff --git a/packages/cli/test/unit/commands/pg/credentials/url.unit.test.ts b/packages/cli/test/unit/commands/pg/credentials/url.unit.test.ts index 6b8582b3b1..09f29a05f1 100644 --- a/packages/cli/test/unit/commands/pg/credentials/url.unit.test.ts +++ b/packages/cli/test/unit/commands/pg/credentials/url.unit.test.ts @@ -1,13 +1,14 @@ import {stdout} from 'stdout-stderr' -// import Cmd from '../../../../../src/commands/pg/credentials/url' +import Cmd from '../../../../../src/commands/pg/credentials/url.js' import runCommand from '../../../../helpers/runCommand.js' import nock from 'nock' import expectOutput from '../../../../helpers/utils/expectOutput.js' import {expect} from 'chai' -import heredoc from 'tsheredoc' +import tsheredoc from 'tsheredoc' import * as fixtures from '../../../../fixtures/addons/fixtures.js' -/* +const heredoc = tsheredoc.default + describe('pg:credentials:url', function () { const addon = fixtures.addons['dwh-db'] const attachments = [fixtures.attachments['acme-inc-dwh::DATABASE']] @@ -129,5 +130,3 @@ describe('pg:credentials:url', function () { `)) }) }) - -*/