1 |
|
2 |
|
3 | const nock = require('nock')
|
4 | const expect = require('chai').expect
|
5 | const Heroku = require('heroku-client')
|
6 | const Utils = require('../../lib/utils')
|
7 | const Factory = require('./factory')
|
8 |
|
9 | describe('Utils', function () {
|
10 | afterEach(() => nock.cleanAll())
|
11 |
|
12 | describe('#getPipeline', function () {
|
13 | it('disambiguates when passing a pipeline', function* () {
|
14 | const pipeline = Factory.pipeline
|
15 | const context = { flags: { pipeline: pipeline.id } }
|
16 | const api = nock(`https://api.heroku.com`)
|
17 | .get(`/pipelines/${pipeline.id}`)
|
18 | .reply(200, pipeline)
|
19 |
|
20 | const response = yield Utils.getPipeline(context, new Heroku())
|
21 | expect(response).to.deep.eq(Factory.pipeline)
|
22 | api.done()
|
23 | })
|
24 |
|
25 | it('uses pipeline-couplings when passing an application', function* () {
|
26 | const app = '123-app'
|
27 |
|
28 | const coupling = { pipeline: Factory.pipeline }
|
29 | const context = { app, flags: {} }
|
30 |
|
31 | const api = nock('https://api.heroku.com')
|
32 | .get(`/apps/${app}/pipeline-couplings`)
|
33 | .reply(200, coupling)
|
34 |
|
35 | const response = yield Utils.getPipeline(context, new Heroku())
|
36 | expect(response).to.deep.eq(Factory.pipeline)
|
37 | api.done()
|
38 | })
|
39 | })
|
40 |
|
41 | describe('#dig', function () {
|
42 | it('is undefined given an undefined object', function () {
|
43 | expect(Utils.dig(undefined)).to.be.undefined
|
44 | })
|
45 |
|
46 | it('deep gets into an object', function () {
|
47 | const obj = { foo: { bar: 'baz' } }
|
48 | expect(Utils.dig(obj, 'foo', 'bar')).to.eq('baz')
|
49 | })
|
50 |
|
51 | it('deep gets into an array', function () {
|
52 | const array = [{ foo: { bar: 'baz' } }]
|
53 | expect(Utils.dig(array, 0, 'foo', 'bar')).to.eq('baz')
|
54 | })
|
55 |
|
56 | it('returns undefined if the path is not present', function () {
|
57 | const obj = { foo: { bar: 'baz' } }
|
58 | expect(Utils.dig(obj, 'foo', 'quz')).to.be.undefined
|
59 | })
|
60 | })
|
61 | })
|