Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions tests/unit/CardUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
getDefaultExpensifyCardLimitType,
getDisplayableExpensifyCards,
getDisplayableThirdPartyCards,
getDomainByFundID,
getEligibleBankAccountsForCard,
getEligibleBankAccountsForUkEuCard,
getFeedConnectionBrokenCard,
Expand Down Expand Up @@ -75,13 +76,15 @@ import {
} from '@src/libs/CardUtils';
import type {CardProgramKey} from '@src/libs/CardUtils';
import DateUtils from '@src/libs/DateUtils';
import ONYXKEYS from '@src/ONYXKEYS';
import type {
BankAccountList,
Card,
CardFeeds,
CardList,
CompanyCardFeed,
CompanyCardFeedWithDomainID,
Domain,
ExpensifyCardSettings,
PersonalDetailsList,
Policy,
Expand Down Expand Up @@ -4642,3 +4645,57 @@ describe('getCompanyCardCustomName', () => {
expect(getCompanyCardCustomName('9999', sharedCardCustomNames, customCardNames)).toBeUndefined();
});
});

describe('getDomainByFundID', () => {
const FUND_ID = 767578;

function makeDomain(accountID: number): Domain {
return createMock<Domain>({accountID});
}

it('resolves the domain keyed by `domain_<fundID>`', () => {
const domain = makeDomain(FUND_ID);
const domains: OnyxCollection<Domain> = {
[`${ONYXKEYS.COLLECTION.DOMAIN}${FUND_ID}`]: domain,
};
expect(getDomainByFundID(domains, FUND_ID)).toBe(domain);
});

it('falls back to a domain whose `accountID` matches the fund when it is not keyed by the fund ID', () => {
const domain = makeDomain(FUND_ID);
const domains: OnyxCollection<Domain> = {
[`${ONYXKEYS.COLLECTION.DOMAIN}1`]: domain,
};
expect(getDomainByFundID(domains, FUND_ID)).toBe(domain);
});

it('prefers the domain keyed by `domain_<fundID>` over one that only matches on `accountID`', () => {
const keyedDomain = makeDomain(999);
const accountIDMatch = makeDomain(FUND_ID);
const domains: OnyxCollection<Domain> = {
[`${ONYXKEYS.COLLECTION.DOMAIN}${FUND_ID}`]: keyedDomain,
[`${ONYXKEYS.COLLECTION.DOMAIN}1`]: accountIDMatch,
};
expect(getDomainByFundID(domains, FUND_ID)).toBe(keyedDomain);
});

it('returns undefined when `domains` is undefined', () => {
expect(getDomainByFundID(undefined, FUND_ID)).toBeUndefined();
});

it('returns undefined when no domain is keyed by or has an `accountID` matching the fund', () => {
const domains: OnyxCollection<Domain> = {
[`${ONYXKEYS.COLLECTION.DOMAIN}1`]: makeDomain(1),
};
expect(getDomainByFundID(domains, FUND_ID)).toBeUndefined();
});

it('ignores undefined entries when scanning for an `accountID` match', () => {
const domain = makeDomain(FUND_ID);
const domains: OnyxCollection<Domain> = {
[`${ONYXKEYS.COLLECTION.DOMAIN}1`]: undefined,
[`${ONYXKEYS.COLLECTION.DOMAIN}2`]: domain,
};
expect(getDomainByFundID(domains, FUND_ID)).toBe(domain);
});
});
Loading