|
1 | 1 | import Onyx from 'react-native-onyx'; |
2 | | -import {connectBankAccountWithPlaid} from '@libs/actions/BankAccounts'; |
| 2 | +import {clearPersonalBankAccount, connectBankAccountWithPlaid} from '@libs/actions/BankAccounts'; |
3 | 3 | import {WRITE_COMMANDS} from '@libs/API/types'; |
4 | 4 | import CONST from '@src/CONST'; |
5 | 5 | import ONYXKEYS from '@src/ONYXKEYS'; |
| 6 | +import ROUTES from '@src/ROUTES'; |
6 | 7 | import type {ReimbursementAccountForm} from '@src/types/form/ReimbursementAccountForm'; |
7 | 8 | import type PlaidBankAccount from '@src/types/onyx/PlaidBankAccount'; |
8 | 9 | import getOnyxValue from '../utils/getOnyxValue'; |
@@ -109,4 +110,49 @@ describe('actions/BankAccounts', () => { |
109 | 110 | }); |
110 | 111 | }); |
111 | 112 | }); |
| 113 | + |
| 114 | + describe('clearPersonalBankAccount', () => { |
| 115 | + test('wipes the entire PERSONAL_BANK_ACCOUNT key by default', async () => { |
| 116 | + await Onyx.set(ONYXKEYS.PERSONAL_BANK_ACCOUNT, {onSuccessFallbackRoute: ROUTES.ENABLE_PAYMENTS, shouldShowSuccess: true}); |
| 117 | + await waitForBatchedUpdates(); |
| 118 | + |
| 119 | + clearPersonalBankAccount(); |
| 120 | + await waitForBatchedUpdates(); |
| 121 | + |
| 122 | + expect(await getOnyxValue(ONYXKEYS.PERSONAL_BANK_ACCOUNT)).toBeFalsy(); |
| 123 | + }); |
| 124 | + |
| 125 | + test('preserves navigation fields and clears form/status fields when shouldPreserveAccountData=true', async () => { |
| 126 | + await Onyx.set(ONYXKEYS.PERSONAL_BANK_ACCOUNT, { |
| 127 | + onSuccessFallbackRoute: ROUTES.ENABLE_PAYMENTS, |
| 128 | + exitReportID: 'report123', |
| 129 | + shouldShowSuccess: true, |
| 130 | + isLoading: true, |
| 131 | + errors: {field: 'error'}, |
| 132 | + updateError: 'addPersonalBankAccount.updatePersonalInfoFailure', |
| 133 | + }); |
| 134 | + await waitForBatchedUpdates(); |
| 135 | + |
| 136 | + clearPersonalBankAccount(true); |
| 137 | + await waitForBatchedUpdates(); |
| 138 | + |
| 139 | + const result = await getOnyxValue(ONYXKEYS.PERSONAL_BANK_ACCOUNT); |
| 140 | + expect(result?.onSuccessFallbackRoute).toBe(ROUTES.ENABLE_PAYMENTS); |
| 141 | + expect(result?.exitReportID).toBe('report123'); |
| 142 | + expect(result?.shouldShowSuccess).toBeFalsy(); |
| 143 | + expect(result?.isLoading).toBeFalsy(); |
| 144 | + expect(result?.errors).toBeFalsy(); |
| 145 | + expect(result?.updateError).toBeFalsy(); |
| 146 | + }); |
| 147 | + |
| 148 | + test('always clears the form draft regardless of the flag', async () => { |
| 149 | + await Onyx.set(ONYXKEYS.FORMS.PERSONAL_BANK_ACCOUNT_FORM_DRAFT, {setupType: CONST.BANK_ACCOUNT.SETUP_TYPE.MANUAL}); |
| 150 | + await waitForBatchedUpdates(); |
| 151 | + |
| 152 | + clearPersonalBankAccount(true); |
| 153 | + await waitForBatchedUpdates(); |
| 154 | + |
| 155 | + expect((await getOnyxValue(ONYXKEYS.FORMS.PERSONAL_BANK_ACCOUNT_FORM_DRAFT))?.setupType).toBeFalsy(); |
| 156 | + }); |
| 157 | + }); |
112 | 158 | }); |
0 commit comments