Skip to content

Commit 95637e3

Browse files
committed
Add tests for clearPersonalBankAccount function
1 parent 2d2226a commit 95637e3

1 file changed

Lines changed: 47 additions & 1 deletion

File tree

tests/actions/BankAccountsTest.ts

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import Onyx from 'react-native-onyx';
2-
import {connectBankAccountWithPlaid} from '@libs/actions/BankAccounts';
2+
import {clearPersonalBankAccount, connectBankAccountWithPlaid} from '@libs/actions/BankAccounts';
33
import {WRITE_COMMANDS} from '@libs/API/types';
44
import CONST from '@src/CONST';
55
import ONYXKEYS from '@src/ONYXKEYS';
6+
import ROUTES from '@src/ROUTES';
67
import type {ReimbursementAccountForm} from '@src/types/form/ReimbursementAccountForm';
78
import type PlaidBankAccount from '@src/types/onyx/PlaidBankAccount';
89
import getOnyxValue from '../utils/getOnyxValue';
@@ -109,4 +110,49 @@ describe('actions/BankAccounts', () => {
109110
});
110111
});
111112
});
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+
});
112158
});

0 commit comments

Comments
 (0)