-
Notifications
You must be signed in to change notification settings - Fork 215
/
disambiguate.unit.test.js
51 lines (42 loc) · 1.46 KB
/
disambiguate.unit.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* eslint-env mocha */
const nock = require('nock')
const expect = require('chai').expect
const Heroku = require('heroku-client')
const herokuAPI = require('../../../lib/heroku-api')
const disambiguate = require('../../../lib/disambiguate')
const pipeline = {
id: '123e4567-e89b-12d3-a456-426655440000',
name: 'my-pipeline',
}
describe('disambiguate', function () {
afterEach(() => nock.cleanAll())
describe('#pipeline', function () {
it('returns pipeline', async function () {
const api = nock('https://api.heroku.com')
.get(`/pipelines/${pipeline.id}`)
.reply(200, pipeline)
const response = await disambiguate(new Heroku(), pipeline.id)
expect(response).to.deep.eq(pipeline)
api.done()
})
it('errors when no pipelines are returned', async function () {
const api = nock('https://api.heroku.com')
.get('/pipelines?eq[name]=notUUID')
.reply(200, [])
let errorMessage
await disambiguate(new Heroku(), 'notUUID').catch(error => {
errorMessage = error.message
})
expect(errorMessage).to.equal('Pipeline not found')
api.done()
})
it('returns a single pipeline', async function () {
const api = nock('https://api.heroku.com')
.get('/pipelines?eq[name]=notUUIDpipeline')
.reply(200, [pipeline])
const response = await disambiguate(new Heroku(), 'notUUIDpipeline')
expect(response).to.deep.eq(pipeline)
api.done()
})
})
})