Skip to content

Commit 4ae3e02

Browse files
authored
Merge branch 'heroku:main' into maarten/heroku-ps-exec-elixir-iex
2 parents f53352c + afc97fa commit 4ae3e02

24 files changed

Lines changed: 278 additions & 420 deletions

‎test/unit/commands/access/update.unit.test.ts‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,14 @@ describe('heroku access:update', function () {
7070
})
7171
it('returns an error when passing permissions', async function () {
7272
personalApp()
73-
await runCommand(Cmd, [
73+
const {error} = await runCommand(Cmd, [
7474
'--app',
7575
'myapp',
7676
'--permissions',
7777
'view,deploy',
7878
'gandalf@heroku.com',
79-
]).catch(error => {
80-
const {message} = error as {message: string}
81-
expect(ansis.strip(message)).to.contain('Error: cannot update permissions. The app ⬢ myapp is not owned by a team')
82-
})
79+
])
80+
expect(ansis.strip(error?.message ?? '')).to.contain('Error: cannot update permissions. The app ⬢ myapp is not owned by a team')
8381
})
8482
})
8583
})

‎test/unit/commands/accounts/add.unit.test.ts‎

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,8 @@ describe('accounts:add', function () {
104104

105105
listStub.resolves([{name: 'testAccountName', username: 'testEmail'}])
106106

107-
try {
108-
await runCommand(Cmd, ['testAccountName'])
109-
} catch (error: unknown) {
110-
expect((error as Error).message).to.contain('testAccountName already exists')
111-
}
107+
const {error} = await runCommand(Cmd, ['testAccountName'])
108+
expect(error?.message).to.contain('testAccountName already exists')
112109
})
113110

114111
it('should error if the email already has an alias', async function () {
@@ -121,11 +118,8 @@ describe('accounts:add', function () {
121118

122119
listStub.resolves([{name: 'existingAlias', username: 'testEmail'}])
123120

124-
try {
125-
await runCommand(Cmd, ['newAlias'])
126-
} catch (error: unknown) {
127-
expect((error as Error).message).to.contain('testEmail already has an alias: existingAlias')
128-
}
121+
const {error} = await runCommand(Cmd, ['newAlias'])
122+
expect(error?.message).to.equal('Account testEmail already has an alias of existingAlias.')
129123
})
130124
})
131125
})

‎test/unit/commands/accounts/current.unit.test.ts‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,8 @@ describe('accounts:current', function () {
2525

2626
it('should print an error message if no account is found', async function () {
2727
currentStub.resolves(null)
28-
await runCommand(Cmd, [])
29-
.catch((error: Error) => {
30-
const expected = 'You haven\'t set an account. Run heroku accounts:add <account-name> to add an account to your cache or heroku accounts:set <account-name> to set the current account.'
31-
expect(ansis.strip(error.message)).to.equal(expected)
32-
})
28+
const {error} = await runCommand(Cmd, [])
29+
expect(ansis.strip(error?.message ?? '')).to.equal(`You haven't set an account.\n
30+
Run heroku accounts:add <account-name> to add an account to your cache or heroku accounts:set <account-name> to set the current account.`)
3331
})
3432
})

‎test/unit/commands/accounts/index.unit.test.ts‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ describe('accounts', function () {
2727

2828
it('should print an error message if no accounts are found', async function () {
2929
listStub.resolves([])
30-
await runCommand(Cmd, [])
31-
.catch((error: Error) => {
32-
expect(error.message).to.contain('You don\'t have any accounts in your cache.')
33-
})
30+
const {error} = await runCommand(Cmd, [])
31+
expect(error?.message).to.contain('You don\'t have any accounts in your cache.')
3432
})
3533
})

‎test/unit/commands/accounts/remove.unit.test.ts‎

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,21 @@ describe('accounts:remove', function () {
3232
it('should return an error if the selected account name is not included in the account list', async function () {
3333
currentStub.resolves('test-account')
3434
listStub.resolves([{name: 'test-account', username: 'user1'}, {name: 'test-account-2', username: 'user2'}])
35-
await runCommand(Cmd, ['test-account-3'])
36-
.catch((error: Error) => {
37-
expect(error.message).to.contain('test-account-3 doesn\'t exist in your accounts cache.')
38-
})
35+
const {error} = await runCommand(Cmd, ['test-account-3'])
36+
expect(error?.message).to.contain('test-account-3 doesn\'t exist in your accounts cache.')
3937
})
4038

4139
it('should return an error if the selected account name is the current account', async function () {
4240
currentStub.resolves('test-account')
4341
listStub.resolves([{name: 'test-account', username: 'user1'}, {name: 'test-account-2', username: 'user2'}])
44-
await runCommand(Cmd, ['test-account'])
45-
.catch((error: Error) => {
46-
expect(ansis.strip(error.message)).to.equal('test-account is the current account. To log out, run heroku logout.')
47-
})
42+
const {error} = await runCommand(Cmd, ['test-account'])
43+
expect(ansis.strip(error?.message ?? '')).to.equal('test-account is the current account. To log out, run $ heroku logout .')
4844
})
4945

5046
it('should return an error if the selected account is the current account (aliased)', async function () {
5147
currentStub.resolves('user1@example.com')
5248
listStub.resolves([{name: 'test-account', username: 'user1@example.com'}, {name: 'test-account-2', username: 'user2@example.com'}])
53-
await runCommand(Cmd, ['test-account'])
54-
.catch((error: Error) => {
55-
expect(ansis.strip(error.message)).to.equal('test-account is the current account. To log out, run heroku logout.')
56-
})
49+
const {error} = await runCommand(Cmd, ['test-account'])
50+
expect(ansis.strip(error?.message ?? '')).to.equal('test-account is the current account. To log out, run $ heroku logout .')
5751
})
5852
})

‎test/unit/commands/addons/create.unit.test.ts‎

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,15 @@ describe('addons:create', function () {
5858
})
5959
context('calling addons:create without a plan', function () {
6060
it('errors out with usage', async function () {
61-
return runCommand(Cmd, [
61+
const {error} = await runCommand(Cmd, [
6262
'--app',
6363
'myapp',
6464
'--name',
6565
'foobar',
6666
])
67-
.catch((error: unknown) => {
68-
expect((error as Error).message).to.equal('Missing 1 required arg:\n'
69-
+ 'service:plan unique identifier or unique name of the add-on service plan\n'
70-
+ 'See more help with --help')
71-
})
67+
expect(error?.message).to.equal('Missing 1 required arg:\n'
68+
+ 'service:plan unique identifier or unique name of the add-on service plan\n'
69+
+ 'See more help with --help')
7270
})
7371
})
7472
context('creating a db', function () {
@@ -262,21 +260,19 @@ describe('addons:create', function () {
262260
deprovisionedAddon.state = 'deprovisioned'
263261
api.get('/apps/myapp/addons/postgresql-swiftly-123')
264262
.reply(200, deprovisionedAddon)
265-
try {
266-
return await runCommand(Cmd, [
267-
'--app',
268-
'myapp',
269-
'--as',
270-
'mydb',
271-
'--wait',
272-
'heroku-postgresql:standard-0',
273-
'--',
274-
'--wait',
275-
])
276-
} catch {
277-
expect(notifyStub.called).to.equal(true)
278-
expect(notifyStub.calledOnce).to.equal(true)
279-
}
263+
const {error} = await runCommand(Cmd, [
264+
'--app',
265+
'myapp',
266+
'--as',
267+
'mydb',
268+
'--wait',
269+
'heroku-postgresql:standard-0',
270+
'--',
271+
'--wait',
272+
])
273+
expect(error?.message).to.equal('The add-on was unable to be created, with status deprovisioned')
274+
expect(notifyStub.called).to.equal(true)
275+
expect(notifyStub.calledOnce).to.equal(true)
280276
})
281277
})
282278
context('when add-on provision errors', function () {
@@ -299,13 +295,13 @@ describe('addons:create', function () {
299295
})
300296
})
301297
context('creating a db requiring confirmation', function () {
302-
it('aborts if confirmation does not match', function () {
298+
it('aborts if confirmation does not match', async function () {
303299
api.post('/apps/myapp/addons', {
304300
attachment: {name: 'mydb'}, config: {follow: 'otherdb', foo: true, rollback: true}, confirm: 'not-my-app', plan: {name: 'heroku-postgresql:standard-0'},
305301
})
306302
.reply(423, {id: 'confirmation_required', message: 'This add-on is not automatically networked with this Private Space. '}, {'X-Confirmation-Required': 'myapp-confirm'})
307303

308-
return runCommand(Cmd, [
304+
const {error} = await runCommand(Cmd, [
309305
'--app',
310306
'myapp',
311307
'--as',
@@ -319,9 +315,7 @@ describe('addons:create', function () {
319315
'otherdb',
320316
'--foo',
321317
])
322-
.catch(error => {
323-
expect(ansis.strip(error.message)).to.equal('Confirmation not-my-app did not match myapp. Aborted.')
324-
})
318+
expect(ansis.strip(error?.message ?? '')).to.equal('Confirmation not-my-app did not match myapp. Aborted.')
325319
})
326320

327321
it('succeeds if confirmation does match', async function () {

‎test/unit/commands/addons/rename.unit.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ describe('addons:rename', function () {
3131
nock('https://api.heroku.com')
3232
.get('/addons/not-an-addon')
3333
.reply(404, {id: 'not_found', message: "Couldn't find that add-on.", resource: 'addon'})
34-
await runCommand(Cmd, ['not-an-addon', 'cache-redis'])
35-
.catch(error => expect(error.message).to.contain("Couldn't find that add-on."))
34+
const {error} = await runCommand(Cmd, ['not-an-addon', 'cache-redis'])
35+
expect(error?.message).to.contain("Couldn't find that add-on.")
3636
})
3737
})
3838
})

‎test/unit/commands/addons/upgrade.unit.test.ts‎

Lines changed: 22 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -136,17 +136,12 @@ describe('addons:upgrade', function () {
136136
})
137137

138138
it('errors with no plan', async function () {
139-
try {
140-
await runCommand(Cmd, [
141-
'--app',
142-
'myapp',
143-
'heroku-redis',
144-
])
145-
} catch (error) {
146-
if (error instanceof Error) {
147-
expect(error.message).to.contain('Error: No plan specified')
148-
}
149-
}
139+
const {error} = await runCommand(Cmd, [
140+
'--app',
141+
'myapp',
142+
'heroku-redis',
143+
])
144+
expect(error?.message).to.contain('Error: No plan specified')
150145
})
151146

152147
it('errors with invalid plan', async function () {
@@ -169,46 +164,31 @@ describe('addons:upgrade', function () {
169164
.patch('/apps/myapp/addons/db1-swiftly-123', {plan: {name: 'heroku-db1:invalid'}})
170165
.reply(422, {message: 'Couldn\'t find either the add-on service or the add-on plan of "heroku-db1:invalid".'})
171166

172-
try {
173-
await runCommand(Cmd, [
174-
'--app',
175-
'myapp',
176-
'heroku-db1:invalid',
177-
])
178-
} catch (error) {
179-
if (error instanceof Error) {
180-
expect(ansis.strip(error.message)).to.equal('Couldn\'t find either the add-on service or the add-on plan of "heroku-db1:invalid".\n\nHere are the available plans for heroku-db1:\nheroku-db1:free\nheroku-db1:basic\nheroku-db1:premium-0\n\nSee more plan information with heroku addons:plans heroku-db1\n\nhttps://devcenter.heroku.com/articles/managing-add-ons')
181-
}
182-
}
167+
const {error} = await runCommand(Cmd, [
168+
'--app',
169+
'myapp',
170+
'heroku-db1:invalid',
171+
])
172+
expect(ansis.strip(error?.message ?? '')).to.equal('Couldn\'t find either the add-on service or the add-on plan of "heroku-db1:invalid".\n\nHere are the available plans for heroku-db1:\nheroku-db1:free\nheroku-db1:basic\nheroku-db1:premium-0\n\nSee more plan information with heroku addons:plans heroku-db1\n\nhttps://devcenter.heroku.com/articles/managing-add-ons')
183173
})
184174

185175
it('displays an error when multiple matches exist', async function () {
186176
api.post('/actions/addons/resolve', {addon: 'heroku-postgresql', app: 'myapp'})
187177
.reply(422, {id: 'multiple_matches', message: 'Multiple matches'})
188-
try {
189-
await runCommand(Cmd, [
190-
'--app',
191-
'myapp',
192-
'heroku-postgresql:hobby',
193-
])
194-
} catch (error) {
195-
if (error instanceof Error) {
196-
expect(error.message).to.contain('Multiple add-ons match')
197-
}
198-
}
178+
const {error} = await runCommand(Cmd, [
179+
'--app',
180+
'myapp',
181+
'heroku-postgresql:hobby',
182+
])
183+
expect(error?.message).to.contain('Multiple add-ons match')
199184
})
200185

201186
it('handles multiple add-ons', async function () {
202187
api.post('/actions/addons/resolve', {addon: 'heroku-redis', app: null})
203188
.reply(200, [{name: 'db1-swiftly-123'}, {name: 'db1-swiftly-456'}])
204-
try {
205-
await runCommand(Cmd, [
206-
'heroku-redis:invalid',
207-
])
208-
} catch (error) {
209-
if (error instanceof Error) {
210-
expect(error.message).to.contain('multiple matching add-ons found')
211-
}
212-
}
189+
const {error} = await runCommand(Cmd, [
190+
'heroku-redis:invalid',
191+
])
192+
expect(error?.message).to.contain('multiple matching add-ons found')
213193
})
214194
})

‎test/unit/commands/addons/wait.unit.test.ts‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,10 @@ Created www-redis as REDIS_URL
125125
nock('https://api.heroku.com', {reqheaders: expansionHeaders})
126126
.get('/apps/acme-inc-www/addons/www-redis')
127127
.reply(200, deprovisionedAddon)
128-
await runCommand(Cmd, ['www-redis'])
129-
.catch(error => {
130-
expect(error.message).to.equal('The add-on was unable to be created, with status deprovisioned')
131-
expect(notifyStub.called).to.be.true
132-
expect(notifyStub.calledOnce).to.be.true
133-
})
128+
const {error} = await runCommand(Cmd, ['www-redis'])
129+
expect(error?.message).to.equal('The add-on was unable to be created, with status deprovisioned')
130+
expect(notifyStub.called).to.be.true
131+
expect(notifyStub.calledOnce).to.be.true
134132
})
135133
it('shows that it failed to provision', async function () {
136134
const notifyStub = sandbox.stub(Cmd, 'notifier')

‎test/unit/commands/apps/leave.unit.test.ts‎

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,22 @@ describe('heroku apps:leave', function () {
6060

6161
describe('when the user tries to leave the app', function () {
6262
it('shows an error if the heroku.delete() operation returns an error', async function () {
63-
try {
64-
await runCommand(LeaveCommand, [
65-
'--app',
66-
'myapp',
67-
])
68-
apiGetUserAccount.done()
69-
apiDeletePersonalAppCollaborator.done()
70-
} catch (error) {
71-
expect(error).to.be.an.instanceof(Error)
72-
}
63+
nock.cleanAll()
64+
65+
const account = nock('https://api.heroku.com')
66+
.get('/account')
67+
.reply(200, {email: 'gandalf@heroku.com'})
68+
const deletion = nock('https://api.heroku.com')
69+
.delete(`/apps/myapp/collaborators/${encodeURIComponent('gandalf@heroku.com')}`)
70+
.reply(403, {id: 'forbidden', message: 'You cannot leave this app.'})
71+
72+
const {error} = await runCommand(LeaveCommand, [
73+
'--app',
74+
'myapp',
75+
])
76+
expect(error).to.be.an.instanceof(Error)
77+
account.done()
78+
deletion.done()
7379
})
7480
})
7581
})

0 commit comments

Comments
 (0)