Skip to content

Commit efcfc8d

Browse files
authored
Merge pull request #61343 from DylanDylann/update-domainaccountID
[Internal QA]: Update domainAccountID
2 parents 32f5371 + 228a39d commit efcfc8d

File tree

4 files changed

+144
-4
lines changed

4 files changed

+144
-4
lines changed

src/libs/API/parameters/OpenPolicyCompanyCardsFeedParams.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
type OpenPolicyCompanyCardsFeedParams = {
2+
domainAccountID?: number;
23
policyID: string;
34
feed: string;
45
};

src/libs/actions/CompanyCards.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,8 +744,9 @@ function openPolicyCompanyCardsPage(policyID: string, workspaceAccountID: number
744744
API.read(READ_COMMANDS.OPEN_POLICY_COMPANY_CARDS_PAGE, params, {optimisticData, successData, failureData});
745745
}
746746

747-
function openPolicyCompanyCardsFeed(policyID: string, feed: CompanyCardFeed) {
747+
function openPolicyCompanyCardsFeed(domainAccountID: number, policyID: string, feed: CompanyCardFeed) {
748748
const parameters: OpenPolicyCompanyCardsFeedParams = {
749+
domainAccountID,
749750
policyID,
750751
feed,
751752
};

src/pages/workspace/companyCards/WorkspaceCompanyCardsPage.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import DecisionModal from '@components/DecisionModal';
55
import DelegateNoAccessModal from '@components/DelegateNoAccessModal';
66
import * as Illustrations from '@components/Icon/Illustrations';
77
import useCardFeeds from '@hooks/useCardFeeds';
8+
import useDefaultFundID from '@hooks/useDefaultFundID';
89
import useLocalize from '@hooks/useLocalize';
910
import useNetwork from '@hooks/useNetwork';
1011
import useResponsiveLayout from '@hooks/useResponsiveLayout';
@@ -75,6 +76,8 @@ function WorkspaceCompanyCardsPage({route}: WorkspaceCompanyCardsPageProps) {
7576
const {isOffline} = useNetwork({onReconnect: fetchCompanyCards});
7677
const isLoading = !isOffline && (!cardFeeds || (!!cardFeeds.isLoading && isEmptyObject(cardsList)));
7778

79+
const defaultFundID = useDefaultFundID(policyID);
80+
7881
useEffect(() => {
7982
fetchCompanyCards();
8083
}, [fetchCompanyCards]);
@@ -84,8 +87,8 @@ function WorkspaceCompanyCardsPage({route}: WorkspaceCompanyCardsPageProps) {
8487
return;
8588
}
8689

87-
openPolicyCompanyCardsFeed(policyID, selectedFeed);
88-
}, [selectedFeed, isLoading, policyID, isPending]);
90+
openPolicyCompanyCardsFeed(defaultFundID, policyID, selectedFeed);
91+
}, [selectedFeed, isLoading, policyID, isPending, defaultFundID]);
8992

9093
const handleAssignCard = () => {
9194
if (isActingAsDelegate) {

tests/unit/CardUtilsTest.ts

Lines changed: 136 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ import {
2222
isExpensifyCardFullySetUp,
2323
lastFourNumbersFromCardName,
2424
maskCardNumber,
25+
sortCardsByCardholderName,
2526
} from '@src/libs/CardUtils';
26-
import type {CardFeeds, CardList, CompanyCardFeed, ExpensifyCardSettings, Policy, WorkspaceCardsList} from '@src/types/onyx';
27+
import type {CardFeeds, CardList, CompanyCardFeed, ExpensifyCardSettings, PersonalDetailsList, Policy, WorkspaceCardsList} from '@src/types/onyx';
2728
import type {CompanyCardFeedWithNumber} from '@src/types/onyx/CardFeeds';
2829

2930
const shortDate = '0924';
@@ -857,4 +858,138 @@ describe('CardUtils', () => {
857858
expect(cards).toEqual({});
858859
});
859860
});
861+
862+
describe('sortCardsByCardholderName', () => {
863+
const mockPersonalDetails: PersonalDetailsList = {
864+
1: {
865+
accountID: 1,
866+
867+
displayName: 'John Doe',
868+
firstName: 'John',
869+
lastName: 'Doe',
870+
},
871+
2: {
872+
accountID: 2,
873+
874+
displayName: 'Jane Smith',
875+
firstName: 'Jane',
876+
lastName: 'Smith',
877+
},
878+
3: {
879+
accountID: 3,
880+
881+
// No displayName or firstName/lastName
882+
},
883+
};
884+
885+
const mockCards: WorkspaceCardsList = {
886+
'1': {
887+
cardID: 1,
888+
accountID: 1,
889+
cardName: 'Card 1',
890+
bank: 'expensify',
891+
domainName: 'expensify-policya7f617b9fe23d2f1.exfy',
892+
fraud: 'none',
893+
lastFourPAN: '',
894+
lastScrape: '',
895+
lastUpdated: '',
896+
state: 2,
897+
},
898+
'2': {
899+
cardID: 2,
900+
accountID: 2,
901+
bank: 'expensify',
902+
cardName: 'Card 2',
903+
domainName: 'expensify-policya7f617b9fe23d2f1.exfy',
904+
fraud: 'none',
905+
lastFourPAN: '',
906+
lastScrape: '',
907+
lastUpdated: '',
908+
state: 2,
909+
},
910+
'3': {
911+
cardID: 3,
912+
accountID: 3,
913+
bank: 'expensify',
914+
cardName: 'Card 3',
915+
domainName: 'expensify-policya7f617b9fe23d2f1.exfy',
916+
fraud: 'none',
917+
lastFourPAN: '',
918+
lastScrape: '',
919+
lastUpdated: '',
920+
state: 2,
921+
},
922+
};
923+
924+
it('should sort cards by cardholder name in ascending order', () => {
925+
const policyMembersAccountIDs = [1, 2, 3];
926+
const sortedCards = sortCardsByCardholderName(mockCards, mockPersonalDetails, policyMembersAccountIDs);
927+
928+
expect(sortedCards).toHaveLength(3);
929+
expect(sortedCards.at(0)?.cardID).toBe(2);
930+
expect(sortedCards.at(1)?.cardID).toBe(1);
931+
expect(sortedCards.at(2)?.cardID).toBe(3);
932+
});
933+
934+
it('should filter out cards that are not associated with policy members', () => {
935+
const policyMembersAccountIDs = [1, 2]; // Exclude accountID 3
936+
const sortedCards = sortCardsByCardholderName(mockCards, mockPersonalDetails, policyMembersAccountIDs);
937+
938+
expect(sortedCards).toHaveLength(2);
939+
expect(sortedCards.at(0)?.cardID).toBe(2);
940+
expect(sortedCards.at(1)?.cardID).toBe(1);
941+
});
942+
943+
it('should handle undefined cardsList', () => {
944+
const policyMembersAccountIDs = [1, 2, 3];
945+
const sortedCards = sortCardsByCardholderName(undefined, mockPersonalDetails, policyMembersAccountIDs);
946+
947+
expect(sortedCards).toHaveLength(0);
948+
});
949+
950+
it('should handle undefined personalDetails', () => {
951+
const policyMembersAccountIDs = [1, 2, 3];
952+
const sortedCards = sortCardsByCardholderName(mockCards, undefined, policyMembersAccountIDs);
953+
954+
expect(sortedCards).toHaveLength(3);
955+
// All cards should be sorted with default names
956+
expect(sortedCards.at(0)?.cardID).toBe(1);
957+
expect(sortedCards.at(1)?.cardID).toBe(2);
958+
expect(sortedCards.at(2)?.cardID).toBe(3);
959+
});
960+
961+
it('should handle cards with missing accountID', () => {
962+
const cardsWithMissingAccountID: WorkspaceCardsList = {
963+
'1': {
964+
cardID: 1,
965+
accountID: 1,
966+
cardName: 'Card 1',
967+
bank: 'expensify',
968+
domainName: 'expensify-policya7f617b9fe23d2f1.exfy',
969+
fraud: 'none',
970+
lastFourPAN: '',
971+
lastScrape: '',
972+
lastUpdated: '',
973+
state: 2,
974+
},
975+
'2': {
976+
cardID: 2,
977+
cardName: 'Card 2',
978+
bank: 'expensify',
979+
domainName: 'expensify-policya7f617b9fe23d2f1.exfy',
980+
fraud: 'none',
981+
lastFourPAN: '',
982+
lastScrape: '',
983+
lastUpdated: '',
984+
state: 2,
985+
},
986+
};
987+
988+
const policyMembersAccountIDs = [1, 2];
989+
const sortedCards = sortCardsByCardholderName(cardsWithMissingAccountID, mockPersonalDetails, policyMembersAccountIDs);
990+
991+
expect(sortedCards).toHaveLength(1);
992+
expect(sortedCards.at(0)?.cardID).toBe(1);
993+
});
994+
});
860995
});

0 commit comments

Comments
 (0)