forked from github/safe-settings
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvariables.test.js
More file actions
79 lines (67 loc) · 2.06 KB
/
variables.test.js
File metadata and controls
79 lines (67 loc) · 2.06 KB
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
const { when } = require('jest-when')
const Variables = require('../../../../lib/plugins/variables')
describe('Variables', () => {
let github
const org = 'bkeepers'
const repo = 'test'
function fillVariables (variables = []) {
return variables
}
function configure () {
const log = { debug: console.debug, error: console.error }
const errors = []
return new Variables(undefined, github, { owner: org, repo }, [{ name: 'test', value: 'test' }], log, errors)
}
beforeAll(() => {
github = {
request: jest.fn().mockReturnValue(Promise.resolve(true))
}
})
it('sync', () => {
const plugin = configure()
when(github.request)
.calledWith('GET /repos/:org/:repo/actions/variables', { org, repo })
.mockResolvedValue({
data: {
variables: [
fillVariables({
variables: []
})
]
}
});
['variables'].forEach(() => {
when(github.request)
.calledWith('GET /repos/:org/:repo/actions/variables', { org, repo })
.mockResolvedValue({
data: {
variables: [{ name: 'DELETE_me', value: 'test' }]
}
})
})
when(github.request).calledWith('POST /repos/:org/:repo/actions/variables').mockResolvedValue({})
return plugin.sync().then(() => {
expect(github.request).toHaveBeenCalledWith('GET /repos/:org/:repo/actions/variables', { org, repo });
['variables'].forEach(() => {
expect(github.request).toHaveBeenCalledWith('GET /repos/:org/:repo/actions/variables', { org, repo })
})
expect(github.request).toHaveBeenCalledWith(
'DELETE /repos/:org/:repo/actions/variables/:variable_name',
expect.objectContaining({
org,
repo,
variable_name: 'DELETE_me'
})
)
expect(github.request).toHaveBeenCalledWith(
'POST /repos/:org/:repo/actions/variables',
expect.objectContaining({
org,
repo,
name: 'TEST',
value: 'test'
})
)
})
})
})