@@ -8,12 +8,14 @@ import {
88 connectBankAccountManually ,
99 connectBankAccountWithPlaid ,
1010 createCollectOnlyDepositAccount ,
11+ createCorpayBankAccountForWalletFlow ,
1112 deletePaymentBankAccount ,
1213 getCorpayOnboardingFields ,
1314} from '@userActions/BankAccounts' ;
1415
1516import CONST from '@src/CONST' ;
1617import ONYXKEYS from '@src/ONYXKEYS' ;
18+ import type { InternationalBankAccountForm } from '@src/types/form' ;
1719import type { LastPaymentMethod , PersonalBankAccount } from '@src/types/onyx' ;
1820import type PlaidBankAccount from '@src/types/onyx/PlaidBankAccount' ;
1921
@@ -186,6 +188,49 @@ describe('BankAccounts', () => {
186188 } ) ;
187189 } ) ;
188190
191+ describe ( 'createCorpayBankAccountForWalletFlow' , ( ) => {
192+ const draft : InternationalBankAccountForm = { bankCountry : CONST . COUNTRY . GB , bankCurrency : CONST . CURRENCY . GBP , acceptTerms : 'true' } ;
193+
194+ beforeAll ( ( ) => Onyx . init ( { keys : ONYXKEYS } ) ) ;
195+
196+ beforeEach ( async ( ) => {
197+ await Onyx . set ( ONYXKEYS . FORMS . INTERNATIONAL_BANK_ACCOUNT_FORM_DRAFT , draft ) ;
198+ } ) ;
199+
200+ afterEach ( ( ) => Onyx . clear ( ) ) ;
201+
202+ test ( 'clears the completed draft after successful creation without waiting for the success screen to finish' , async ( ) => {
203+ // Given a retained international draft that could otherwise reopen at confirmation
204+ createCorpayBankAccountForWalletFlow ( draft , 'individual' , CONST . COUNTRY . GB , 'wire' ) ;
205+ const [ , , onyxData ] = mockWrite . mock . calls . at ( - 1 ) ?? [ ] ;
206+
207+ // When the API applies the successful creation updates, even without a mounted confirmation
208+ await Onyx . update ( onyxData ?. successData ?? [ ] ) ;
209+ await waitForBatchedUpdates ( ) ;
210+
211+ // Then the draft is removed and the normal success state is preserved
212+ expect ( await getOnyxValue ( ONYXKEYS . FORMS . INTERNATIONAL_BANK_ACCOUNT_FORM_DRAFT ) ) . toBeUndefined ( ) ;
213+ expect ( await getOnyxValue ( ONYXKEYS . REIMBURSEMENT_ACCOUNT ) ) . toEqual ( expect . objectContaining ( { isSuccess : true , isLoading : false } ) ) ;
214+ } ) ;
215+
216+ test ( 'preserves the draft while creation is pending and after failure so it can be retried' , async ( ) => {
217+ // Given a filled draft submitted for creation
218+ createCorpayBankAccountForWalletFlow ( draft , 'individual' , CONST . COUNTRY . GB , 'wire' ) ;
219+ const [ , , onyxData ] = mockWrite . mock . calls . at ( - 1 ) ?? [ ] ;
220+
221+ // When optimistic updates are applied while the request is pending
222+ await Onyx . update ( onyxData ?. optimisticData ?? [ ] ) ;
223+ await waitForBatchedUpdates ( ) ;
224+
225+ // Then the draft remains available, including after failure updates are applied
226+ expect ( await getOnyxValue ( ONYXKEYS . FORMS . INTERNATIONAL_BANK_ACCOUNT_FORM_DRAFT ) ) . toEqual ( draft ) ;
227+ await Onyx . update ( onyxData ?. failureData ?? [ ] ) ;
228+ await waitForBatchedUpdates ( ) ;
229+ expect ( await getOnyxValue ( ONYXKEYS . FORMS . INTERNATIONAL_BANK_ACCOUNT_FORM_DRAFT ) ) . toEqual ( draft ) ;
230+ expect ( await getOnyxValue ( ONYXKEYS . REIMBURSEMENT_ACCOUNT ) ) . toEqual ( expect . objectContaining ( { isSuccess : false , isLoading : false } ) ) ;
231+ } ) ;
232+ } ) ;
233+
189234 describe ( 'deletePaymentBankAccount' , ( ) => {
190235 const deletedBankAccountID = 123 ;
191236 const replacementBankAccountID = 456 ;
0 commit comments