@@ -34,7 +34,6 @@ import {
3434 canUserPerformWriteAction ,
3535 findLastAccessedReport ,
3636 getAllAncestorReportActions ,
37- getAllReportActionsErrorsAndReportActionThatRequiresAttention ,
3837 getApprovalChain ,
3938 getChatByParticipants ,
4039 getDefaultWorkspaceAvatar ,
@@ -79,7 +78,7 @@ import {buildOptimisticTransaction} from '@libs/TransactionUtils';
7978import CONST from '@src/CONST' ;
8079import IntlStore from '@src/languages/IntlStore' ;
8180import ONYXKEYS from '@src/ONYXKEYS' ;
82- import type { Beta , OnyxInputOrEntry , PersonalDetailsList , Policy , PolicyEmployeeList , Report , ReportAction , ReportActions , ReportNameValuePairs , Transaction } from '@src/types/onyx' ;
81+ import type { Beta , OnyxInputOrEntry , PersonalDetailsList , Policy , PolicyEmployeeList , Report , ReportAction , ReportNameValuePairs , Transaction } from '@src/types/onyx' ;
8382import type { ErrorFields , Errors } from '@src/types/onyx/OnyxCommon' ;
8483import type { Participant } from '@src/types/onyx/Report' ;
8584import { toCollectionDataSet } from '@src/types/utils/CollectionDataSet' ;
@@ -5412,123 +5411,4 @@ describe('ReportUtils', () => {
54125411 } ) ;
54135412 } ) ;
54145413 } ) ;
5415-
5416- describe ( 'getAllReportActionsErrorsAndReportActionThatRequiresAttention' , ( ) => {
5417- const report : Report = {
5418- ...createRandomReport ( 40003 ) ,
5419- parentReportID : '40004' ,
5420- parentReportActionID : '2' ,
5421- } ;
5422- const parentReport : Report = {
5423- ...createRandomReport ( 40004 ) ,
5424- statusNum : 0 ,
5425- } ;
5426- const reportAction1 : ReportAction = {
5427- ...createRandomReportAction ( 1 ) ,
5428- reportID : report . reportID ,
5429- } ;
5430- const parentReportAction1 : ReportAction = {
5431- ...createRandomReportAction ( 2 ) ,
5432- reportID : '40004' ,
5433- actorAccountID : currentUserAccountID ,
5434- } ;
5435- const reportActions = [ reportAction1 , parentReportAction1 ] . reduce < ReportActions > ( ( acc , action ) => {
5436- if ( action . reportActionID ) {
5437- acc [ action . reportActionID ] = action ;
5438- }
5439- return acc ;
5440- } , { } ) ;
5441- beforeEach ( async ( ) => {
5442- await Onyx . clear ( ) ;
5443- await Onyx . set ( ONYXKEYS . SESSION , { email : currentUserEmail , accountID : currentUserAccountID } ) ;
5444- await Onyx . merge ( `${ ONYXKEYS . COLLECTION . REPORT } ${ report . reportID } ` , report ) ;
5445- await Onyx . merge ( `${ ONYXKEYS . COLLECTION . REPORT } ${ parentReport . reportID } ` , parentReport ) ;
5446- await Onyx . merge ( `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ reportAction1 . reportID } ` , {
5447- [ reportAction1 . reportActionID ] : reportAction1 ,
5448- } ) ;
5449- await Onyx . merge ( `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ parentReportAction1 . reportID } ` , {
5450- [ parentReportAction1 . reportActionID ] : parentReportAction1 ,
5451- } ) ;
5452-
5453- return waitForBatchedUpdates ( ) ;
5454- } ) ;
5455- it ( "should return nothing when there's no actions required" , ( ) => {
5456- expect ( getAllReportActionsErrorsAndReportActionThatRequiresAttention ( report , reportActions , false ) ) . toEqual ( {
5457- errors : { } ,
5458- reportAction : undefined ,
5459- } ) ;
5460- } ) ;
5461- it ( "should return error with report action when there's actions required" , async ( ) => {
5462- const reportActionWithError : ReportAction = {
5463- ...createRandomReportAction ( 1 ) ,
5464- reportID : report . reportID ,
5465- errors : {
5466- reportID : 'Error message' ,
5467- accountID : 'Error in accountID' ,
5468- } ,
5469- } ;
5470- const reportActionsWithError = {
5471- ...reportActions ,
5472- [ reportActionWithError . reportActionID ] : reportActionWithError ,
5473- } ;
5474- await Onyx . merge ( `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ reportActionWithError . reportID } ` , {
5475- [ reportActionWithError . reportActionID ] : reportActionWithError ,
5476- } ) ;
5477- await waitForBatchedUpdates ( ) ;
5478- expect ( getAllReportActionsErrorsAndReportActionThatRequiresAttention ( report , reportActionsWithError , false ) ) . toEqual ( {
5479- errors : {
5480- reportID : 'Error message' ,
5481- accountID : 'Error in accountID' ,
5482- } ,
5483- reportAction : reportActionWithError ,
5484- } ) ;
5485- } ) ;
5486- it ( "should return smart scan error with no report action when there's actions required and report is not archived" , async ( ) => {
5487- await Onyx . merge ( `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ parentReportAction1 . reportID } ` , {
5488- [ parentReportAction1 . reportActionID ] : {
5489- actorAccountID : currentUserAccountID ,
5490- actionName : CONST . REPORT . ACTIONS . TYPE . IOU ,
5491- originalMessage : {
5492- type : CONST . IOU . REPORT_ACTION_TYPE . CREATE ,
5493- IOUTransactionID : '12345' ,
5494- } ,
5495- } ,
5496- } ) ;
5497- const transaction : Transaction = {
5498- ...createRandomTransaction ( 12345 ) ,
5499- reportID : parentReport . reportID ,
5500- amount : 0 ,
5501- } ;
5502- await Onyx . merge ( `${ ONYXKEYS . COLLECTION . TRANSACTION } ${ transaction . transactionID } ` , transaction ) ;
5503- await waitForBatchedUpdates ( ) ;
5504- const { errors, reportAction} = getAllReportActionsErrorsAndReportActionThatRequiresAttention ( report , reportActions , false ) ;
5505- expect ( Object . keys ( errors ) ) . toHaveLength ( 1 ) ;
5506- expect ( Object . keys ( errors ) . at ( 0 ) ) . toBe ( 'smartscan' ) ;
5507- expect ( Object . keys ( errors . smartscan ?? { } ) ) . toHaveLength ( 1 ) ;
5508- expect ( errors . smartscan ?. [ Object . keys ( errors . smartscan ) [ 0 ] ] ) . toEqual ( 'Transaction is missing fields' ) ;
5509- expect ( reportAction ) . toBeUndefined ( ) ;
5510- } ) ;
5511- it ( "should return no error and no report action when there's actions required and report is archived" , async ( ) => {
5512- await Onyx . merge ( `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ parentReportAction1 . reportID } ` , {
5513- [ parentReportAction1 . reportActionID ] : {
5514- actorAccountID : currentUserAccountID ,
5515- actionName : CONST . REPORT . ACTIONS . TYPE . IOU ,
5516- originalMessage : {
5517- type : CONST . IOU . REPORT_ACTION_TYPE . CREATE ,
5518- IOUTransactionID : '12345' ,
5519- } ,
5520- } ,
5521- } ) ;
5522- const transaction : Transaction = {
5523- ...createRandomTransaction ( 12345 ) ,
5524- reportID : parentReport . reportID ,
5525- amount : 0 ,
5526- } ;
5527- await Onyx . merge ( `${ ONYXKEYS . COLLECTION . TRANSACTION } ${ transaction . transactionID } ` , transaction ) ;
5528- await waitForBatchedUpdates ( ) ;
5529- const { errors, reportAction} = getAllReportActionsErrorsAndReportActionThatRequiresAttention ( report , reportActions , true ) ;
5530- expect ( Object . keys ( errors ) ) . toHaveLength ( 0 ) ;
5531- expect ( reportAction ) . toBeUndefined ( ) ;
5532- } ) ;
5533- } ) ;
55345414} ) ;
0 commit comments