@@ -1907,6 +1907,96 @@ describe('actions/IOU', () => {
1907
1907
} ) ;
1908
1908
} ) ;
1909
1909
1910
+ describe ( 'a workspace chat with a cancelled payment' , ( ) => {
1911
+ const amount = 10000 ;
1912
+ const comment = '💸💸💸💸' ;
1913
+ const merchant = 'NASDAQ' ;
1914
+
1915
+ afterEach ( ( ) => {
1916
+ mockFetch ?. resume ?.( ) ;
1917
+ } ) ;
1918
+
1919
+ it ( "has an iouReportID of the cancelled payment's expense report" , ( ) => {
1920
+ let expenseReport : OnyxEntry < OnyxTypes . Report > ;
1921
+ let chatReport : OnyxEntry < OnyxTypes . Report > ;
1922
+
1923
+ // Given a signed in account, which owns a workspace, and has a policy expense chat
1924
+ Onyx . set ( ONYXKEYS . SESSION , { email : CARLOS_EMAIL , accountID : CARLOS_ACCOUNT_ID } ) ;
1925
+ return waitForBatchedUpdates ( )
1926
+ . then ( ( ) => {
1927
+ // Which owns a workspace
1928
+ PolicyActions . createWorkspace ( CARLOS_EMAIL , true , "Carlos's Workspace" ) ;
1929
+ return waitForBatchedUpdates ( ) ;
1930
+ } )
1931
+ . then ( ( ) =>
1932
+ TestHelper . getOnyxData ( {
1933
+ key : ONYXKEYS . COLLECTION . REPORT ,
1934
+ waitForCollectionCallback : true ,
1935
+ callback : ( allReports ) => {
1936
+ chatReport = Object . values ( allReports ?? { } ) . find ( ( report ) => report ?. chatType === CONST . REPORT . CHAT_TYPE . POLICY_EXPENSE_CHAT ) ;
1937
+ } ,
1938
+ } ) ,
1939
+ )
1940
+ . then ( ( ) => {
1941
+ if ( chatReport ) {
1942
+ // When an IOU expense is submitted to that policy expense chat
1943
+ IOU . requestMoney ( {
1944
+ report : chatReport ,
1945
+ participantParams : {
1946
+ payeeEmail : RORY_EMAIL ,
1947
+ payeeAccountID : RORY_ACCOUNT_ID ,
1948
+ participant : { login : CARLOS_EMAIL , accountID : CARLOS_ACCOUNT_ID } ,
1949
+ } ,
1950
+ transactionParams : {
1951
+ amount,
1952
+ attendees : [ ] ,
1953
+ currency : CONST . CURRENCY . USD ,
1954
+ created : '' ,
1955
+ merchant,
1956
+ comment,
1957
+ } ,
1958
+ } ) ;
1959
+ }
1960
+ return waitForBatchedUpdates ( ) ;
1961
+ } )
1962
+ . then ( ( ) =>
1963
+ // And given an expense report has now been created which holds the IOU
1964
+ TestHelper . getOnyxData ( {
1965
+ key : ONYXKEYS . COLLECTION . REPORT ,
1966
+ waitForCollectionCallback : true ,
1967
+ callback : ( allReports ) => {
1968
+ expenseReport = Object . values ( allReports ?? { } ) . find ( ( report ) => report ?. type === CONST . REPORT . TYPE . IOU ) ;
1969
+ } ,
1970
+ } ) ,
1971
+ )
1972
+ . then ( ( ) => {
1973
+ // When the expense report is paid elsewhere (but really, any payment option would work)
1974
+ if ( chatReport && expenseReport ) {
1975
+ IOU . payMoneyRequest ( CONST . IOU . PAYMENT_TYPE . ELSEWHERE , chatReport , expenseReport ) ;
1976
+ }
1977
+ return waitForBatchedUpdates ( ) ;
1978
+ } )
1979
+ . then ( ( ) => {
1980
+ if ( chatReport && expenseReport ) {
1981
+ // And when the payment is cancelled
1982
+ IOU . cancelPayment ( expenseReport , chatReport ) ;
1983
+ }
1984
+ return waitForBatchedUpdates ( ) ;
1985
+ } )
1986
+ . then ( ( ) =>
1987
+ TestHelper . getOnyxData ( {
1988
+ key : ONYXKEYS . COLLECTION . REPORT ,
1989
+ waitForCollectionCallback : true ,
1990
+ callback : ( allReports ) => {
1991
+ const chatReportData = allReports ?. [ `${ ONYXKEYS . COLLECTION . REPORT } ${ chatReport ?. reportID } ` ] ;
1992
+ // Then the policy expense chat report has the iouReportID of the IOU expense report
1993
+ expect ( chatReportData ?. iouReportID ) . toBe ( expenseReport ?. reportID ) ;
1994
+ } ,
1995
+ } ) ,
1996
+ ) ;
1997
+ } ) ;
1998
+ } ) ;
1999
+
1910
2000
describe ( 'deleteMoneyRequest' , ( ) => {
1911
2001
const amount = 10000 ;
1912
2002
const comment = 'Send me money please' ;
0 commit comments