@@ -1185,141 +1185,6 @@ describe('actions/IOU/ReportWorkflow', () => {
11851185 expect ( Navigation . navigate ) . not . toHaveBeenCalledWith ( ROUTES . RESTRICTED_ACTION . getRoute ( policyID ) ) ;
11861186 }
11871187 } ) ;
1188-
1189- it ( 'preserves the existing report manager when cached policy data resolves to a different approver' , async ( ) => {
1190- const apiWriteSpy = jest . spyOn ( API , 'write' ) . mockImplementation ( ( ) => Promise . resolve ( ) ) ;
1191- const policyID = '1' ;
1192- const submitterAccountID = 100 ;
1193- const correctManagerAccountID = 101 ;
1194- const defaultApproverAccountID = 102 ;
1195- const submitterEmail = 'submitter@example.com' ;
1196- const correctManagerEmail = 'correct-manager@example.com' ;
1197- const defaultApproverEmail = 'default-approver@example.com' ;
1198-
1199- await Onyx . set ( ONYXKEYS . PERSONAL_DETAILS_LIST , {
1200- [ submitterAccountID ] : { accountID : submitterAccountID , login : submitterEmail } ,
1201- [ correctManagerAccountID ] : { accountID : correctManagerAccountID , login : correctManagerEmail } ,
1202- [ defaultApproverAccountID ] : { accountID : defaultApproverAccountID , login : defaultApproverEmail } ,
1203- } ) ;
1204-
1205- // Given cached policy data resolves to the default approver.
1206- const policy : Policy = {
1207- ...createRandomPolicy ( Number ( policyID ) ) ,
1208- id : policyID ,
1209- type : CONST . POLICY . TYPE . CORPORATE ,
1210- approvalMode : CONST . POLICY . APPROVAL_MODE . ADVANCED ,
1211- approver : defaultApproverEmail ,
1212- owner : defaultApproverEmail ,
1213- employeeList : { } ,
1214- } ;
1215-
1216- // And the report already has the correct manager.
1217- const expenseReport : Report = {
1218- ...createRandomReport ( Number ( policyID ) , undefined ) ,
1219- reportID : '1' ,
1220- policyID,
1221- type : CONST . REPORT . TYPE . EXPENSE ,
1222- ownerAccountID : submitterAccountID ,
1223- managerID : correctManagerAccountID ,
1224- stateNum : CONST . REPORT . STATE_NUM . OPEN ,
1225- statusNum : CONST . REPORT . STATUS_NUM . OPEN ,
1226- total : 1000 ,
1227- currency : CONST . CURRENCY . USD ,
1228- } ;
1229-
1230- // When submitting the report.
1231- submitReport ( {
1232- expenseReport,
1233- policy,
1234- currentUserAccountIDParam : submitterAccountID ,
1235- currentUserEmailParam : submitterEmail ,
1236- hasViolations : false ,
1237- isASAPSubmitBetaEnabled : false ,
1238- expenseReportCurrentNextStepDeprecated : undefined ,
1239- userBillingGracePeriodEnds : undefined ,
1240- amountOwed : 0 ,
1241- ownerBillingGracePeriodEnd : undefined ,
1242- delegateEmail : undefined ,
1243- } ) ;
1244-
1245- // Then the API payload and optimistic report update preserve the existing manager.
1246- const [ , parameters , onyxData ] = apiWriteSpy . mock . calls . at ( 0 ) as [ unknown , { managerAccountID ?: number } , OnyxData < typeof ONYXKEYS . COLLECTION . REPORT > ] ;
1247- expect ( parameters . managerAccountID ) . toBe ( correctManagerAccountID ) ;
1248-
1249- const optimisticReportUpdate = onyxData . optimisticData ?. find ( ( update ) => update . key === `${ ONYXKEYS . COLLECTION . REPORT } ${ expenseReport . reportID } ` ) ;
1250- expect ( ( optimisticReportUpdate ?. value as Report | undefined ) ?. managerID ) . toBe ( correctManagerAccountID ) ;
1251-
1252- apiWriteSpy . mockRestore ( ) ;
1253- } ) ;
1254-
1255- it ( 'ignores the existing report manager when it points to the submitter' , async ( ) => {
1256- // eslint-disable-next-line rulesdir/no-multiple-api-calls -- Inspecting API.write calls to verify submit payload and optimistic data.
1257- const apiWriteSpy = jest . spyOn ( API , 'write' ) . mockImplementation ( ( ) => Promise . resolve ( ) ) ;
1258- const policyID = '1' ;
1259- const submitterAccountID = 100 ;
1260- const computedManagerAccountID = 101 ;
1261- const submitterEmail = 'submitter@example.com' ;
1262- const computedManagerEmail = 'computed-manager@example.com' ;
1263-
1264- await Onyx . set ( ONYXKEYS . PERSONAL_DETAILS_LIST , {
1265- [ submitterAccountID ] : { accountID : submitterAccountID , login : submitterEmail } ,
1266- [ computedManagerAccountID ] : { accountID : computedManagerAccountID , login : computedManagerEmail } ,
1267- } ) ;
1268-
1269- // Given cached policy data resolves to the configured approver.
1270- const policy : Policy = {
1271- ...createRandomPolicy ( Number ( policyID ) ) ,
1272- id : policyID ,
1273- type : CONST . POLICY . TYPE . CORPORATE ,
1274- approvalMode : CONST . POLICY . APPROVAL_MODE . ADVANCED ,
1275- approver : computedManagerEmail ,
1276- owner : computedManagerEmail ,
1277- employeeList : {
1278- [ submitterEmail ] : {
1279- email : submitterEmail ,
1280- submitsTo : computedManagerEmail ,
1281- } ,
1282- } ,
1283- } ;
1284-
1285- // And the draft report manager is still the submitter.
1286- const expenseReport : Report = {
1287- ...createRandomReport ( Number ( policyID ) , undefined ) ,
1288- reportID : '1' ,
1289- policyID,
1290- type : CONST . REPORT . TYPE . EXPENSE ,
1291- ownerAccountID : submitterAccountID ,
1292- managerID : submitterAccountID ,
1293- stateNum : CONST . REPORT . STATE_NUM . OPEN ,
1294- statusNum : CONST . REPORT . STATUS_NUM . OPEN ,
1295- total : 1000 ,
1296- currency : CONST . CURRENCY . USD ,
1297- } ;
1298-
1299- // When submitting the report.
1300- submitReport ( {
1301- expenseReport,
1302- policy,
1303- currentUserAccountIDParam : submitterAccountID ,
1304- currentUserEmailParam : submitterEmail ,
1305- hasViolations : false ,
1306- isASAPSubmitBetaEnabled : false ,
1307- expenseReportCurrentNextStepDeprecated : undefined ,
1308- userBillingGracePeriodEnds : undefined ,
1309- amountOwed : 0 ,
1310- ownerBillingGracePeriodEnd : undefined ,
1311- delegateEmail : undefined ,
1312- } ) ;
1313-
1314- // Then the API payload and optimistic report update use the configured approver instead of routing to the submitter.
1315- const [ , parameters , onyxData ] = apiWriteSpy . mock . calls . at ( 0 ) as [ unknown , { managerAccountID ?: number } , OnyxData < typeof ONYXKEYS . COLLECTION . REPORT > ] ;
1316- expect ( parameters . managerAccountID ) . toBe ( computedManagerAccountID ) ;
1317-
1318- const optimisticReportUpdate = onyxData . optimisticData ?. find ( ( update ) => update . key === `${ ONYXKEYS . COLLECTION . REPORT } ${ expenseReport . reportID } ` ) ;
1319- expect ( ( optimisticReportUpdate ?. value as Report | undefined ) ?. managerID ) . toBe ( computedManagerAccountID ) ;
1320-
1321- apiWriteSpy . mockRestore ( ) ;
1322- } ) ;
13231188 } ) ;
13241189
13251190 describe ( 'delegateAccountID forwarding' , ( ) => {
@@ -1328,7 +1193,6 @@ describe('actions/IOU/ReportWorkflow', () => {
13281193
13291194 beforeEach ( async ( ) => {
13301195 jest . clearAllMocks ( ) ;
1331- // eslint-disable-next-line rulesdir/no-multiple-api-calls -- Inspecting API.write calls to verify optimistic data.
13321196 jest . spyOn ( API , 'write' ) ;
13331197 await Onyx . merge ( ONYXKEYS . PERSONAL_DETAILS_LIST , {
13341198 [ DELEGATE_ACCOUNT_ID ] : {
0 commit comments