Skip to content
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
type QueueExpensifyCardForBillingParams = {
feedCountry: string;
feedCountry?: string;
domainAccountID: number;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {ValueOf} from 'type-fest';
type UpdateCardSettlementFrequencyParams = {
settlementFrequency: ValueOf<typeof CONST.EXPENSIFY_CARD.FREQUENCY_SETTING>;
policyAccountID: number;
feedCountry: string;
};

export default UpdateCardSettlementFrequencyParams;
3 changes: 2 additions & 1 deletion src/libs/actions/Card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,7 @@ function updateSettlementFrequency(
const parameters = {
policyAccountID: workspaceAccountID,
settlementFrequency,
feedCountry: programKey,
};

API.write(WRITE_COMMANDS.UPDATE_CARD_SETTLEMENT_FREQUENCY, parameters, {optimisticData, successData, failureData});
Expand Down Expand Up @@ -1777,7 +1778,7 @@ function updateSelectedExpensifyCardFeed(feed: number, policyID: string | undefi
]);
}

function queueExpensifyCardForBilling(feedCountry: string, domainAccountID: number) {
function queueExpensifyCardForBilling(domainAccountID: number, feedCountry?: CardProgramKey) {
const parameters = {
feedCountry,
domainAccountID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {usePersonalDetailsByIDs} from '@hooks/usePersonalDetails';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useThemeStyles from '@hooks/useThemeStyles';

import {getCardSettings} from '@libs/CardUtils';
import {getCardProgramKey, getCardSettings} from '@libs/CardUtils';
import type {PlatformStackRouteProp} from '@libs/Navigation/PlatformStackNavigation/types';
import {isSupportedInviteOnboardingChoice, isSupportedPendingInviteOnboarding} from '@libs/OnboardingUtils';
import {buildQueryStringFromFilterFormValues} from '@libs/SearchQueryUtils';
Expand Down Expand Up @@ -179,7 +179,7 @@ function WorkspaceCardsListLabel({type, value, style}: WorkspaceCardsListLabelPr
if (action !== ModalActions.CONFIRM) {
return;
}
queueExpensifyCardForBilling(CONST.COUNTRY.US, defaultFundID);
queueExpensifyCardForBilling(defaultFundID, getCardProgramKey(cardSettings));
});
};

Expand Down
1 change: 1 addition & 0 deletions tests/actions/CardSettlementFrequencyTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ describe('actions/Card', () => {
expect.objectContaining({
policyAccountID: String(workspaceAccountID),
settlementFrequency: CONST.EXPENSIFY_CARD.FREQUENCY_SETTING.MONTHLY,
feedCountry: programKey,
}),
);
expect(getLastSettlementFrequencyRequestParams()).not.toHaveProperty('monthlySettlementDate');
Expand Down
38 changes: 38 additions & 0 deletions tests/ui/WorkspaceCardsListLabelTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import ComposeProviders from '@components/ComposeProviders';
import {LocaleContextProvider} from '@components/LocaleContextProvider';
import OnyxListItemProvider from '@components/OnyxListItemProvider';

import {WRITE_COMMANDS} from '@libs/API/types';

import WorkspaceCardsListLabel from '@pages/workspace/expensifyCard/WorkspaceCardsListLabel';

import CONST from '@src/CONST';
Expand All @@ -12,6 +14,10 @@ import ONYXKEYS from '@src/ONYXKEYS';
import React from 'react';
import Onyx from 'react-native-onyx';

import type * as ConfirmModalMock from '../utils/mockUseConfirmModal';

import {resetMockConfirmModal, resolveShowConfirmModal} from '../utils/mockUseConfirmModal';
import * as TestHelper from '../utils/TestHelper';
import waitForBatchedUpdatesWithAct from '../utils/waitForBatchedUpdatesWithAct';

const WORKSPACE_ACCOUNT_ID = 424242;
Expand Down Expand Up @@ -47,6 +53,10 @@ jest.mock('@hooks/useWorkspaceAccountID', () => ({
default: () => 424242,
}));

jest.mock('@hooks/useConfirmModal', () => jest.requireActual<typeof ConfirmModalMock>('../utils/mockUseConfirmModal').default);

TestHelper.setupGlobalFetchMock();

const cardSettingsKey = `${ONYXKEYS.COLLECTION.PRIVATE_EXPENSIFY_CARD_SETTINGS}${WORKSPACE_ACCOUNT_ID}` as const;

describe('WorkspaceCardsListLabel', () => {
Expand All @@ -55,12 +65,40 @@ describe('WorkspaceCardsListLabel', () => {
});

afterEach(async () => {
resetMockConfirmModal();
await act(async () => {
await Onyx.clear();
await waitForBatchedUpdatesWithAct();
});
});

it('settles the balance of the card program the workspace is on', async () => {
// Given a UK/EU workspace on monthly settlement, whose card settings live under the GB program
await act(async () => {
await Onyx.merge(cardSettingsKey, {[CONST.COUNTRY.GB]: {monthlySettlementDate: 5}});
await waitForBatchedUpdatesWithAct();
});

// When the admin presses Settle balance and confirms
render(
<ComposeProviders components={[OnyxListItemProvider, LocaleContextProvider]}>
<WorkspaceCardsListLabel
type={CONST.WORKSPACE_CARDS_LIST_LABEL_TYPE.CURRENT_BALANCE}
value={100000}
/>
</ComposeProviders>,
);
await waitForBatchedUpdatesWithAct();
fireEvent.press(screen.getByText('Settle balance'));
await act(async () => {
resolveShowConfirmModal();
await waitForBatchedUpdatesWithAct();
});

// Then the request names the GB program instead of US
TestHelper.expectAPICommandToHaveBeenCalledWith(WRITE_COMMANDS.QUEUE_EXPENSIFY_CARD_FOR_BILLING, 0, {feedCountry: CONST.COUNTRY.GB, domainAccountID: WORKSPACE_ACCOUNT_ID});
});

it('hides Request limit increase from an admin who is not shared on the Plaid settlement account', async () => {
// Given a Plaid settlement account that is not in the admin's bank account list
await act(async () => {
Expand Down
Loading