generated from eclass/template-semantic-release-plugin
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathpublish.test.js
116 lines (110 loc) · 3.26 KB
/
publish.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
const { describe, it, beforeEach } = require('mocha')
const { expect } = require('chai')
const nock = require('nock')
const publish = require('../src/publish')
describe('Publish', () => {
const ctx = {
env: {
SENTRY_ORG: 'valid',
SENTRY_PROJECT: 'error',
SENTRY_AUTH_TOKEN: 'valid'
},
commits: [
{
hash: 'bb3dedcb1fbbd8ffa8fc75d082ea91340a4c7aa7',
message: 'fix(js): fix request',
author: { name: 'me', email: 'me@me.me' },
committerDate: new Date().toISOString()
}
],
nextRelease: { version: '1.0.0', gitTag: 'v1.0.0' }
}
const SENTRY_HOST = 'https://sentry.io'
const tagsUrl = 'https://myreleases/'
const PATH_RELEASE = '/api/0/organizations/valid/releases/'
const NOCK_OPTIONS = { reqheaders: { authorization: 'Bearer valid' } }
const SERVER_ERROR_TITLE =
'Return SemanticReleaseError if a get a error from sentry'
beforeEach(() => {
nock.disableNetConnect()
nock(SENTRY_HOST, NOCK_OPTIONS)
.post(PATH_RELEASE, body => body.projects.includes('error'))
.reply(500)
nock(SENTRY_HOST, NOCK_OPTIONS)
.post(PATH_RELEASE, body => body.projects.includes('server'))
.replyWithError('server error')
nock(SENTRY_HOST, NOCK_OPTIONS)
.post(PATH_RELEASE, body => body.projects.includes('invalid'))
.reply(201, 'success')
nock(SENTRY_HOST, NOCK_OPTIONS)
.post(PATH_RELEASE)
.reply(201, {
authors: [],
commitCount: 0,
data: {},
dateCreated: new Date().toISOString(),
dateReleased: null,
deployCount: 0,
firstEvent: null,
lastCommit: null,
lastDeploy: null,
lastEvent: null,
newGroups: 0,
owner: null,
projects: [
{
name: 'project',
slug: 'project'
}
],
ref: '6ba09a7c53235ee8a8fa5ee4c1ca8ca886e7fdbb',
shortVersion: '1.0.0',
url: null,
version: '1.0.0'
})
.post('/api/0/organizations/valid/releases/1.0.0/deploys/')
.reply(201, {
name: 'amazon',
url: 'https://api.example.com/',
environment: 'production',
dateStarted: '2020-02-05T10:29:59Z',
dateFinished: '2020-02-05T10:30:43Z',
id: '5044917'
})
})
it(SERVER_ERROR_TITLE, async () => {
try {
// @ts-ignore
await publish({ tagsUrl: '' }, ctx)
} catch (err) {
expect(err.name).to.equal('SemanticReleaseError')
expect(err.code).to.equal('ESENTRYDEPLOY')
}
})
it(SERVER_ERROR_TITLE, async () => {
try {
ctx.env.SENTRY_PROJECT = 'invalid'
// @ts-ignore
await publish({ tagsUrl }, ctx)
} catch (err) {
expect(err.name).to.equal('SemanticReleaseError')
expect(err.code).to.equal('ESENTRYDEPLOY')
}
})
it(SERVER_ERROR_TITLE, async () => {
try {
ctx.env.SENTRY_PROJECT = 'server'
// @ts-ignore
await publish({ tagsUrl }, ctx)
} catch (err) {
expect(err.name).to.equal('SemanticReleaseError')
expect(err.code).to.equal('ESENTRYDEPLOY')
}
})
it('Deploy app', async () => {
ctx.env.SENTRY_PROJECT = 'project'
// @ts-ignore
const result = await publish({ tagsUrl }, ctx)
expect(result.release.version).to.equal('1.0.0')
})
})