forked from appvia/githubUserManager
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.spec.ts
More file actions
99 lines (92 loc) · 3.32 KB
/
Copy pathindex.spec.ts
File metadata and controls
99 lines (92 loc) · 3.32 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import { jest } from '@jest/globals'
jest.mock('../src/google.js')
jest.mock('../src/github.js')
import * as google from '../src/google.js'
import * as github from '../src/github.js'
import * as mod from '../index.js'
let processExitSpy
let consoleSpy
beforeEach(() => {
processExitSpy = jest.spyOn(global.process, 'exit').mockImplementation(() => {
return undefined as never
})
consoleSpy = jest.spyOn(global.console, 'log').mockImplementation(() => {})
})
describe('missmatch', () => {
beforeEach(() => {
// @ts-expect-error mockResolved unexpected
google.getGithubUsersFromGoogle.mockResolvedValue(new Set(['a', 'd']))
// @ts-expect-error mockResolved unexpected
github.getGithubUsersFromGithub.mockResolvedValue(new Set(['b', 'c', 'a']))
})
it('should have consistent console output', async () => {
await mod.run()
return expect(consoleSpy).toMatchSnapshot()
})
it('should exit with 0 by default as there is a missmatch', async () => {
await mod.run()
return expect(processExitSpy).toHaveBeenCalledWith(0)
})
it('should exit with 122 if defined when there is a missmatch', async () => {
process.env.EXIT_CODE_ON_MISMATCH = '122'
await mod.run()
return expect(processExitSpy).toHaveBeenCalledWith(122)
})
it('should not add users if not set to', async () => {
delete process.env.ADD_USERS
await mod.run()
return expect(github.addUsersToGitHubOrg).not.toHaveBeenCalled()
})
it('should not remove users if not set to', async () => {
delete process.env.REMOVE_USERS
await mod.run()
return expect(github.removeUsersFromGitHubOrg).not.toHaveBeenCalled()
})
it('should add users if set to', async () => {
process.env.ADD_USERS = 'true'
await mod.run()
return expect(github.addUsersToGitHubOrg).toMatchSnapshot()
})
it('should remove users if set to', async () => {
process.env.REMOVE_USERS = 'true'
await mod.run()
return expect(github.removeUsersFromGitHubOrg).toMatchSnapshot()
})
it('should have consistent console output with full destructive mode on', async () => {
process.env.REMOVE_USERS = 'true'
process.env.ADD_USERS = 'true'
await mod.run()
return expect(consoleSpy).toMatchSnapshot()
})
})
describe('match', () => {
beforeEach(() => {
// @ts-expect-error mockResolved unexpected
google.getGithubUsersFromGoogle.mockResolvedValue(new Set(['a', 'b', 'c', 'd']))
// @ts-expect-error mockResolved unexpected
github.getGithubUsersFromGithub.mockResolvedValue(new Set(['a', 'b', 'c', 'd']))
})
it('should have consistent console output', async () => {
await mod.run()
return expect(consoleSpy).toMatchSnapshot()
})
it('should exit with 0 by default', async () => {
await mod.run()
return expect(processExitSpy).toHaveBeenCalledWith(0)
})
it('should not exit with 122 if defined', async () => {
process.env.EXIT_CODE_ON_MISMATCH = '122'
await mod.run()
return expect(processExitSpy).not.toHaveBeenCalledWith(122)
})
it('should not add users', async () => {
process.env.ADD_USERS = 'true'
await mod.run()
return expect(github.addUsersToGitHubOrg).not.toHaveBeenCalled()
})
it('should not remove users', async () => {
process.env.REMOVE_USERS = 'true'
await mod.run()
return expect(github.removeUsersFromGitHubOrg).not.toHaveBeenCalled()
})
})