Skip to content

Commit

Permalink
Add tests for index and remove old command
Browse files Browse the repository at this point in the history
  • Loading branch information
raulb committed Aug 22, 2018
1 parent fdafed9 commit 02d7ab5
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 109 deletions.
49 changes: 0 additions & 49 deletions packages/ci-v5/commands/ci/index.js

This file was deleted.

60 changes: 0 additions & 60 deletions packages/ci-v5/test/commands/ci/index-test.js

This file was deleted.

65 changes: 65 additions & 0 deletions packages/ci/test/commands/ci/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import Nock from '@fancy-test/nock'
import * as Test from '@oclif/test'

const test = Test.test
.register('nock', Nock)
const expect = Test.expect

describe('ci', () => {
test
.command(['ci'])
.catch(e => {
expect(e.message).to.contain('Required flag: --pipeline PIPELINE or --app APP')
})
.it('errors when not specifying a pipeline or an app')

describe('when specifying a pipeline', () => {
const pipeline = {id: '14402644-c207-43aa-9bc1-974a34914010', name: 'my-pipeline'}

let testRuns: any = []
const statusIcon = ['✓', '!', '✗', '-']
const statuses = ['succeeded', 'errored', 'failed', 'creating']
const commit_branch = 'master'
const commit_sha = ['d2e177a', '14a0a11', '40d9717', 'f2e574e']

beforeEach(() => {
for (let i = 0; i < 20; i++) {
testRuns.push({
commit_branch,
commit_sha: commit_sha[i % 4],
number: i,
pipeline: {id: pipeline.id},
status: statuses[i % 4]
})
}
})

test
.stdout()
.nock('https://api.heroku.com', api => {
api.get(`/pipelines?eq[name]=${pipeline.name}`)
.reply(200, [
{
id: pipeline.id,
name: pipeline.name
}
])

api.get(`/pipelines/${pipeline.id}/test-runs`)
.reply(200, testRuns)
})
.command(['ci', `--pipeline=${pipeline.name}`])
.it('it shows the latest 15 test runs', ({stdout}) => {
expect(stdout).to.contain(`=== Showing latest test runs for the ${pipeline.name} pipeline`)

for (let i = 5; i < 10; i++) {
expect(stdout).to.contain(`${statusIcon[i % 4]} ${testRuns[i].number} master ${testRuns[i].commit_sha} ${testRuns[i].status}\n`)
}
for (let i = 10; i < 20; i++) {
expect(stdout).to.contain(`${statusIcon[i % 4]} ${testRuns[i].number} master ${testRuns[i].commit_sha} ${testRuns[i].status}\n`)
}

expect(stdout).not.to.contain(`${testRuns[4].number} ${testRuns[4].commit_sha}`)
})
})
})

0 comments on commit 02d7ab5

Please sign in to comment.