|
| 1 | +import { type BypassConfig } from '../interface/RemoteConfig'; |
| 2 | +import { userHasBypass } from './RemoteConfigProvider'; |
| 3 | +jest.mock('firebase/compat/app', () => ({ |
| 4 | + initializeApp: jest.fn(), |
| 5 | + remoteConfig: jest.fn(() => ({ |
| 6 | + settings: { minimumFetchIntervalMillis: 3600000 }, |
| 7 | + })), |
| 8 | +})); |
| 9 | +describe('userHasBypass', () => { |
| 10 | + beforeEach(() => { |
| 11 | + jest.clearAllMocks(); |
| 12 | + }); |
| 13 | + |
| 14 | + it('should return false if userEmail is null', () => { |
| 15 | + const byPassConfig: BypassConfig = { regex: ['.*@example.com'] }; |
| 16 | + expect(userHasBypass(byPassConfig, null)).toBe(false); |
| 17 | + }); |
| 18 | + |
| 19 | + it('should return false if userEmail is undefined', () => { |
| 20 | + const byPassConfig: BypassConfig = { regex: ['.*@example.com'] }; |
| 21 | + expect(userHasBypass(byPassConfig, undefined)).toBe(false); |
| 22 | + }); |
| 23 | + |
| 24 | + it('should return true if userEmail matches one of the regex patterns', () => { |
| 25 | + const byPassConfig: BypassConfig = { regex: ['.*@example.com'] }; |
| 26 | + expect(userHasBypass(byPassConfig, '[email protected]')).toBe(true); |
| 27 | + }); |
| 28 | + |
| 29 | + it('should return true if userEmail matches one of the more complex regex patterns', () => { |
| 30 | + const byPassConfig: BypassConfig = { regex: ['[^@][email protected]'] }; |
| 31 | + expect(userHasBypass(byPassConfig, '[email protected]')).toBe(true); |
| 32 | + }); |
| 33 | + |
| 34 | + it('should return false if userEmail does not match any regex patterns', () => { |
| 35 | + const byPassConfig: BypassConfig = { regex: ['.*@example.com'] }; |
| 36 | + expect(userHasBypass(byPassConfig, '[email protected]')).toBe(false); |
| 37 | + }); |
| 38 | + |
| 39 | + it('should return true if userEmail matches multiple regex patterns', () => { |
| 40 | + const byPassConfig: BypassConfig = { |
| 41 | + regex: ['.*@example.com', '.*@another.com'], |
| 42 | + }; |
| 43 | + expect(userHasBypass(byPassConfig, '[email protected]')).toBe(true); |
| 44 | + }); |
| 45 | + |
| 46 | + it('should return false if byPassConfig has an empty regex array', () => { |
| 47 | + const byPassConfig: BypassConfig = { regex: [] }; |
| 48 | + expect(userHasBypass(byPassConfig, '[email protected]')).toBe(false); |
| 49 | + }); |
| 50 | + |
| 51 | + it('should return true if user is in list of regex', () => { |
| 52 | + const byPassConfig: BypassConfig = { |
| 53 | + |
| 54 | + }; |
| 55 | + expect(userHasBypass(byPassConfig, '[email protected]')).toBe(true); |
| 56 | + }); |
| 57 | + |
| 58 | + it('should return false if user is not in list', () => { |
| 59 | + const byPassConfig: BypassConfig = { |
| 60 | + |
| 61 | + }; |
| 62 | + expect(userHasBypass(byPassConfig, '[email protected]')).toBe(false); |
| 63 | + }); |
| 64 | + |
| 65 | + it('should not break the function if there is an invalid regex', () => { |
| 66 | + const byPassConfig: BypassConfig = { |
| 67 | + |
| 68 | + }; |
| 69 | + expect(userHasBypass(byPassConfig, '[email protected]')).toBe(true); |
| 70 | + }); |
| 71 | +}); |
0 commit comments