-
Notifications
You must be signed in to change notification settings - Fork 234
Expand file tree
/
Copy pathrun.unit.test.ts
More file actions
118 lines (102 loc) · 4.04 KB
/
run.unit.test.ts
File metadata and controls
118 lines (102 loc) · 4.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import ansis from 'ansis'
import {expect} from 'chai'
import nock from 'nock'
import {stderr, stdout} from 'stdout-stderr'
import tsheredoc from 'tsheredoc'
import DataPgUpgradeRun from '../../../../../../src/commands/data/pg/upgrade/run.js'
import {
advancedAddonAttachment,
nonAdvancedAddonAttachment,
pgInfo,
} from '../../../../../fixtures/data/pg/fixtures.js'
import runCommand from '../../../../../helpers/runCommand.js'
const heredoc = tsheredoc.default
describe('data:pg:upgrade:run', function () {
it('upgrades an advanced database to the latest version', async function () {
const resolveApi = nock('https://api.heroku.com')
.post('/actions/addon-attachments/resolve')
.reply(200, [advancedAddonAttachment])
const {addon, name: attachmentName} = advancedAddonAttachment
const dataApi = nock('https://api.data.heroku.com')
.get(`/data/postgres/v1/${addon.id}/info`)
.reply(200, {...pgInfo, version: '16.10'})
.post(`/data/postgres/v1/${addon.id}/upgrade/run`, {})
.reply(200, {message: 'Upgrade started. Monitor progress with heroku data:pg:info.'})
await runCommand(DataPgUpgradeRun, [
attachmentName,
'--app=myapp',
'--confirm=myapp',
])
resolveApi.done()
dataApi.done()
expect(ansis.strip(stderr.output)).to.equal(
heredoc(`
Upgrading your ⛁ ${addon.name} database from 16.10 to the latest supported Postgres version... done
Upgrade started. Monitor progress with heroku data:pg:info.
`),
)
expect(stdout.output).to.equal('')
})
it('upgrades an advanced database to a specific version with --version', async function () {
const resolveApi = nock('https://api.heroku.com')
.post('/actions/addon-attachments/resolve')
.reply(200, [advancedAddonAttachment])
const {addon, name: attachmentName} = advancedAddonAttachment
const dataApi = nock('https://api.data.heroku.com')
.get(`/data/postgres/v1/${addon.id}/info`)
.reply(200, {...pgInfo, version: '16.10'})
.post(`/data/postgres/v1/${addon.id}/upgrade/run`, {version: '17.5'})
.reply(200, {message: 'Upgrade to 17.5 started.'})
await runCommand(DataPgUpgradeRun, [
attachmentName,
'--app=myapp',
'--confirm=myapp',
'--version=17.5',
])
resolveApi.done()
dataApi.done()
expect(ansis.strip(stderr.output)).to.include('from 16.10 to 17.5')
expect(ansis.strip(stderr.output)).to.include('Upgrade to 17.5 started.')
})
it('errors if database is not Advanced-tier', async function () {
const resolveApi = nock('https://api.heroku.com')
.post('/actions/addon-attachments/resolve')
.reply(200, [nonAdvancedAddonAttachment])
const {addon, name: attachmentName} = nonAdvancedAddonAttachment
try {
await runCommand(DataPgUpgradeRun, [
attachmentName,
'--app=myapp',
'--confirm=myapp',
])
} catch (error: unknown) {
resolveApi.done()
expect(ansis.strip((error as Error).message)).to.equal(
'You can only use this command on Advanced-tier databases.\n'
+ `Run heroku pg:upgrade:run ${addon.name} --app myapp instead.`,
)
}
})
it('displays the correct error when the upgrade API fails', async function () {
const resolveApi = nock('https://api.heroku.com')
.post('/actions/addon-attachments/resolve')
.reply(200, [advancedAddonAttachment])
const {addon, name: attachmentName} = advancedAddonAttachment
const dataApi = nock('https://api.data.heroku.com')
.get(`/data/postgres/v1/${addon.id}/info`)
.reply(200, {...pgInfo, version: '16.10'})
.post(`/data/postgres/v1/${addon.id}/upgrade/run`)
.reply(422, {message: 'Database is not ready for upgrade.'})
try {
await runCommand(DataPgUpgradeRun, [
attachmentName,
'--app=myapp',
'--confirm=myapp',
])
} catch (error: unknown) {
resolveApi.done()
dataApi.done()
expect(ansis.strip((error as Error).message)).to.include('Database is not ready for upgrade.')
}
})
})