-
Notifications
You must be signed in to change notification settings - Fork 200
Expand file tree
/
Copy pathvariables.test.js
More file actions
66 lines (56 loc) · 2.01 KB
/
variables.test.js
File metadata and controls
66 lines (56 loc) · 2.01 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
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;
}
beforeAll(() => {
github = {
request: jest.fn().mockReturnValue(Promise.resolve(true)),
};
});
it('sync', () => {
const plugin = new Variables(undefined, github, { owner: org, repo }, [{ name: 'test', value: 'test' }], {
debug() {},
});
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: [],
},
});
});
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(
'POST /repos/:org/:repo/actions/variables',
expect.objectContaining({
org,
repo,
name: 'TEST',
value: 'test',
})
);
});
});
});