Skip to content

[Internal QA]: Update domainAccountID #61343

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 5, 2025
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
type OpenPolicyCompanyCardsFeedParams = {
domainAccountID?: number;
policyID: string;
feed: string;
};
Expand Down
3 changes: 2 additions & 1 deletion src/libs/actions/CompanyCards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -744,8 +744,9 @@ function openPolicyCompanyCardsPage(policyID: string, workspaceAccountID: number
API.read(READ_COMMANDS.OPEN_POLICY_COMPANY_CARDS_PAGE, params, {optimisticData, successData, failureData});
}

function openPolicyCompanyCardsFeed(policyID: string, feed: CompanyCardFeed) {
function openPolicyCompanyCardsFeed(domainAccountID: number, policyID: string, feed: CompanyCardFeed) {
const parameters: OpenPolicyCompanyCardsFeedParams = {
domainAccountID,
policyID,
feed,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import DecisionModal from '@components/DecisionModal';
import DelegateNoAccessModal from '@components/DelegateNoAccessModal';
import * as Illustrations from '@components/Icon/Illustrations';
import useCardFeeds from '@hooks/useCardFeeds';
import useDefaultFundID from '@hooks/useDefaultFundID';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
Expand Down Expand Up @@ -75,6 +76,8 @@ function WorkspaceCompanyCardsPage({route}: WorkspaceCompanyCardsPageProps) {
const {isOffline} = useNetwork({onReconnect: fetchCompanyCards});
const isLoading = !isOffline && (!cardFeeds || (!!cardFeeds.isLoading && isEmptyObject(cardsList)));

const defaultFundID = useDefaultFundID(policyID);

useEffect(() => {
fetchCompanyCards();
}, [fetchCompanyCards]);
Expand All @@ -84,8 +87,8 @@ function WorkspaceCompanyCardsPage({route}: WorkspaceCompanyCardsPageProps) {
return;
}

openPolicyCompanyCardsFeed(policyID, selectedFeed);
}, [selectedFeed, isLoading, policyID, isPending]);
openPolicyCompanyCardsFeed(defaultFundID, policyID, selectedFeed);
}, [selectedFeed, isLoading, policyID, isPending, defaultFundID]);

const handleAssignCard = () => {
if (isActingAsDelegate) {
Expand Down
137 changes: 136 additions & 1 deletion tests/unit/CardUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ import {
isExpensifyCardFullySetUp,
lastFourNumbersFromCardName,
maskCardNumber,
sortCardsByCardholderName,
} from '@src/libs/CardUtils';
import type {CardFeeds, CardList, CompanyCardFeed, ExpensifyCardSettings, Policy, WorkspaceCardsList} from '@src/types/onyx';
import type {CardFeeds, CardList, CompanyCardFeed, ExpensifyCardSettings, PersonalDetailsList, Policy, WorkspaceCardsList} from '@src/types/onyx';
import type {CompanyCardFeedWithNumber} from '@src/types/onyx/CardFeeds';

const shortDate = '0924';
Expand Down Expand Up @@ -857,4 +858,138 @@ describe('CardUtils', () => {
expect(cards).toEqual({});
});
});

describe('sortCardsByCardholderName', () => {
const mockPersonalDetails: PersonalDetailsList = {
1: {
accountID: 1,
login: '[email protected]',
displayName: 'John Doe',
firstName: 'John',
lastName: 'Doe',
},
2: {
accountID: 2,
login: '[email protected]',
displayName: 'Jane Smith',
firstName: 'Jane',
lastName: 'Smith',
},
3: {
accountID: 3,
login: '[email protected]',
// No displayName or firstName/lastName
},
};

const mockCards: WorkspaceCardsList = {
'1': {
cardID: 1,
accountID: 1,
cardName: 'Card 1',
bank: 'expensify',
domainName: 'expensify-policya7f617b9fe23d2f1.exfy',
fraud: 'none',
lastFourPAN: '',
lastScrape: '',
lastUpdated: '',
state: 2,
},
'2': {
cardID: 2,
accountID: 2,
bank: 'expensify',
cardName: 'Card 2',
domainName: 'expensify-policya7f617b9fe23d2f1.exfy',
fraud: 'none',
lastFourPAN: '',
lastScrape: '',
lastUpdated: '',
state: 2,
},
'3': {
cardID: 3,
accountID: 3,
bank: 'expensify',
cardName: 'Card 3',
domainName: 'expensify-policya7f617b9fe23d2f1.exfy',
fraud: 'none',
lastFourPAN: '',
lastScrape: '',
lastUpdated: '',
state: 2,
},
};

it('should sort cards by cardholder name in ascending order', () => {
const policyMembersAccountIDs = [1, 2, 3];
const sortedCards = sortCardsByCardholderName(mockCards, mockPersonalDetails, policyMembersAccountIDs);

expect(sortedCards).toHaveLength(3);
expect(sortedCards.at(0)?.cardID).toBe(2);
expect(sortedCards.at(1)?.cardID).toBe(1);
expect(sortedCards.at(2)?.cardID).toBe(3);
});

it('should filter out cards that are not associated with policy members', () => {
const policyMembersAccountIDs = [1, 2]; // Exclude accountID 3
const sortedCards = sortCardsByCardholderName(mockCards, mockPersonalDetails, policyMembersAccountIDs);

expect(sortedCards).toHaveLength(2);
expect(sortedCards.at(0)?.cardID).toBe(2);
expect(sortedCards.at(1)?.cardID).toBe(1);
});

it('should handle undefined cardsList', () => {
const policyMembersAccountIDs = [1, 2, 3];
const sortedCards = sortCardsByCardholderName(undefined, mockPersonalDetails, policyMembersAccountIDs);

expect(sortedCards).toHaveLength(0);
});

it('should handle undefined personalDetails', () => {
const policyMembersAccountIDs = [1, 2, 3];
const sortedCards = sortCardsByCardholderName(mockCards, undefined, policyMembersAccountIDs);

expect(sortedCards).toHaveLength(3);
// All cards should be sorted with default names
expect(sortedCards.at(0)?.cardID).toBe(1);
expect(sortedCards.at(1)?.cardID).toBe(2);
expect(sortedCards.at(2)?.cardID).toBe(3);
});

it('should handle cards with missing accountID', () => {
const cardsWithMissingAccountID: WorkspaceCardsList = {
'1': {
cardID: 1,
accountID: 1,
cardName: 'Card 1',
bank: 'expensify',
domainName: 'expensify-policya7f617b9fe23d2f1.exfy',
fraud: 'none',
lastFourPAN: '',
lastScrape: '',
lastUpdated: '',
state: 2,
},
'2': {
cardID: 2,
cardName: 'Card 2',
bank: 'expensify',
domainName: 'expensify-policya7f617b9fe23d2f1.exfy',
fraud: 'none',
lastFourPAN: '',
lastScrape: '',
lastUpdated: '',
state: 2,
},
};

const policyMembersAccountIDs = [1, 2];
const sortedCards = sortCardsByCardholderName(cardsWithMissingAccountID, mockPersonalDetails, policyMembersAccountIDs);

expect(sortedCards).toHaveLength(1);
expect(sortedCards.at(0)?.cardID).toBe(1);
});
});
});