Skip to content
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
type SetCompanyCardTransactionLiability = {
policyID: string;
bankName: string;
domainAccountID: number;
liabilityType: string;
};

Expand Down
1 change: 1 addition & 0 deletions src/libs/actions/CompanyCards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ function setWorkspaceCompanyCardTransactionLiability(domainOrWorkspaceAccountID:

const parameters = {
policyID,
domainAccountID: domainOrWorkspaceAccountID,
bankName,
liabilityType,
};
Expand Down
41 changes: 41 additions & 0 deletions tests/actions/CompanyCardsLiabilityTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import {setWorkspaceCompanyCardTransactionLiability} from '@libs/actions/CompanyCards';
import {WRITE_COMMANDS} from '@libs/API/types';

import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';

const POLICY_ID = 'A1B2C3D4E5F60718';
const DOMAIN_ACCOUNT_ID = 1234567;
const FEED = CONST.COMPANY_CARD.FEED_BANK_NAME.VISA;

describe('actions/CompanyCards setWorkspaceCompanyCardTransactionLiability', () => {
afterEach(() => {
jest.restoreAllMocks();
});

it('targets the feed-owning domain account when restricting deletion on a domain feed', () => {
// Given a domain feed, whose settings live on the +@domain account rather than the workspace account
const apiWriteSpy = jest.spyOn(require('@libs/API'), 'write').mockImplementation(() => Promise.resolve());

// When an admin turns off deleting transactions for that feed
setWorkspaceCompanyCardTransactionLiability(DOMAIN_ACCOUNT_ID, POLICY_ID, FEED, CONST.COMPANY_CARDS.DELETE_TRANSACTIONS.RESTRICT);

// Then the domainAccountID is forwarded to the backend, so the setting is written to the correct account, and the optimistic Onyx write targets that same account.
expect(apiWriteSpy).toHaveBeenCalledWith(
WRITE_COMMANDS.SET_COMPANY_CARD_TRANSACTION_LIABILITY,
expect.objectContaining({
policyID: POLICY_ID,
bankName: FEED,
liabilityType: CONST.COMPANY_CARDS.DELETE_TRANSACTIONS.RESTRICT,
domainAccountID: DOMAIN_ACCOUNT_ID,
}),
expect.objectContaining({
optimisticData: expect.arrayContaining([
expect.objectContaining({
key: `${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER}${DOMAIN_ACCOUNT_ID}`,
}),
]),
}),
);
});
});
18 changes: 18 additions & 0 deletions tests/unit/CardUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {
getDisplayableExpensifyCards,
getDisplayableThirdPartyCards,
getDomainByFundID,
getDomainOrWorkspaceAccountID,
getEligibleBankAccountsForCard,
getEligibleBankAccountsForUkEuCard,
getFeedNameForDisplay,
Expand Down Expand Up @@ -1412,6 +1413,23 @@ describe('CardUtils', () => {
});
});

describe('getDomainOrWorkspaceAccountID', () => {
it('Should return the domain account that owns a domain feed', () => {
const accountID = getDomainOrWorkspaceAccountID(7654321, {domainID: 1234567});
expect(accountID).toBe(1234567);
});

it('Should return the workspace account when the feed has no domain', () => {
const accountID = getDomainOrWorkspaceAccountID(7654321, {});
expect(accountID).toBe(7654321);
});

it('Should return the workspace account when there is no feed data', () => {
const accountID = getDomainOrWorkspaceAccountID(7654321, undefined);
expect(accountID).toBe(7654321);
});
});

describe('getCustomOrFormattedFeedName', () => {
beforeAll(() => {
IntlStore.load(CONST.LOCALES.EN);
Expand Down
Loading