Skip to content

Commit

Permalink
Revert "refactor: add per hour and max price per month to pricing dis…
Browse files Browse the repository at this point in the history
…plays (#2439)" (#2447)

This reverts commit 3777f8d.
  • Loading branch information
k80bowman committed Aug 17, 2023
1 parent 3777f8d commit 0a4a28e
Show file tree
Hide file tree
Showing 17 changed files with 84 additions and 216 deletions.
21 changes: 2 additions & 19 deletions packages/addons-v5/commands/addons/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,7 @@ async function run(ctx, api) {
label: 'Price',
format: function (price) {
if (typeof price === 'undefined') return style('dim', '?')
return formatPrice({price, hourly: true})
},
},
{
key: 'plan.price',
label: 'Max Price',
format: function (price) {
if (typeof price === 'undefined') return style('dim', '?')
return formatPrice({price, hourly: false})
return formatPrice(price)
},
},
{
Expand Down Expand Up @@ -231,16 +223,7 @@ async function run(ctx, api) {
label: 'Price',
format: function (addon) {
if (addon.app.name === app) {
return formatPrice({price: addon.plan.price, hourly: true})
}

return style('dim', printf('(billed to %s app)', style('app', addon.app.name)))
},
}, {
label: 'Max Price',
format: function (addon) {
if (addon.app.name === app) {
return formatPrice({price: addon.plan.price, hourly: false})
return formatPrice(addon.plan.price)
}

return style('dim', printf('(billed to %s app)', style('app', addon.app.name)))
Expand Down
3 changes: 1 addition & 2 deletions packages/addons-v5/commands/addons/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ let run = cli.command({preauth: true}, function (ctx, api) {
cli.styledHeader(style('addon', addon.name))
cli.styledHash({
Plan: addon.plan.name,
Price: formatPrice({price: addon.plan.price, hourly: true}),
'Max Price': formatPrice({price: addon.plan.price, hourly: false}),
Price: formatPrice(addon.plan.price),
Attachments: addon.attachments.map(function (att) {
return [
style('app', att.app.name),
Expand Down
7 changes: 1 addition & 6 deletions packages/addons-v5/commands/addons/plans.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@ async function run(context, heroku) {
{key: 'default', label: '', format: d => d ? 'default' : ''},
{key: 'name', label: 'slug'},
{key: 'human_name', label: 'name'},
{key: 'price', format: function (price) {
return util.formatPrice({price, hourly: true})
}},
{key: 'price', label: 'max price', format: function (price) {
return util.formatPrice({price, hourly: false})
}},
{key: 'price', format: util.formatPrice},
],
})
}
Expand Down
2 changes: 1 addition & 1 deletion packages/addons-v5/commands/addons/upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ async function run(c, h) {
'X-Heroku-Legacy-Provider-Messages': 'true',
},
}).catch(error => handlePlanChangeAPIError(error))
cli.action.done(`done${addon.plan.price ? `, ${util.formatPriceText(addon.plan.price)}` : ''}`)
cli.action.done(`done, ${cli.color.green(util.formatPrice(addon.plan.price))}`)
if (addon.provision_message) cli.log(addon.provision_message)
})())
}
Expand Down
2 changes: 1 addition & 1 deletion packages/addons-v5/lib/create_addon.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.exports = async function (heroku, app, plan, confirm, wait, options) {
'x-heroku-legacy-provider-messages': 'true',
},
}).then(function (addon) {
cli.action.done(cli.color.green(util.formatPriceText(addon.plan.price)))
cli.action.done(cli.color.green(util.formatPrice(addon.plan.price)))
return addon
}),
)
Expand Down
16 changes: 1 addition & 15 deletions packages/addons-v5/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,13 @@ module.exports = {
})
},

// This function assumes that price.cents will reflect price per month.
// If the API returns any unit other than month
// this function will need to be updated.
formatPrice: function ({price, hourly}) {
formatPrice: function (price) {
const printf = require('printf')

if (!price) return
if (price.contract) return 'contract'
if (price.cents === 0) return 'free'

// we are using a standardized 720 hours/month
if (hourly) return `~$${((price.cents / 100) / 720).toFixed(3)}/hour`

let fmt = price.cents % 100 === 0 ? '$%.0f/%s' : '$%.02f/%s'
return printf(fmt, price.cents / 100, price.unit)
},
Expand All @@ -56,14 +50,6 @@ module.exports = {
})
},

formatPriceText: function (price) {
const priceHourly = this.formatPrice({price, hourly: true})
const priceMonthly = this.formatPrice({price, hourly: false})
if (!priceHourly) return ''
if (priceHourly === 'free' || priceHourly === 'contract') return `${cli.color.green(priceHourly)}`
return `${cli.color.green(priceHourly)} (max ${priceMonthly})`
},

formatState: function (state) {
switch (state) {
case 'provisioned':
Expand Down
22 changes: 11 additions & 11 deletions packages/addons-v5/test/unit/commands/addons.--all.unit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ describe('addons --all', function () {
it('prints add-ons in a table', function () {
return cmd.run({flags: {}}).then(function () {
util.expectOutput(cli.stdout,
`Owning App Add-on Plan Price Max Price State
──────────── ───────── ────────────────────── ──────────── ───────── ────────
acme-inc-api api-redis heroku-redis:premium-2 ~$0.083/hour $60/month created
acme-inc-www www-db heroku-postgresql:mini ~$0.007/hour $5/month created
acme-inc-www www-redis heroku-redis:premium-2 ~$0.083/hour $60/month creating`)
`Owning App Add-on Plan Price State
──────────── ───────── ────────────────────── ───────── ────────
acme-inc-api api-redis heroku-redis:premium-2 $60/month created
acme-inc-www www-db heroku-postgresql:mini $5/month created
acme-inc-www www-redis heroku-redis:premium-2 $60/month creating`)
})
})

Expand Down Expand Up @@ -67,9 +67,9 @@ acme-inc-www www-redis heroku-redis:premium-2 ~$0.083/hour $60/month creati
it('prints add-ons in a table with the grandfathered price', function () {
return cmd.run({flags: {}}).then(function () {
util.expectOutput(cli.stdout,
`Owning App Add-on Plan Price Max Price State
──────────── ────── ──────────────────────────── ──────────── ────────── ───────
acme-inc-dwh dwh-db heroku-postgresql:standard-2 ~$0.139/hour $100/month created`)
`Owning App Add-on Plan Price State
──────────── ────── ──────────────────────────── ────────── ───────
acme-inc-dwh dwh-db heroku-postgresql:standard-2 $100/month created`)
})
})
})
Expand All @@ -89,9 +89,9 @@ acme-inc-dwh dwh-db heroku-postgresql:standard-2 ~$0.139/hour $100/month cr
it('prints add-ons in a table with contract', function () {
return cmd.run({flags: {}}).then(function () {
util.expectOutput(cli.stdout,
`Owning App Add-on Plan Price Max Price State
──────────── ────── ──────────────────────────── ──────── ───────── ───────
acme-inc-dwh dwh-db heroku-postgresql:standard-2 contract contract created`)
`Owning App Add-on Plan Price State
──────────── ────── ──────────────────────────── ──────── ───────
acme-inc-dwh dwh-db heroku-postgresql:standard-2 contract created`)
})
})
})
Expand Down
39 changes: 19 additions & 20 deletions packages/addons-v5/test/unit/commands/addons.--app.unit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ describe('addons --app', function () {

return run('acme-inc-www', function () {
util.expectOutput(cli.stdout, `
Add-on Plan Price Max Price State
────────────────────────── ───────── ──────────── ───────── ────────
heroku-postgresql (www-db) mini ~$0.007/hour $5/month created
Add-on Plan Price State
────────────────────────── ───────── ───────── ────────
heroku-postgresql (www-db) mini $5/month created
└─ as DATABASE
heroku-redis (www-redis) premium-2 ~$0.083/hour $60/month creating
heroku-redis (www-redis) premium-2 $60/month creating
└─ as REDIS
The table above shows add-ons and the attachments to the current app (acme-inc-www) or other apps.
Expand All @@ -72,9 +72,9 @@ The table above shows add-ons and the attachments to the current app (acme-inc-w
])
return run('acme-inc-www', function () {
util.expectOutput(cli.stdout, `
Add-on Plan Price Max Price State
───────────────────────────────── ──── ──────────── ───────── ───────
heroku-postgresql (www-db) mini ~$0.007/hour $5/month created
Add-on Plan Price State
───────────────────────────────── ──── ──────── ───────
heroku-postgresql (www-db) mini $5/month created
├─ as DATABASE
└─ as WWW_DB on acme-inc-dwh app
Expand All @@ -91,9 +91,9 @@ The table above shows add-ons and the attachments to the current app (acme-inc-w

return run('acme-inc-dwh', function () {
util.expectOutput(cli.stdout, `
Add-on Plan Price Max Price State
─────────────────────────────────── ──── ──────────────────────────── ──────────────────────────── ───────
heroku-postgresql (www-db) mini (billed to acme-inc-www app) (billed to acme-inc-www app) created
Add-on Plan Price State
─────────────────────────────────── ──── ──────────────────────────── ───────
heroku-postgresql (www-db) mini (billed to acme-inc-www app) created
├─ as WWW_DB
└─ as DATABASE on acme-inc-www app
Expand Down Expand Up @@ -257,9 +257,9 @@ The table above shows add-ons and the attachments to the current app (acme-inc-d
it('prints add-ons in a table with the grandfathered price', function () {
return run('acme-inc-dwh', function () {
util.expectOutput(cli.stdout,
`Add-on Plan Price Max Price State
────────────────────────── ────────── ──────────── ────────── ───────
heroku-postgresql (dwh-db) standard-2 ~$0.139/hour $100/month created
`Add-on Plan Price State
────────────────────────── ────────── ────────── ───────
heroku-postgresql (dwh-db) standard-2 $100/month created
└─ as DATABASE
The table above shows add-ons and the attachments to the current app (acme-inc-dwh) or other apps.`)
})
Expand All @@ -281,10 +281,9 @@ The table above shows add-ons and the attachments to the current app (acme-inc-d
it('prints add-ons in a table with contract', function () {
return run('acme-inc-dwh', function () {
util.expectOutput(cli.stdout,
`
Add-on Plan Price Max Price State
────────────────────────── ────────── ──────── ───────── ───────
heroku-postgresql (dwh-db) standard-2 contract contract created
`Add-on Plan Price State
────────────────────────── ────────── ──────── ───────
heroku-postgresql (dwh-db) standard-2 contract created
└─ as DATABASE
The table above shows add-ons and the attachments to the current app (acme-inc-dwh) or other apps.`)
})
Expand All @@ -296,9 +295,9 @@ The table above shows add-ons and the attachments to the current app (acme-inc-d

return run('acme-inc-api', function () {
util.expectOutput(cli.stdout, `
Add-on Plan Price Max Price State
───────────── ──── ──────────────────────────── ──────────────────────────── ─────
? (www-db) ? (billed to acme-inc-www app) (billed to acme-inc-www app)
Add-on Plan Price State
───────────── ──── ──────────────────────────── ─────
? (www-db) ? (billed to acme-inc-www app)
└─ as WWW_DB
The table above shows add-ons and the attachments to the current app (acme-inc-api) or other apps.
Expand Down
14 changes: 7 additions & 7 deletions packages/addons-v5/test/unit/commands/addons/create.unit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe('addons:create', () => {
args: ['heroku-postgresql:standard-0', '--rollback', '--follow', 'otherdb', '--foo'],
flags: {as: 'mydb'},
})
.then(() => expect(cli.stderr).to.equal('Creating heroku-postgresql:standard-0 on myapp... ~$0.139/hour (max $100/month)\n'))
.then(() => expect(cli.stderr).to.equal('Creating heroku-postgresql:standard-0 on myapp... $100/month\n'))
.then(() => expect(cli.stdout).to.equal(`provision message
Created db3-swiftly-123 as DATABASE_URL
Use heroku addons:docs heroku-db3 to view documentation
Expand Down Expand Up @@ -132,7 +132,7 @@ Use heroku addons:docs heroku-db3 to view documentation
args: ['heroku-postgresql:standard-0'],
flags: {as: 'mydb'},
})
.then(() => expect(cli.stderr).to.equal('Creating heroku-postgresql:standard-0 on myapp... ~$0.139/hour (max $100/month)\n'))
.then(() => expect(cli.stderr).to.equal('Creating heroku-postgresql:standard-0 on myapp... $100/month\n'))
.then(() => expect(cli.stdout).to.equal(`provision message
db3-swiftly-123 is being created in the background. The app will restart when complete...
Use heroku addons:info db3-swiftly-123 to check creation progress
Expand Down Expand Up @@ -162,7 +162,7 @@ Use heroku addons:docs heroku-db3 to view documentation
args: ['heroku-postgresql:standard-0'],
flags: {as: 'mydb'},
})
.then(() => expect(cli.stderr).to.equal('Creating heroku-postgresql:standard-0 on myapp... ~$0.139/hour (max $100/month)\n'))
.then(() => expect(cli.stderr).to.equal('Creating heroku-postgresql:standard-0 on myapp... $100/month\n'))
.then(() => expect(cli.stdout).to.equal(`db3-swiftly-123 is being created in the background. The app will restart when complete...
Use heroku addons:info db3-swiftly-123 to check creation progress
Use heroku addons:docs heroku-db3 to view documentation
Expand Down Expand Up @@ -191,7 +191,7 @@ Use heroku addons:docs heroku-db3 to view documentation
args: ['heroku-postgresql:standard-0'],
flags: {as: 'mydb'},
})
.then(() => expect(cli.stderr).to.equal('Creating heroku-postgresql:standard-0 on myapp... ~$0.139/hour (max $100/month)\n'))
.then(() => expect(cli.stderr).to.equal('Creating heroku-postgresql:standard-0 on myapp... $100/month\n'))
.then(() => expect(cli.stdout).to.equal(`provision message
db3-swiftly-123 is being created in the background. The app will restart when complete...
Use heroku addons:info db3-swiftly-123 to check creation progress
Expand Down Expand Up @@ -246,7 +246,7 @@ Use heroku addons:docs heroku-db3 to view documentation
.then(() => provisionedResponse.done())
.then(() => expect(notifySpy.called).to.equal(true))
.then(() => expect(notifySpy.calledOnce).to.equal(true))
.then(() => expect(cli.stderr).to.equal('Creating heroku-postgresql:standard-0 on myapp... ~$0.139/hour (max $100/month)\nCreating db3-swiftly-123... done\n'))
.then(() => expect(cli.stderr).to.equal('Creating heroku-postgresql:standard-0 on myapp... $100/month\nCreating db3-swiftly-123... done\n'))
.then(() => expect(cli.stdout).to.equal(`provision message
Waiting for db3-swiftly-123...
Created db3-swiftly-123 as DATABASE_URL
Expand Down Expand Up @@ -352,7 +352,7 @@ Use heroku addons:docs heroku-db3 to view documentation
app: 'myapp',
args: ['heroku-postgresql:standard-0', '--rollback', '--follow', 'otherdb', '--foo'],
flags: {as: 'mydb', confirm: 'myapp'},
}).then(() => expect(cli.stderr).to.equal('Creating heroku-postgresql:standard-0 on myapp... !\nCreating heroku-postgresql:standard-0 on myapp... ~$0.139/hour (max $100/month)\n'))
}).then(() => expect(cli.stderr).to.equal('Creating heroku-postgresql:standard-0 on myapp... !\nCreating heroku-postgresql:standard-0 on myapp... $100/month\n'))
.then(() => expect(cli.stdout).to.equal(`provision message
Created db3-swiftly-123 as DATABASE_URL
Use heroku addons:docs heroku-db3 to view documentation
Expand Down Expand Up @@ -399,7 +399,7 @@ Use heroku addons:docs heroku-db3 to view documentation
args: ['heroku-postgresql:standard-0'],
flags: {as: 'mydb'},
})
.then(() => expect(cli.stderr).to.equal('Creating heroku-postgresql:standard-0 on myapp... ~$0.139/hour (max $100/month)\n'))
.then(() => expect(cli.stderr).to.equal('Creating heroku-postgresql:standard-0 on myapp... $100/month\n'))
.then(() => expect(cli.stdout).to.equal(`provision message
Created db3-swiftly-123
Use heroku addons:docs heroku-db3 to view documentation
Expand Down
13 changes: 4 additions & 9 deletions packages/addons-v5/test/unit/commands/addons/info.unit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,9 @@ describe('addons:info', function () {
`=== www-db
Attachments: acme-inc-www::DATABASE
Installed at: Invalid Date
Max Price: $5/month
Owning app: acme-inc-www
Plan: heroku-postgresql:mini
Price: ~$0.007/hour
Price: $5/month
State: created
`)
})
Expand Down Expand Up @@ -71,10 +70,9 @@ State: created
`=== www-db
Attachments: acme-inc-www::DATABASE
Installed at: Invalid Date
Max Price: $5/month
Owning app: acme-inc-www
Plan: heroku-postgresql:mini
Price: ~$0.007/hour
Price: $5/month
State: created
`)
})
Expand Down Expand Up @@ -110,10 +108,9 @@ State: created
`=== www-db
Attachments: acme-inc-www::DATABASE
Installed at: Invalid Date
Max Price: $5/month
Owning app: acme-inc-www
Plan: heroku-postgresql:mini
Price: ~$0.007/hour
Price: $5/month
State: created
`)
})
Expand Down Expand Up @@ -146,10 +143,9 @@ State: created
`=== dwh-db
Attachments: acme-inc-dwh::DATABASE
Installed at: Invalid Date
Max Price: $100/month
Owning app: acme-inc-dwh
Plan: heroku-postgresql:standard-2
Price: ~$0.139/hour
Price: $100/month
State: created
`)
})
Expand Down Expand Up @@ -182,7 +178,6 @@ State: created
`=== dwh-db
Attachments: acme-inc-dwh::DATABASE
Installed at: Invalid Date
Max Price: contract
Owning app: acme-inc-dwh
Plan: heroku-postgresql:standard-2
Price: contract
Expand Down
Loading

0 comments on commit 0a4a28e

Please sign in to comment.