|
| 1 | +/* |
| 2 | + * Copyright (c) 2026-present, Okta, Inc. and/or its affiliates. All rights reserved. |
| 3 | + * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") |
| 4 | + * |
| 5 | + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. |
| 6 | + * Unless required by applicable law or agreed to in writing, software |
| 7 | + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 8 | + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 9 | + * |
| 10 | + * See the License for the specific language governing permissions and limitations under the License. |
| 11 | + */ |
| 12 | + |
| 13 | +import { getStubFormBag, getStubTransactionWithNextStep } from 'src/mocks/utils/utils'; |
| 14 | + |
| 15 | +import { IDX_STEP } from '../../constants'; |
| 16 | +import { |
| 17 | + DescriptionElement, LaunchAuthenticatorButtonElement, TitleElement, WidgetProps, |
| 18 | +} from '../../types'; |
| 19 | +import { transformNfcPinLaunchAuthenticator } from './transformNfcPinLaunchAuthenticator'; |
| 20 | + |
| 21 | +describe('transformNfcPinLaunchAuthenticator', () => { |
| 22 | + const transaction = getStubTransactionWithNextStep(); |
| 23 | + const formBag = getStubFormBag(); |
| 24 | + const widgetProps = {} as WidgetProps; |
| 25 | + |
| 26 | + beforeEach(() => { |
| 27 | + formBag.uischema.elements = []; |
| 28 | + transaction.context = { |
| 29 | + ...transaction.context, |
| 30 | + app: { type: 'object', value: { label: '' } }, |
| 31 | + }; |
| 32 | + }); |
| 33 | + |
| 34 | + afterEach(() => { |
| 35 | + jest.restoreAllMocks(); |
| 36 | + }); |
| 37 | + |
| 38 | + it('should create title, description, and launch button elements', () => { |
| 39 | + const result = transformNfcPinLaunchAuthenticator({ |
| 40 | + transaction, formBag, widgetProps, |
| 41 | + }); |
| 42 | + |
| 43 | + expect(result.uischema.elements.length).toBe(3); |
| 44 | + expect((result.uischema.elements[0] as TitleElement).type).toBe('Title'); |
| 45 | + expect((result.uischema.elements[1] as DescriptionElement).type).toBe('Description'); |
| 46 | + expect((result.uischema.elements[2] as LaunchAuthenticatorButtonElement).type).toBe('LaunchAuthenticatorButton'); |
| 47 | + }); |
| 48 | + |
| 49 | + it('should use primaryauth.title as the title', () => { |
| 50 | + const result = transformNfcPinLaunchAuthenticator({ |
| 51 | + transaction, formBag, widgetProps, |
| 52 | + }); |
| 53 | + |
| 54 | + expect((result.uischema.elements[0] as TitleElement).options.content) |
| 55 | + .toBe('primaryauth.title'); |
| 56 | + }); |
| 57 | + |
| 58 | + it('should use NFC-specific button label', () => { |
| 59 | + const result = transformNfcPinLaunchAuthenticator({ |
| 60 | + transaction, formBag, widgetProps, |
| 61 | + }); |
| 62 | + |
| 63 | + const button = result.uischema.elements[2] as LaunchAuthenticatorButtonElement; |
| 64 | + expect(button.label).toBe('oie.nfc_pin.launch.button'); |
| 65 | + expect(button.options.i18nKey).toBe('oie.nfc_pin.launch.button'); |
| 66 | + }); |
| 67 | + |
| 68 | + it('should use launch-nfc-authenticator as the step', () => { |
| 69 | + const result = transformNfcPinLaunchAuthenticator({ |
| 70 | + transaction, formBag, widgetProps, |
| 71 | + }); |
| 72 | + |
| 73 | + const button = result.uischema.elements[2] as LaunchAuthenticatorButtonElement; |
| 74 | + expect(button.options.step).toBe(IDX_STEP.LAUNCH_NFC_AUTHENTICATOR); |
| 75 | + }); |
| 76 | + |
| 77 | + it('should show app-specific description when app label is provided', () => { |
| 78 | + transaction.context.app = { type: 'object', value: { label: 'Okta Dashboard' } }; |
| 79 | + |
| 80 | + const result = transformNfcPinLaunchAuthenticator({ |
| 81 | + transaction, formBag, widgetProps, |
| 82 | + }); |
| 83 | + |
| 84 | + expect((result.uischema.elements[1] as DescriptionElement).options.content) |
| 85 | + .toBe('oktaVerify.appDescription'); |
| 86 | + }); |
| 87 | + |
| 88 | + it('should show generic description when no app label', () => { |
| 89 | + transaction.context.app = { type: 'object', value: { label: '' } }; |
| 90 | + |
| 91 | + const result = transformNfcPinLaunchAuthenticator({ |
| 92 | + transaction, formBag, widgetProps, |
| 93 | + }); |
| 94 | + |
| 95 | + expect((result.uischema.elements[1] as DescriptionElement).options.content) |
| 96 | + .toBe('oktaVerify.description'); |
| 97 | + }); |
| 98 | + |
| 99 | + it('should pass deviceChallengeUrl from authenticatorChallenge', () => { |
| 100 | + // @ts-expect-error authenticatorChallenge not typed on context |
| 101 | + transaction.context.authenticatorChallenge = { |
| 102 | + value: { |
| 103 | + href: 'com-okta-authenticator:/deviceChallenge?challengeRequest=mock-jwt', |
| 104 | + challengeMethod: 'CUSTOM_URI', |
| 105 | + }, |
| 106 | + }; |
| 107 | + |
| 108 | + const result = transformNfcPinLaunchAuthenticator({ |
| 109 | + transaction, formBag, widgetProps, |
| 110 | + }); |
| 111 | + |
| 112 | + const button = result.uischema.elements[2] as LaunchAuthenticatorButtonElement; |
| 113 | + expect(button.options.deviceChallengeUrl) |
| 114 | + .toBe('com-okta-authenticator:/deviceChallenge?challengeRequest=mock-jwt'); |
| 115 | + expect(button.options.challengeMethod).toBe('CUSTOM_URI'); |
| 116 | + }); |
| 117 | +}); |
0 commit comments