generated from eclass/template-semantic-release-plugin
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathverify.test.js
132 lines (122 loc) · 3.99 KB
/
verify.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
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
const { describe, it, beforeEach } = require('mocha')
const { expect } = require('chai')
const nock = require('nock')
const verify = require('../src/verify')
describe('Verify', () => {
const env = { SENTRY_ORG: 'invalid', SENTRY_PROJECT: 'project' }
const SENTRY_HOST = 'https://sentry.io'
const NOCK_OPTIONS = { reqheaders: { authorization: 'Bearer valid' } }
beforeEach(() => {
nock.disableNetConnect()
nock(SENTRY_HOST)
.get('/api/0/organizations/invalid/')
.reply(404)
nock(SENTRY_HOST, {
reqheaders: {
authorization: 'Bearer invalid'
}
})
.get('/api/0/organizations/valid/')
.reply(401)
nock(SENTRY_HOST, NOCK_OPTIONS)
.get('/api/0/organizations/valid/')
.reply(200)
nock(SENTRY_HOST, NOCK_OPTIONS)
.post('/api/0/organizations/valid/releases/')
.reply(201)
nock(SENTRY_HOST, NOCK_OPTIONS)
.get('/api/0/organizations/error/')
.replyWithError('server error')
})
it('Return SemanticReleaseError if a SENTRY_AUTH_TOKEN environment variable is not defined', async () => {
try {
// @ts-ignore
await verify({}, { env })
} catch (errs) {
const err = errs._errors[0]
expect(err.name).to.equal('SemanticReleaseError')
expect(err.code).to.equal('ENOSENTRYTOKEN')
}
})
it('Return SemanticReleaseError if a SENTRY_ORG environment variable is not defined', async () => {
try {
env.SENTRY_AUTH_TOKEN = 'invalid'
delete env.SENTRY_ORG
// @ts-ignore
await verify({}, { env })
} catch (errs) {
const err = errs._errors[0]
expect(err.name).to.equal('SemanticReleaseError')
expect(err.code).to.equal('ENOSENTRYORG')
}
})
it('Return SemanticReleaseError if a SENTRY_PROJECT environment variable is not defined', async () => {
try {
env.SENTRY_AUTH_TOKEN = 'invalid'
env.SENTRY_ORG = 'invalid'
delete env.SENTRY_PROJECT
// @ts-ignore
await verify({}, { env })
} catch (errs) {
const err = errs._errors[0]
expect(err.name).to.equal('SemanticReleaseError')
expect(err.code).to.equal('ENOSENTRYPROJECT')
}
})
it('Return SemanticReleaseError if a tagsUrl is invalid', async () => {
try {
env.SENTRY_AUTH_TOKEN = 'invalid'
env.SENTRY_ORG = 'invalid'
env.SENTRY_PROJECT = 'project'
// @ts-ignore
await verify({ tagsUrl: '1111' }, { env })
} catch (errs) {
const err = errs._errors[0]
expect(err.name).to.equal('SemanticReleaseError')
expect(err.code).to.equal('EINVALIDTAGSURL')
}
})
it('Return SemanticReleaseError if a get a error from sentry', async () => {
try {
env.SENTRY_AUTH_TOKEN = 'valid'
env.SENTRY_ORG = 'error'
env.SENTRY_PROJECT = 'project'
// @ts-ignore
await verify({}, { env })
} catch (err) {
expect(err.name).to.equal('SemanticReleaseError')
expect(err.code).to.equal('ESENTRYDEPLOY')
}
})
it('Return SemanticReleaseError if a SENTRY_ORG environment variable is invalid', async () => {
try {
env.SENTRY_AUTH_TOKEN = 'valid'
env.SENTRY_ORG = 'invalid'
env.SENTRY_PROJECT = 'project'
// @ts-ignore
await verify({}, { env })
} catch (err) {
expect(err.name).to.equal('SemanticReleaseError')
expect(err.code).to.equal('EINVALIDSENTRYORG')
}
})
it('Return SemanticReleaseError if a SENTRY_AUTH_TOKEN environment variable is invalid', async () => {
try {
env.SENTRY_AUTH_TOKEN = 'invalid'
env.SENTRY_ORG = 'valid'
env.SENTRY_PROJECT = 'project'
// @ts-ignore
await verify({}, { env })
} catch (err) {
expect(err.name).to.equal('SemanticReleaseError')
expect(err.code).to.equal('EINVALIDSENTRYTOKEN')
}
})
it('Verify alias from a custom environmen variable', async () => {
env.SENTRY_AUTH_TOKEN = 'valid'
env.SENTRY_ORG = 'valid'
env.SENTRY_PROJECT = 'project'
// @ts-ignore
expect(await verify({}, { env })).to.be.a('undefined')
})
})