@@ -5,8 +5,6 @@ import {getOnboardingMessages} from '@libs/actions/Welcome/OnboardingFlow';
55import { WRITE_COMMANDS } from '@libs/API/types' ;
66// eslint-disable-next-line no-restricted-syntax
77import * as PersonalDetailsUtils from '@libs/PersonalDetailsUtils' ;
8- // eslint-disable-next-line no-restricted-syntax
9- import * as PolicyUtils from '@libs/PolicyUtils' ;
108import CONST from '@src/CONST' ;
119import IntlStore from '@src/languages/IntlStore' ;
1210import OnyxUpdateManager from '@src/libs/actions/OnyxUpdateManager' ;
@@ -1071,6 +1069,7 @@ describe('actions/Policy', () => {
10711069 reimbursementAccountError : { } ,
10721070 bankAccountList : { } ,
10731071 lastUsedPaymentMethods : undefined ,
1072+ localeCompare : TestHelper . localeCompare ,
10741073 } ) ;
10751074
10761075 await waitForBatchedUpdates ( ) ;
@@ -1167,6 +1166,7 @@ describe('actions/Policy', () => {
11671166 reimbursementAccountError : undefined ,
11681167 bankAccountList : { } ,
11691168 lastUsedPaymentMethods : undefined ,
1169+ localeCompare : TestHelper . localeCompare ,
11701170 } ) ;
11711171
11721172 await waitForBatchedUpdates ( ) ;
@@ -1181,28 +1181,42 @@ describe('actions/Policy', () => {
11811181 expect ( violations ?. every ( ( violation ) => violation . type !== CONST . VIOLATION_TYPES . VIOLATION ) ) . toBe ( true ) ;
11821182 } ) ;
11831183
1184- it ( 'should update active policy ID to personal policy when deleting the active policy' , async ( ) => {
1185- const personalPolicy = createRandomPolicy ( 0 , CONST . POLICY . TYPE . PERSONAL ) ;
1186- const teamPolicy = createRandomPolicy ( 1 , CONST . POLICY . TYPE . TEAM ) ;
1184+ it ( 'should update active policy ID to most recently created group policy when deleting the active policy' , async ( ) => {
1185+ const personalPolicy = createRandomPolicy ( 1 , CONST . POLICY . TYPE . PERSONAL ) ;
1186+ personalPolicy . created = '2020-01-01 10:00:00' ;
1187+ personalPolicy . pendingAction = null ;
1188+
1189+ const randomGroupPolicy = createRandomPolicy ( 2 , CONST . POLICY . TYPE . TEAM ) ;
1190+ randomGroupPolicy . created = '2021-01-01 10:00:00' ;
1191+ personalPolicy . pendingAction = null ;
1192+
1193+ const randomGroupPolicy2 = createRandomPolicy ( 3 , CONST . POLICY . TYPE . CORPORATE ) ;
1194+ randomGroupPolicy2 . created = '2022-01-01 10:00:00' ;
1195+ randomGroupPolicy2 . pendingAction = null ;
1196+
1197+ const mostRecentlyCreatedGroupPolicy = createRandomPolicy ( 0 , CONST . POLICY . TYPE . TEAM ) ;
1198+ mostRecentlyCreatedGroupPolicy . created = '3000-01-01 10:00:00' ;
1199+ mostRecentlyCreatedGroupPolicy . pendingAction = null ;
11871200
11881201 await Onyx . merge ( `${ ONYXKEYS . COLLECTION . POLICY } ${ personalPolicy . id } ` , personalPolicy ) ;
1189- await Onyx . merge ( `${ ONYXKEYS . COLLECTION . POLICY } ${ teamPolicy . id } ` , teamPolicy ) ;
1190- await Onyx . merge ( ONYXKEYS . NVP_ACTIVE_POLICY_ID , teamPolicy . id ) ;
1202+ await Onyx . merge ( `${ ONYXKEYS . COLLECTION . POLICY } ${ randomGroupPolicy . id } ` , randomGroupPolicy ) ;
1203+ await Onyx . merge ( `${ ONYXKEYS . COLLECTION . POLICY } ${ randomGroupPolicy2 . id } ` , randomGroupPolicy2 ) ;
1204+ await Onyx . merge ( `${ ONYXKEYS . COLLECTION . POLICY } ${ mostRecentlyCreatedGroupPolicy . id } ` , mostRecentlyCreatedGroupPolicy ) ;
1205+ await Onyx . merge ( ONYXKEYS . NVP_ACTIVE_POLICY_ID , randomGroupPolicy . id ) ;
11911206 await waitForBatchedUpdates ( ) ;
11921207
1193- jest . spyOn ( PolicyUtils , 'getPersonalPolicy' ) . mockReturnValue ( personalPolicy ) ;
1194-
11951208 Policy . deleteWorkspace ( {
1196- policyID : teamPolicy . id ,
1197- activePolicyID : teamPolicy . id ,
1198- policyName : teamPolicy . name ,
1209+ policyID : randomGroupPolicy . id ,
1210+ activePolicyID : randomGroupPolicy . id ,
1211+ policyName : randomGroupPolicy . name ,
11991212 lastAccessedWorkspacePolicyID : undefined ,
12001213 policyCardFeeds : undefined ,
12011214 reportsToArchive : [ ] ,
12021215 transactionViolations : undefined ,
12031216 reimbursementAccountError : undefined ,
12041217 bankAccountList : { } ,
12051218 lastUsedPaymentMethods : undefined ,
1219+ localeCompare : TestHelper . localeCompare ,
12061220 } ) ;
12071221 await waitForBatchedUpdates ( ) ;
12081222
@@ -1216,7 +1230,7 @@ describe('actions/Policy', () => {
12161230 } ) ;
12171231 } ) ;
12181232
1219- expect ( activePolicyID ) . toBe ( personalPolicy . id ) ;
1233+ expect ( activePolicyID ) . toBe ( mostRecentlyCreatedGroupPolicy . id ) ;
12201234 } ) ;
12211235
12221236 it ( 'should reset lastAccessedWorkspacePolicyID when deleting the last accessed workspace' , async ( ) => {
@@ -1238,6 +1252,7 @@ describe('actions/Policy', () => {
12381252 reimbursementAccountError : undefined ,
12391253 bankAccountList : { } ,
12401254 lastUsedPaymentMethods : undefined ,
1255+ localeCompare : TestHelper . localeCompare ,
12411256 } ) ;
12421257 await waitForBatchedUpdates ( ) ;
12431258
@@ -1275,6 +1290,7 @@ describe('actions/Policy', () => {
12751290 reimbursementAccountError : undefined ,
12761291 bankAccountList : { } ,
12771292 lastUsedPaymentMethods : undefined ,
1293+ localeCompare : TestHelper . localeCompare ,
12781294 } ) ;
12791295 await waitForBatchedUpdates ( ) ;
12801296
0 commit comments