UNPKG

1.14 kBJavaScriptView Raw
1'use strict'
2/* global describe it beforeEach afterEach */
3
4const cli = require('heroku-cli-util')
5const expect = require('unexpected')
6const nock = require('nock')
7const proxyquire = require('proxyquire')
8
9const addon = {
10 id: 1,
11 name: 'postgres-1',
12 plan: {name: 'heroku-postgresql:standard-0'}
13}
14const fetcher = () => {
15 return {
16 all: () => [addon],
17 addon: () => addon
18 }
19}
20
21const cmd = proxyquire('../../../commands/links', {
22 '../../lib/fetcher': fetcher
23})
24
25describe('pg:links', () => {
26 let api, pg
27
28 beforeEach(() => {
29 api = nock('https://api.heroku.com')
30 pg = nock('https://postgres-api.heroku.com')
31 cli.mockConsole()
32 })
33
34 afterEach(() => {
35 nock.cleanAll()
36 api.done()
37 pg.done()
38 })
39
40 it('shows links', () => {
41 pg.get('/client/v11/databases/1/links').reply(200, [
42 {name: 'redis-link-1', created_at: '100', remote: {attachment_name: 'REDIS', name: 'redis-001'}}
43 ])
44 return cmd.run({app: 'myapp', args: {}, flags: {confirm: 'myapp'}})
45 .then(() => expect(cli.stdout, 'to equal', `=== postgres-1
46
47 * redis-link-1
48created_at: 100
49remote: REDIS (redis-001)
50`))
51 })
52})