|
1 | | -describe('index', () => { |
2 | | - it.todo('run') |
| 1 | +jest.mock('../src/google') |
| 2 | +jest.mock('../src/github') |
| 3 | +import * as google from '../src/google' |
| 4 | +import * as github from '../src/github' |
| 5 | +import * as mod from '../index' |
| 6 | + |
| 7 | +let processExitSpy |
| 8 | +let consoleSpy |
| 9 | + |
| 10 | +beforeEach(() => { |
| 11 | + processExitSpy = jest.spyOn(global.process, 'exit').mockImplementation(() => { |
| 12 | + return undefined as never |
| 13 | + }) |
| 14 | + consoleSpy = jest.spyOn(global.console, 'log').mockImplementation() |
| 15 | +}) |
| 16 | + |
| 17 | +describe('missmatch', () => { |
| 18 | + beforeEach(() => { |
| 19 | + // @ts-expect-error mockResolved unexpected |
| 20 | + google.getGithubUsersFromGoogle.mockResolvedValue(new Set(['a', 'd'])) |
| 21 | + // @ts-expect-error mockResolved unexpected |
| 22 | + github.getGithubUsersFromGithub.mockResolvedValue(new Set(['b', 'c', 'a'])) |
| 23 | + // github.addUsersToGitHubOrg |
| 24 | + }) |
| 25 | + it('should have consistent console output', async () => { |
| 26 | + await mod.run() |
| 27 | + return expect(consoleSpy).toMatchSnapshot() |
| 28 | + }) |
| 29 | + |
| 30 | + it('should exit with 0 by default as there is a missmatch', async () => { |
| 31 | + await mod.run() |
| 32 | + return expect(processExitSpy).toBeCalledWith(0) |
| 33 | + }) |
| 34 | + it('should exit with 122 if defined when there is a missmatch', async () => { |
| 35 | + process.env.EXIT_CODE_ON_MISMATCH = '122' |
| 36 | + await mod.run() |
| 37 | + return expect(processExitSpy).toBeCalledWith(122) |
| 38 | + }) |
| 39 | + it('should not add users if not set to', async () => { |
| 40 | + await mod.run() |
| 41 | + return expect(github.addUsersToGitHubOrg).not.toBeCalled() |
| 42 | + }) |
| 43 | + it('should not remove users if not set to', async () => { |
| 44 | + await mod.run() |
| 45 | + return expect(github.removeUsersToGitHubOrg).not.toBeCalled() |
| 46 | + }) |
| 47 | + it('should add users if set to', async () => { |
| 48 | + process.env.ADD_USERS = 'true' |
| 49 | + await mod.run() |
| 50 | + return expect(github.addUsersToGitHubOrg).toMatchSnapshot() |
| 51 | + }) |
| 52 | + it('should remove users if set to', async () => { |
| 53 | + process.env.REMOVE_USERS = 'true' |
| 54 | + await mod.run() |
| 55 | + return expect(github.removeUsersToGitHubOrg).toMatchSnapshot() |
| 56 | + }) |
| 57 | + it('should have consistent console output with full destructive mode on', async () => { |
| 58 | + process.env.REMOVE_USERS = 'true' |
| 59 | + process.env.ADD_USERS = 'true' |
| 60 | + await mod.run() |
| 61 | + return expect(consoleSpy).toMatchSnapshot() |
| 62 | + }) |
| 63 | +}) |
| 64 | + |
| 65 | +describe('match', () => { |
| 66 | + beforeEach(() => { |
| 67 | + // @ts-expect-error mockResolved unexpected |
| 68 | + google.getGithubUsersFromGoogle.mockResolvedValue(new Set(['a', 'b', 'c', 'd'])) |
| 69 | + // @ts-expect-error mockResolved unexpected |
| 70 | + github.getGithubUsersFromGithub.mockResolvedValue(new Set(['a', 'b', 'c', 'd'])) |
| 71 | + }) |
| 72 | + it('should have consistent console output', async () => { |
| 73 | + await mod.run() |
| 74 | + return expect(consoleSpy).toMatchSnapshot() |
| 75 | + }) |
| 76 | + it('should exit with 0 by default', async () => { |
| 77 | + await mod.run() |
| 78 | + return expect(processExitSpy).toBeCalledWith(0) |
| 79 | + }) |
| 80 | + it('should not exit with 122 if defined', async () => { |
| 81 | + process.env.EXIT_CODE_ON_MISMATCH = '122' |
| 82 | + await mod.run() |
| 83 | + return expect(processExitSpy).not.toBeCalledWith(122) |
| 84 | + }) |
| 85 | + it('should not add users', async () => { |
| 86 | + process.env.ADD_USERS = 'true' |
| 87 | + await mod.run() |
| 88 | + return expect(github.addUsersToGitHubOrg).not.toBeCalled() |
| 89 | + }) |
| 90 | + it('should not remove users', async () => { |
| 91 | + process.env.REMOVE_USERS = 'true' |
| 92 | + await mod.run() |
| 93 | + return expect(github.removeUsersToGitHubOrg).not.toBeCalled() |
| 94 | + }) |
3 | 95 | }) |
0 commit comments