|
2 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
3 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
4 | 4 |
|
5 | | -import { isPasskeyFeatureEnabled } from './passkey-utils'; |
6 | | -import { AppError } from '@fxa/accounts/errors'; |
| 5 | +import { |
| 6 | + isPasskeyAuthenticationEnabled, |
| 7 | + isPasskeyFeatureEnabled, |
| 8 | + isPasskeyRegistrationEnabled, |
| 9 | +} from './passkey-utils'; |
7 | 10 |
|
8 | 11 | describe('passkey-utils', () => { |
9 | 12 | describe('isPasskeyFeatureEnabled', () => { |
10 | 13 | it('should return true when passkeys are enabled', () => { |
11 | 14 | const config = { passkeys: { enabled: true } }; |
12 | | - const result = isPasskeyFeatureEnabled(config); |
13 | | - expect(result).toBe(true); |
| 15 | + expect(isPasskeyFeatureEnabled(config)).toBe(true); |
14 | 16 | }); |
15 | 17 |
|
16 | 18 | it('should throw featureNotEnabled error when passkeys are disabled', () => { |
17 | 19 | const config = { passkeys: { enabled: false } }; |
18 | | - try { |
19 | | - isPasskeyFeatureEnabled(config); |
20 | | - throw new Error('should have thrown an error'); |
21 | | - } catch (error: any) { |
22 | | - expect(error.errno).toBe(AppError.featureNotEnabled().errno); |
23 | | - expect(error.message).toBe('Feature not enabled'); |
24 | | - } |
| 20 | + expect(() => isPasskeyFeatureEnabled(config)).toThrow( |
| 21 | + 'Feature not enabled' |
| 22 | + ); |
25 | 23 | }); |
26 | 24 |
|
27 | 25 | it('should throw featureNotEnabled error when config.passkeys.enabled is undefined', () => { |
28 | 26 | const config = { passkeys: {} }; |
29 | | - try { |
30 | | - isPasskeyFeatureEnabled(config); |
31 | | - throw new Error('should have thrown an error'); |
32 | | - } catch (error: any) { |
33 | | - expect(error.errno).toBe(AppError.featureNotEnabled().errno); |
34 | | - } |
| 27 | + expect(() => isPasskeyFeatureEnabled(config)).toThrow( |
| 28 | + 'Feature not enabled' |
| 29 | + ); |
| 30 | + }); |
| 31 | + }); |
| 32 | + |
| 33 | + describe('isPasskeyRegistrationEnabled', () => { |
| 34 | + it('should return true when master and registration flags are both enabled', () => { |
| 35 | + const config = { |
| 36 | + passkeys: { enabled: true, registrationEnabled: true }, |
| 37 | + }; |
| 38 | + expect(isPasskeyRegistrationEnabled(config)).toBe(true); |
| 39 | + }); |
| 40 | + |
| 41 | + it('should throw when master is enabled but registrationEnabled is false', () => { |
| 42 | + const config = { |
| 43 | + passkeys: { enabled: true, registrationEnabled: false }, |
| 44 | + }; |
| 45 | + expect(() => isPasskeyRegistrationEnabled(config)).toThrow( |
| 46 | + 'Feature not enabled' |
| 47 | + ); |
| 48 | + }); |
| 49 | + |
| 50 | + it('should throw when master is disabled even if registrationEnabled is true', () => { |
| 51 | + const config = { |
| 52 | + passkeys: { enabled: false, registrationEnabled: true }, |
| 53 | + }; |
| 54 | + expect(() => isPasskeyRegistrationEnabled(config)).toThrow( |
| 55 | + 'Feature not enabled' |
| 56 | + ); |
| 57 | + }); |
| 58 | + }); |
| 59 | + |
| 60 | + describe('isPasskeyAuthenticationEnabled', () => { |
| 61 | + it('should return true when master and authentication flags are both enabled', () => { |
| 62 | + const config = { |
| 63 | + passkeys: { enabled: true, authenticationEnabled: true }, |
| 64 | + }; |
| 65 | + expect(isPasskeyAuthenticationEnabled(config)).toBe(true); |
| 66 | + }); |
| 67 | + |
| 68 | + it('should throw when master is enabled but authenticationEnabled is false', () => { |
| 69 | + const config = { |
| 70 | + passkeys: { enabled: true, authenticationEnabled: false }, |
| 71 | + }; |
| 72 | + expect(() => isPasskeyAuthenticationEnabled(config)).toThrow( |
| 73 | + 'Feature not enabled' |
| 74 | + ); |
| 75 | + }); |
| 76 | + |
| 77 | + it('should throw when master is disabled even if authenticationEnabled is true', () => { |
| 78 | + const config = { |
| 79 | + passkeys: { enabled: false, authenticationEnabled: true }, |
| 80 | + }; |
| 81 | + expect(() => isPasskeyAuthenticationEnabled(config)).toThrow( |
| 82 | + 'Feature not enabled' |
| 83 | + ); |
35 | 84 | }); |
36 | 85 | }); |
37 | 86 | }); |
0 commit comments