|
| 1 | +/* This Source Code Form is subject to the terms of the Mozilla Public |
| 2 | + * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 | + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 4 | + |
| 5 | +'use strict'; |
| 6 | + |
| 7 | +const { assert } = require('chai'); |
| 8 | +const { isPasskeyFeatureEnabled } = require('../../lib/passkey-utils'); |
| 9 | +const { AppError } = require('@fxa/accounts/errors'); |
| 10 | + |
| 11 | +describe('passkey-utils', () => { |
| 12 | + describe('isPasskeyFeatureEnabled', () => { |
| 13 | + it('should return true when passkeys are enabled', () => { |
| 14 | + const config = { |
| 15 | + passkeys: { |
| 16 | + enabled: true, |
| 17 | + }, |
| 18 | + }; |
| 19 | + |
| 20 | + const result = isPasskeyFeatureEnabled(config); |
| 21 | + assert.equal(result, true, 'should return true when enabled'); |
| 22 | + }); |
| 23 | + |
| 24 | + it('should throw featureNotEnabled error when passkeys are disabled', () => { |
| 25 | + const config = { |
| 26 | + passkeys: { |
| 27 | + enabled: false, |
| 28 | + }, |
| 29 | + }; |
| 30 | + |
| 31 | + try { |
| 32 | + isPasskeyFeatureEnabled(config); |
| 33 | + assert.fail('should have thrown an error'); |
| 34 | + } catch (error) { |
| 35 | + assert.equal( |
| 36 | + error.errno, |
| 37 | + AppError.featureNotEnabled().errno, |
| 38 | + 'should throw featureNotEnabled error' |
| 39 | + ); |
| 40 | + assert.equal( |
| 41 | + error.message, |
| 42 | + 'Feature not enabled', |
| 43 | + 'should have correct error message' |
| 44 | + ); |
| 45 | + } |
| 46 | + }); |
| 47 | + |
| 48 | + it('should throw featureNotEnabled error when config.passkeys.enabled is undefined', () => { |
| 49 | + const config = { |
| 50 | + passkeys: {}, |
| 51 | + }; |
| 52 | + |
| 53 | + try { |
| 54 | + isPasskeyFeatureEnabled(config); |
| 55 | + assert.fail('should have thrown an error'); |
| 56 | + } catch (error) { |
| 57 | + assert.equal( |
| 58 | + error.errno, |
| 59 | + AppError.featureNotEnabled().errno, |
| 60 | + 'should throw featureNotEnabled error' |
| 61 | + ); |
| 62 | + } |
| 63 | + }); |
| 64 | + }); |
| 65 | +}); |
0 commit comments