generated from actions/javascript-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.js
43 lines (30 loc) · 2.54 KB
/
index.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
const toggleProtection = require('./toggle-protection');
const MOCK_RULES = '{"url":"https://api.github.com/repos/zalari/action-toggle-branch-protection/branches/master/protection","required_pull_request_reviews":{"url":"https://api.github.com/repos/zalari/action-toggle-branch-protection/branches/master/protection/required_pull_request_reviews","dismiss_stale_reviews":false,"require_code_owner_reviews":false,"required_approving_review_count":1},"enforce_admins":{"url":"https://api.github.com/repos/zalari/action-toggle-branch-protection/branches/master/protection/enforce_admins","enabled":false},"required_linear_history":{"enabled":false},"allow_force_pushes":{"enabled":false},"allow_deletions":{"enabled":false}}';
const MOCK_RULES_TOO = "{\"url\":\"https://api.github.com/repos/zalari/action-toggle-branch-protection/branches/master/protection\",\"required_status_checks\":{\"url\":\"https://api.github.com/repos/zalari/action-toggle-branch-protection/branches/master/protection/required_status_checks\",\"strict\":false,\"contexts\":[\"test\"],\"contexts_url\":\"https://api.github.com/repos/zalari/action-toggle-branch-protection/branches/master/protection/required_status_checks/contexts\"},\"required_pull_request_reviews\":{\"url\":\"https://api.github.com/repos/zalari/action-toggle-branch-protection/branches/master/protection/required_pull_request_reviews\",\"dismiss_stale_reviews\":false,\"require_code_owner_reviews\":false,\"required_approving_review_count\":1},\"enforce_admins\":{\"url\":\"https://api.github.com/repos/zalari/action-toggle-branch-protection/branches/master/protection/enforce_admins\",\"enabled\":false},\"required_linear_history\":{\"enabled\":false},\"allow_force_pushes\":{\"enabled\":false},\"allow_deletions\":{\"enabled\":false}}";
describe('toggleProtection', () => {
it('should return a stringified protection object for passing off', async () => {
const { on } = await toggleProtection({
off: true,
repo: 'action-toggle-branch-protection',
branch: 'master',
owner: 'zalari'
});
expect(on)
.toEqual(MOCK_RULES_TOO);
});
it('should resolve passing on', async () => {
const response = await toggleProtection({
// on: JSON.stringify({
// required_status_checks: null,
// enforce_admins: null,
// required_pull_request_reviews: null,
// restrictions: null
// }),
on: MOCK_RULES_TOO,
repo: 'action-toggle-branch-protection',
branch: 'master',
owner: 'zalari'
});
expect(response).toEqual({nice: true});
});
});