@@ -21,8 +21,10 @@ import {
2121} from '@libs/PolicyUtils' ;
2222import { isWorkspaceEligibleForReportChange } from '@libs/ReportUtils' ;
2323import CONST from '@src/CONST' ;
24+ import { getPolicyBrickRoadIndicatorStatus } from '@src/libs/PolicyUtils' ;
2425import ONYXKEYS from '@src/ONYXKEYS' ;
2526import type { PersonalDetailsList , Policy , PolicyEmployeeList , Report , Transaction } from '@src/types/onyx' ;
27+ import type { Connections } from '@src/types/onyx/Policy' ;
2628import createCollection from '../utils/collections/createCollection' ;
2729import createRandomPolicy from '../utils/collections/policies' ;
2830import { createRandomReport } from '../utils/collections/reports' ;
@@ -1032,4 +1034,138 @@ describe('PolicyUtils', () => {
10321034 expect ( result ) . toBe ( false ) ;
10331035 } ) ;
10341036 } ) ;
1037+
1038+ describe ( 'getPolicyBrickRoadIndicatorStatus' , ( ) => {
1039+ const baseAdminPolicy : OnyxEntry < Policy > = {
1040+ id : 'ABC123' ,
1041+ name : 'Test Workspace' ,
1042+ type : CONST . POLICY . TYPE . TEAM ,
1043+ role : CONST . POLICY . ROLE . ADMIN ,
1044+ employeeList : { } ,
1045+ connections : { } ,
1046+ errors : { } ,
1047+ errorFields : { } ,
1048+ } as OnyxEntry < Policy > ;
1049+
1050+ const baseUserPolicy : OnyxEntry < Policy > = {
1051+ id : 'DEF456' ,
1052+ name : 'User Workspace' ,
1053+ type : CONST . POLICY . TYPE . TEAM ,
1054+ role : CONST . POLICY . ROLE . USER ,
1055+ employeeList : { } ,
1056+ connections : { } ,
1057+ errors : { } ,
1058+ errorFields : { } ,
1059+ } as OnyxEntry < Policy > ;
1060+
1061+ it ( 'does return an ERROR RBR when a sync error exists for an admin' , ( ) => {
1062+ const policyWithConnectionFailures = {
1063+ ...baseAdminPolicy ,
1064+ // Failed sync
1065+ connections : {
1066+ [ CONST . POLICY . CONNECTIONS . NAME . NETSUITE ] : {
1067+ verified : false ,
1068+ lastSync : {
1069+ errorDate : new Date ( ) . toISOString ( ) ,
1070+ errorMessage : 'Error' ,
1071+ isAuthenticationError : true ,
1072+ isConnected : false ,
1073+ isSuccessful : false ,
1074+ source : 'NEWEXPENSIFY' ,
1075+ successfulDate : '' ,
1076+ } ,
1077+ } ,
1078+ } as Connections ,
1079+ } as OnyxEntry < Policy > ;
1080+
1081+ const result = getPolicyBrickRoadIndicatorStatus ( policyWithConnectionFailures , false ) ;
1082+ expect ( result ) . toEqual ( CONST . BRICK_ROAD_INDICATOR_STATUS . ERROR ) ;
1083+ } ) ;
1084+
1085+ it ( 'does not return an ERROR RBR when a sync error exists for a user' , ( ) => {
1086+ const policyWithConnectionFailures = {
1087+ ...baseUserPolicy ,
1088+ // Failed sync
1089+ connections : {
1090+ [ CONST . POLICY . CONNECTIONS . NAME . NETSUITE ] : {
1091+ verified : false ,
1092+ lastSync : {
1093+ errorDate : new Date ( ) . toISOString ( ) ,
1094+ errorMessage : 'Error' ,
1095+ isAuthenticationError : true ,
1096+ isConnected : false ,
1097+ isSuccessful : false ,
1098+ source : 'NEWEXPENSIFY' ,
1099+ successfulDate : '' ,
1100+ } ,
1101+ } ,
1102+ } as Connections ,
1103+ } as OnyxEntry < Policy > ;
1104+
1105+ const result = getPolicyBrickRoadIndicatorStatus ( policyWithConnectionFailures , false ) ;
1106+ expect ( result ) . toBeUndefined ( ) ;
1107+ } ) ;
1108+
1109+ it ( 'does not return an ERROR RBR when no sync errors exist for an admin' , ( ) => {
1110+ const policyWithoutConnections = {
1111+ ...baseAdminPolicy ,
1112+ connections : { } as Connections ,
1113+ } as OnyxEntry < Policy > ;
1114+
1115+ const policyWithoutConnectionFailures = {
1116+ ...baseAdminPolicy ,
1117+ connections : {
1118+ [ CONST . POLICY . CONNECTIONS . NAME . NETSUITE ] : {
1119+ verified : true ,
1120+ lastSync : {
1121+ errorDate : '' ,
1122+ errorMessage : '' ,
1123+ isAuthenticationError : false ,
1124+ isConnected : true ,
1125+ isSuccessful : true ,
1126+ source : 'NEWEXPENSIFY' ,
1127+ successfulDate : '' ,
1128+ } ,
1129+ } ,
1130+ } as Connections ,
1131+ } as OnyxEntry < Policy > ;
1132+
1133+ const result = getPolicyBrickRoadIndicatorStatus ( policyWithoutConnectionFailures , false ) ;
1134+ expect ( result ) . toBeUndefined ( ) ;
1135+
1136+ const result2 = getPolicyBrickRoadIndicatorStatus ( policyWithoutConnections , false ) ;
1137+ expect ( result2 ) . toBeUndefined ( ) ;
1138+ } ) ;
1139+
1140+ it ( 'does not return an ERROR RBR when no sync error exists for a user' , ( ) => {
1141+ const policyWithoutConnections = {
1142+ ...baseUserPolicy ,
1143+ connections : { } as Connections ,
1144+ } as OnyxEntry < Policy > ;
1145+
1146+ const policyWithoutConnectionFailures = {
1147+ ...baseUserPolicy ,
1148+ connections : {
1149+ [ CONST . POLICY . CONNECTIONS . NAME . NETSUITE ] : {
1150+ verified : true ,
1151+ lastSync : {
1152+ errorDate : '' ,
1153+ errorMessage : '' ,
1154+ isAuthenticationError : false ,
1155+ isConnected : true ,
1156+ isSuccessful : true ,
1157+ source : 'NEWEXPENSIFY' ,
1158+ successfulDate : '' ,
1159+ } ,
1160+ } ,
1161+ } as Connections ,
1162+ } as OnyxEntry < Policy > ;
1163+
1164+ const result = getPolicyBrickRoadIndicatorStatus ( policyWithoutConnections , false ) ;
1165+ expect ( result ) . toBeUndefined ( ) ;
1166+
1167+ const result2 = getPolicyBrickRoadIndicatorStatus ( policyWithoutConnectionFailures , false ) ;
1168+ expect ( result2 ) . toBeUndefined ( ) ;
1169+ } ) ;
1170+ } ) ;
10351171} ) ;
0 commit comments