-
Notifications
You must be signed in to change notification settings - Fork 214
/
connect.unit.test.ts
84 lines (80 loc) · 2.55 KB
/
connect.unit.test.ts
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import {expect, test} from '@oclif/test'
describe('pipelines:connect', () => {
describe('when the user is not linked to GitHub', () => {
test
.stderr()
.stdout()
.nock('https://kolkrabbi.heroku.com', kolkrabbi => {
kolkrabbi.get('/account/github/token').reply(401, {})
})
.command(['pipelines:connect', 'my-pipeline', '--repo=my-org/my-repo'])
.catch('Account not connected to GitHub.')
.it('displays an error')
})
describe('with an account connected to GitHub', () => {
test
.nock('https://kolkrabbi.heroku.com', kolkrabbi => {
const kolkrabbiAccount = {
github: {
token: '123-abc',
},
}
const pipeline = {
id: 123,
name: 'my-pipeline',
}
kolkrabbi.get('/account/github/token').reply(200, kolkrabbiAccount)
return kolkrabbi.post(`/pipelines/${pipeline.id}/repository`).reply(201, {})
})
.nock('https://api.github.com', github => {
const repo = {
id: 1235,
default_branch: 'main',
name: 'my-org/my-repo',
}
github.get(`/repos/${repo.name}`).reply(200, {repo})
})
.nock('https://api.heroku.com', api => {
const pipeline = {
id: 123,
name: 'my-pipeline',
}
return api.get(`/pipelines/${pipeline.name}`)
.reply(200, {
id: pipeline.id,
name: pipeline.name,
})
})
.stderr()
.stdout()
.command(['pipelines:connect', 'my-pipeline', '--repo=my-org/my-repo'])
.it('shows success', ctx => {
expect(ctx.stderr).to.include('Linking to repo...')
expect(ctx.stdout).to.equal('')
})
})
describe('with an account connected to GitHub experiencing request failures', () => {
test
.nock('https://kolkrabbi.heroku.com', kolkrabbi => {
const kolkrabbiAccount = {
github: {
token: '123-abc',
},
}
kolkrabbi.get('/account/github/token').reply(200, kolkrabbiAccount)
})
.nock('https://api.github.com', github => {
const repo = {
id: 1235,
default_branch: 'main',
name: 'my-org/my-repo',
}
github.get(`/repos/${repo.name}`).reply(401, {})
})
.command(['pipelines:connect', 'my-pipeline', '--repo=my-org/my-repo'])
.catch(error => {
expect(error.message).to.contain('Could not access the my-org/my-repo repo')
})
.it('shows an error if GitHub request fails')
})
})