-
Notifications
You must be signed in to change notification settings - Fork 46
/
deploy-command.test.ts
65 lines (59 loc) · 1.97 KB
/
deploy-command.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
import { expect, test } from '@oclif/test'
import { baseUrl } from '../../src/rest-client/baseUrl'
import simpleGit from 'simple-git'
import * as creds from '../../src/creds'
const successResponseFixture = {
status: 'CREATED',
name: 'elated_leavitt',
artifactUrl: 'https://github.com/nock/nock',
}
const unauthorizedResponseFixture = {
name: 'UnauthorizedError',
message: '',
label: 'UNAUTHORIZED_ERROR',
}
describe('deploy command', () => {
const preset = test
.stub(simpleGit, 'getRemotes', () => () => [
{ name: 'origin', refs: { fetch: 'origin', push: 'origin' } },
{ name: 'upstream', refs: { fetch: 'upstream', push: 'upstream' } },
])
.stub(simpleGit, 'branch', () => () => {
return { current: 'master' }
})
preset
.nock(baseUrl, (api) => {
api.post('/client/deployment').reply(200, successResponseFixture)
})
.stdout()
.do(() => creds.setCreds('test_creds')) // perhaps we got a right creds
.command(['deploy', '-n', successResponseFixture.name])
.it('show success message when rest response is 200', (ctx) => {
expect(ctx.stdout).to.equal(
`Created deployment with name ${successResponseFixture.name}\n`
)
})
preset
.stdout()
.do(() => creds.deleteCreds()) // perhaps we got no creds
.command(['deploy', '-n', successResponseFixture.name])
.catch((err) =>
expect(err.message).to.equal(
`Credentials data not found. Run hydra-cli login`
)
)
.it('show error message when not logged in')
preset
.nock(baseUrl, (api) => {
api.post('/client/deployment').reply(401, unauthorizedResponseFixture)
})
.stdout()
.do(() => creds.setCreds('test_creds')) // perhaps we got an expired or broken creds
.command(['deploy', '-n', successResponseFixture.name])
.catch((err) =>
expect(err.message.indexOf('Run hydra-cli login')).to.satisfy(
(index) => index > 0
)
)
.it('show error message when broken creds')
})