1 |
|
2 |
|
3 | const nock = require('nock')
|
4 | const expect = require('chai').expect
|
5 | const cli = require('heroku-cli-util')
|
6 | const sinon = require('sinon')
|
7 | const cmd = require('../../../commands/ci/last')
|
8 |
|
9 | describe('heroku ci:last', function () {
|
10 | let app, coupling, testRun, setupOutput, testOutput
|
11 |
|
12 | beforeEach(function () {
|
13 | cli.mockConsole()
|
14 | sinon.stub(process, 'exit')
|
15 |
|
16 | app = '123-app'
|
17 |
|
18 | coupling = {
|
19 | pipeline: {
|
20 | id: '123-abc',
|
21 | name: '123-abc'
|
22 | }
|
23 | }
|
24 |
|
25 | testRun = {
|
26 | id: '123-abc',
|
27 | number: 123,
|
28 | output_stream_url: 'https://output.com/tests',
|
29 | setup_stream_url: 'https://output.com/setup',
|
30 | pipeline: coupling.pipeline,
|
31 | status: 'succeeded',
|
32 | commit_sha: '123abc456def',
|
33 | commit_branch: 'master'
|
34 | }
|
35 |
|
36 | setupOutput = ''
|
37 | testOutput = ''
|
38 | })
|
39 |
|
40 | afterEach(function () {
|
41 | process.exit.restore()
|
42 | })
|
43 |
|
44 | it('when pipeline has runs, displays the results of the latest run', function* () {
|
45 | const api = nock('https://api.heroku.com')
|
46 | .get(`/apps/${app}/pipeline-couplings`)
|
47 | .reply(200, coupling)
|
48 | .get(`/pipelines/${coupling.pipeline.id}/test-runs`)
|
49 | .reply(200, [testRun])
|
50 | .get(`/pipelines/${coupling.pipeline.id}/test-runs/${testRun.number}`)
|
51 | .reply(200, testRun)
|
52 |
|
53 | const streamAPI = nock('https://output.com')
|
54 | .get('/setup')
|
55 | .reply(200, setupOutput)
|
56 | .get('/tests')
|
57 | .reply(200, testOutput)
|
58 |
|
59 | yield cmd.run({ app })
|
60 | expect(cli.stdout).to.contain(`✓ #${testRun.number}`)
|
61 |
|
62 | api.done()
|
63 | streamAPI.done()
|
64 | })
|
65 |
|
66 | it('when pipeline does not have any runs, reports that there are no runs', function* () {
|
67 | let api = nock('https://api.heroku.com')
|
68 | .get(`/apps/${app}/pipeline-couplings`)
|
69 | .reply(200, coupling)
|
70 | .get(`/pipelines/${coupling.pipeline.id}/test-runs`)
|
71 | .reply(200, [])
|
72 |
|
73 | yield cmd.run({ app })
|
74 | expect(cli.stderr).to.contain('No Heroku CI runs found')
|
75 | api.done()
|
76 | })
|
77 | })
|