-
Notifications
You must be signed in to change notification settings - Fork 216
/
schedules.unit.test.js
72 lines (61 loc) · 1.91 KB
/
schedules.unit.test.js
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
'use strict'
/* global beforeEach afterEach context */
const cli = require('heroku-cli-util')
const {expect} = require('chai')
const nock = require('nock')
const cmd = require('../../../..').commands.find(c => c.topic === 'pg' && c.command === 'backups:schedules')
const shouldSchedules = function (cmdRun) {
let api
let pg
beforeEach(() => {
api = nock('https://api.heroku.com')
pg = nock('https://postgres-api.heroku.com')
cli.mockConsole()
})
afterEach(() => {
nock.cleanAll()
api.done()
pg.done()
})
it('shows empty message with no databases', () => {
api.get('/apps/myapp/addons').reply(200, [])
return expect(cmdRun({app: 'myapp'})).to.be.rejectedWith('No heroku-postgresql databases on myapp')
})
context('with databases', () => {
beforeEach(() => {
api.get('/apps/myapp/addons').reply(200, [
{
id: 1,
name: 'postgres-1',
plan: {name: 'heroku-postgresql:standard-0'},
app: {name: 'myapp'},
},
])
})
it('shows empty message with no schedules', () => {
pg.get('/client/v11/databases/1/transfer-schedules').reply(200, [])
return cmd.run({app: 'myapp'}).then(() => {
expect(cli.stderr).to.contain('No backup schedules found on myapp\n')
expect(cli.stderr).to.contain('Use heroku pg:backups:schedule to set one up\n')
})
})
it('shows schedule', () => {
pg.get('/client/v11/databases/1/transfer-schedules').reply(200, [
{name: 'DATABASE_URL', hour: 5, timezone: 'UTC'},
])
return cmdRun({app: 'myapp'}).then(() =>
expect(cli.stdout).to.equal(
`=== Backup Schedules
DATABASE_URL: daily at 5:00 UTC
`,
),
)
})
})
}
describe('pg:backups:schedules', () => {
shouldSchedules(args => cmd.run(args))
})
describe('pg:backups schedules', () => {
shouldSchedules(require('./helpers.js').dup('schedules', cmd))
})