Skip to content

Commit e96169a

Browse files
committed
tests: add the proper MFA context implementation
1 parent 7422d96 commit e96169a

File tree

1 file changed

+128
-1
lines changed

1 file changed

+128
-1
lines changed

tests/unit/components/MultifactorAuthentication/helpers.test.ts

Lines changed: 128 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
import type {Writable} from 'type-fest';
1+
import type {ValueOf, Writable} from 'type-fest';
22
import {
3+
convertResultIntoMultifactorAuthenticationStatus,
34
createAuthorizeErrorStatus,
45
doesDeviceSupportBiometrics,
56
getAuthTypeName,
7+
getNotificationPath,
68
getNotificationPaths,
9+
getNotificationRoute,
710
isBiometryConfigured,
811
isValidScenario,
912
resetKeys,
13+
shouldAllowBiometrics,
1014
shouldClearScenario,
1115
Status,
1216
} from '@components/MultifactorAuthentication/helpers';
@@ -506,4 +510,127 @@ describe('MultifactorAuthentication helpers', () => {
506510
expect(result.headerTitle).toBe('New title');
507511
});
508512
});
513+
514+
describe('shouldAllowBiometrics', () => {
515+
it('should return true when biometrics is the allowed type', () => {
516+
const result = shouldAllowBiometrics(CONST.MULTIFACTOR_AUTHENTICATION.TYPE.BIOMETRICS);
517+
expect(result).toBe(true);
518+
});
519+
520+
it('should return false for other authentication types', () => {
521+
// Assuming there might be other types, we test with a different value
522+
expect(shouldAllowBiometrics('OTHER_TYPE' as ValueOf<typeof CONST.MULTIFACTOR_AUTHENTICATION.TYPE>)).toBe(false);
523+
});
524+
});
525+
526+
describe('getNotificationRoute', () => {
527+
it('should return not found route when path is undefined', () => {
528+
const result = getNotificationRoute(undefined);
529+
expect(typeof result).toBe('string');
530+
});
531+
532+
it('should return notification route for valid path', () => {
533+
const result = getNotificationRoute('biometrics-test-success');
534+
expect(typeof result).toBe('string');
535+
});
536+
});
537+
538+
describe('getNotificationPath', () => {
539+
it('should construct notification path with scenario prefix and success suffix', () => {
540+
const result = getNotificationPath('biometrics-test', 'success');
541+
expect(result).toContain('success');
542+
expect(result).toContain('biometrics-test');
543+
});
544+
545+
it('should construct notification path with scenario prefix and failure suffix', () => {
546+
const result = getNotificationPath('biometrics-test', 'failure');
547+
expect(result).toContain('failure');
548+
expect(result).toContain('biometrics-test');
549+
});
550+
551+
it('should use default prefix when scenario is undefined', () => {
552+
const result = getNotificationPath(undefined, 'success');
553+
expect(result).toContain('biometrics-test');
554+
expect(result).toContain('success');
555+
});
556+
});
557+
558+
describe('convertResultIntoMultifactorAuthenticationStatus', () => {
559+
it('should convert status with scenario and type', () => {
560+
const sourceStatus: MultifactorAuthenticationStatus<boolean> = {
561+
value: true,
562+
reason: CONST.MULTIFACTOR_AUTHENTICATION.REASON.GENERIC.NO_ACTION_MADE_YET,
563+
step: {
564+
wasRecentStepSuccessful: true,
565+
isRequestFulfilled: true,
566+
requiredFactorForNextStep: undefined,
567+
},
568+
scenario: CONST.MULTIFACTOR_AUTHENTICATION.SCENARIO.BIOMETRICS_TEST,
569+
headerTitle: 'Test',
570+
title: 'Test',
571+
description: 'Test',
572+
notificationPaths: {successNotification: 'biometrics-test-success', failureNotification: 'biometrics-test-failure'},
573+
};
574+
575+
const result = convertResultIntoMultifactorAuthenticationStatus(
576+
sourceStatus,
577+
CONST.MULTIFACTOR_AUTHENTICATION.SCENARIO.BIOMETRICS_TEST,
578+
CONST.MULTIFACTOR_AUTHENTICATION.SCENARIO_TYPE.AUTHORIZATION,
579+
false,
580+
);
581+
582+
expect(result).toHaveProperty('value');
583+
expect(result.value).toHaveProperty('type');
584+
expect(result.value).toHaveProperty('payload');
585+
});
586+
587+
it('should extract payload from scenario parameters', () => {
588+
const sourceStatus: MultifactorAuthenticationPartialStatus<boolean> = {
589+
value: true,
590+
reason: CONST.MULTIFACTOR_AUTHENTICATION.REASON.GENERIC.NO_ACTION_MADE_YET,
591+
step: {
592+
wasRecentStepSuccessful: true,
593+
isRequestFulfilled: true,
594+
requiredFactorForNextStep: undefined,
595+
},
596+
};
597+
598+
const params = {validateCode: 123456, customParam: 'test'};
599+
600+
const result = convertResultIntoMultifactorAuthenticationStatus(
601+
sourceStatus,
602+
CONST.MULTIFACTOR_AUTHENTICATION.SCENARIO.BIOMETRICS_TEST,
603+
CONST.MULTIFACTOR_AUTHENTICATION.SCENARIO_TYPE.AUTHORIZATION,
604+
params,
605+
);
606+
607+
expect(result.value).toHaveProperty('payload');
608+
});
609+
610+
it('should handle false params by setting payload to undefined', () => {
611+
const sourceStatus: MultifactorAuthenticationStatus<boolean> = {
612+
value: true,
613+
reason: CONST.MULTIFACTOR_AUTHENTICATION.REASON.GENERIC.NO_ACTION_MADE_YET,
614+
step: {
615+
wasRecentStepSuccessful: true,
616+
isRequestFulfilled: true,
617+
requiredFactorForNextStep: undefined,
618+
},
619+
scenario: CONST.MULTIFACTOR_AUTHENTICATION.SCENARIO.BIOMETRICS_TEST,
620+
headerTitle: 'Test',
621+
title: 'Test',
622+
description: 'Test',
623+
notificationPaths: {successNotification: 'biometrics-test-success', failureNotification: 'biometrics-test-failure'},
624+
};
625+
626+
const result = convertResultIntoMultifactorAuthenticationStatus(
627+
sourceStatus,
628+
CONST.MULTIFACTOR_AUTHENTICATION.SCENARIO.BIOMETRICS_TEST,
629+
CONST.MULTIFACTOR_AUTHENTICATION.SCENARIO_TYPE.AUTHORIZATION,
630+
false,
631+
);
632+
633+
expect(result.value.payload).toBeUndefined();
634+
});
635+
});
509636
});

0 commit comments

Comments
 (0)