1 |
|
2 |
|
3 |
|
4 | const nock = require('nock')
|
5 | const expect = require('chai').expect
|
6 | const Heroku = require('heroku-client')
|
7 | const herokuAPI = require('../../lib/heroku-api')
|
8 |
|
9 | describe('heroku-api', function () {
|
10 | afterEach(() => nock.cleanAll())
|
11 |
|
12 | describe('#pipelineCoupling', function () {
|
13 | it('gets the pipeline coupling given an app', function* () {
|
14 | const app = 'sausages'
|
15 | const coupling = { pipeline: { id: '123-abc' } }
|
16 | const api = nock(`https://api.heroku.com`)
|
17 | .get(`/apps/${app}/pipeline-couplings`)
|
18 | .reply(200, coupling)
|
19 |
|
20 | const response = yield herokuAPI.pipelineCoupling(new Heroku(), app)
|
21 | expect(response).to.deep.eq(coupling)
|
22 | api.done()
|
23 | })
|
24 | })
|
25 |
|
26 | describe('#pipelineRepository', function () {
|
27 | it('gets the pipeline repository given a pipeline', function* () {
|
28 | const pipeline = '123-abc'
|
29 | const repo = { repository: { name: 'heroku/heroku' } }
|
30 | const api = nock(`https://kolkrabbi.heroku.com`)
|
31 | .get(`/pipelines/${pipeline}/repository`)
|
32 | .reply(200, repo)
|
33 |
|
34 | const response = yield herokuAPI.pipelineRepository(new Heroku(), pipeline)
|
35 | expect(response).to.deep.eq(repo)
|
36 | api.done()
|
37 | })
|
38 | })
|
39 |
|
40 | describe('#getDyno', function () {
|
41 | it('returns dyno information', function* () {
|
42 | const appID = '123-456-67-89'
|
43 | const dynoID = '01234567-89ab-cdef-0123-456789abcdef'
|
44 | const dyno = {
|
45 | id: dynoID,
|
46 | attach_url: 'rendezvous://rendezvous.runtime.heroku.com:5000/{rendezvous-id}',
|
47 | app: { id: appID }
|
48 | }
|
49 |
|
50 | const api = nock(`https://api.heroku.com`)
|
51 | .get(`/apps/${appID}/dynos/${dynoID}`)
|
52 | .reply(200, dyno)
|
53 |
|
54 | const response = yield herokuAPI.getDyno(new Heroku(), appID, dynoID)
|
55 | expect(response).to.deep.eq(dyno)
|
56 | api.done()
|
57 | })
|
58 | })
|
59 |
|
60 | describe('#githubArchiveLink', function () {
|
61 | it('gets a GitHub archive link', function* () {
|
62 | const { user, repository } = ['heroku', 'heroku-ci']
|
63 | const ref = '123-abc'
|
64 | const archiveLink = { archive_link: 'https://example.com' }
|
65 | const api = nock(`https://kolkrabbi.heroku.com`)
|
66 | .get(`/github/repos/${user}/${repository}/tarball/${ref}`)
|
67 | .reply(200, archiveLink)
|
68 |
|
69 | const response = yield herokuAPI.githubArchiveLink(new Heroku(), user, repository, ref)
|
70 | expect(response).to.deep.eq(archiveLink)
|
71 | api.done()
|
72 | })
|
73 | })
|
74 |
|
75 | describe('#testRun', function () {
|
76 | it('gets a test run given a pipeline and number', function* () {
|
77 | const pipeline = '123-abc'
|
78 | const number = 1
|
79 | const testRun = { number }
|
80 | const api = nock(`https://api.heroku.com`, {reqheaders: {Accept: 'application/vnd.heroku+json; version=3.ci'}})
|
81 | .get(`/pipelines/${pipeline}/test-runs/${number}`)
|
82 |
|
83 |
|
84 | .reply(200, testRun)
|
85 |
|
86 | const response = yield herokuAPI.testRun(new Heroku(), pipeline, number)
|
87 | expect(response).to.deep.eq(testRun)
|
88 | api.done()
|
89 | })
|
90 | })
|
91 |
|
92 | describe('#testNodes', function () {
|
93 | it('gets a test run given a pipeline and number', function* () {
|
94 | const testRun = { id: 'uuid-999' }
|
95 | const testNode = { test_run: { id: testRun.id } }
|
96 |
|
97 | const api = nock(`https://api.heroku.com`, {reqheaders: {Accept: 'application/vnd.heroku+json; version=3.ci'}})
|
98 | .get(`/test-runs/${testRun.id}/test-nodes`)
|
99 |
|
100 |
|
101 | .reply(200, [testNode])
|
102 |
|
103 | const response = yield herokuAPI.testNodes(new Heroku(), testRun.id)
|
104 | expect(response).to.deep.eq([testNode])
|
105 | api.done()
|
106 | })
|
107 | })
|
108 |
|
109 | describe('#testRuns', function () {
|
110 | it('gets test runs given a pipeline', function* () {
|
111 | const pipeline = '123-abc'
|
112 | const testRuns = [{ id: '123' }]
|
113 | const api = nock(`https://api.heroku.com`, {reqheaders: {Accept: 'application/vnd.heroku+json; version=3.ci'}})
|
114 | .get(`/pipelines/${pipeline}/test-runs`)
|
115 |
|
116 |
|
117 | .reply(200, testRuns)
|
118 |
|
119 | const response = yield herokuAPI.testRuns(new Heroku(), pipeline)
|
120 | expect(response).to.deep.eq(testRuns)
|
121 | api.done()
|
122 | })
|
123 | })
|
124 |
|
125 | describe('#latestTestRun', function () {
|
126 | it('gets the latest test run given a pipeline', function* () {
|
127 | const pipeline = '123-abc'
|
128 | const testRuns = [{ number: 123 }, { number: 122 }]
|
129 | const api = nock(`https://api.heroku.com`, {reqheaders: {Accept: 'application/vnd.heroku+json; version=3.ci'}})
|
130 | .get(`/pipelines/${pipeline}/test-runs`)
|
131 |
|
132 |
|
133 | .reply(200, testRuns)
|
134 |
|
135 | const response = yield herokuAPI.latestTestRun(new Heroku(), pipeline)
|
136 | expect(response).to.deep.eq(testRuns[0])
|
137 | api.done()
|
138 | })
|
139 | })
|
140 |
|
141 | describe('#createSource', function () {
|
142 | it('creates a source', function* () {
|
143 | const source = { source_blob: { get_url: 'https://example.com/get', put_url: 'https://example.com/put' } }
|
144 | const api = nock(`https://api.heroku.com`)
|
145 | .post(`/sources`)
|
146 | .reply(201, source)
|
147 |
|
148 | const response = yield herokuAPI.createSource(new Heroku())
|
149 | expect(response).to.deep.eq(source)
|
150 | api.done()
|
151 | })
|
152 | })
|
153 |
|
154 | describe('#configVars', function () {
|
155 | it('gets config vars', function* () {
|
156 | const id = '123'
|
157 | const config = { FOO: 'bar' }
|
158 | const api = nock(`https://api.heroku.com`)
|
159 | .get(`/pipelines/${id}/stage/test/config-vars`)
|
160 | .reply(200, config)
|
161 |
|
162 | const response = yield herokuAPI.configVars(new Heroku(), id)
|
163 | expect(response).to.deep.eq(config)
|
164 | api.done()
|
165 | })
|
166 | })
|
167 |
|
168 | describe('#setConfigVars', function () {
|
169 | it('patches config vars', function* () {
|
170 | const id = '123'
|
171 | const config = { FOO: 'bar' }
|
172 | const api = nock(`https://api.heroku.com`)
|
173 | .patch(`/pipelines/${id}/stage/test/config-vars`)
|
174 | .reply(200, config)
|
175 |
|
176 | const response = yield herokuAPI.setConfigVars(new Heroku(), id, config)
|
177 | expect(response).to.deep.eq(config)
|
178 | api.done()
|
179 | })
|
180 | })
|
181 | })
|