Skip to content

Commit

Permalink
chore(pg-v5): add code coverage reports (heroku#2397)
Browse files Browse the repository at this point in the history
* Add test coverage to unschedule.js

* Add test coverage to links/index.js

* WIP test setup working

* WIP successfully setup settings mock

* Dynamically refactored test setup

* Add test coverage

* Update packages/pg-v5/test/unit/commands/backups/unschedule.unit.test.js

Co-authored-by: Katy Bowman <[email protected]>

---------

Co-authored-by: Katy Bowman <[email protected]>
  • Loading branch information
zwhitfield3 and k80bowman authored Jun 23, 2023
1 parent ba951f2 commit 1665912
Show file tree
Hide file tree
Showing 3 changed files with 390 additions and 0 deletions.
29 changes: 29 additions & 0 deletions packages/pg-v5/test/unit/commands/backups/unschedule.unit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,32 @@ describe('pg:backups:unschedule', () => {
describe('pg:backups unschedule', () => {
shouldUnschedule(require('./helpers.js').dup('unschedule', cmd))
})

describe('pg:backups:unschedule error state', () => {
let pg
let api

beforeEach(() => {
api = nock('https://api.heroku.com')
api.get('/apps/myapp/addons').reply(200, [addon])
api.post('/actions/addon-attachments/resolve', {
app: 'myapp',
addon_attachment: 'DATABASE_URL',
addon_service: 'heroku-postgresql',
}).reply(200, [attachment])
pg = nock('https://postgres-api.heroku.com')
pg.get('/client/v11/databases/1/transfer-schedules').twice().reply(200, [{name: 'DATABASE_URL', uuid: '100-001'}, {name: 'DATABASE_URL2', uuid: '100-002'}])
cli.mockConsole()
})

afterEach(() => {
nock.cleanAll()
api.done()
pg.done()
})

it('errors when multiple schedules are returned from API', () => {
return cmd.run({app: 'myapp', args: {}, flags: {at: '06:00 EDT'}})
.catch(error => expect(error.message).to.equal('Specify schedule on myapp. Existing schedules: DATABASE_URL, DATABASE_URL2'))
})
})
13 changes: 13 additions & 0 deletions packages/pg-v5/test/unit/commands/links/index.unit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@ describe('pg:links', () => {
* redis-link-1
created_at: 100
remote: REDIS (redis-001)
`))
})

it('shows links when args are present', () => {
pg.get('/client/v11/databases/1/links').reply(200, [
{name: 'redis-link-1', created_at: '100', remote: {attachment_name: 'REDIS', name: 'redis-001'}},
])
return cmd.run({app: 'myapp', args: {database: 'test-database'}, flags: {confirm: 'myapp'}})
.then(() => expect(cli.stdout).to.equal(`=== postgres-1
* redis-link-1
created_at: 100
remote: REDIS (redis-001)
`))
})
})
Loading

0 comments on commit 1665912

Please sign in to comment.