Skip to content
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
4 changes: 3 additions & 1 deletion src/libs/actions/CompanyCards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ function buildOptimisticCompanyCardCSVTransactions(
const externalIDColumnIndex = isExternalIDColumnMapped ? mappedExternalIDColumnIndex : normalizedColumnMappings.length - 1;

const cardNumberColumnIndex = getColumnIndex(normalizedColumnMappings, CONST.CSV_IMPORT_COLUMNS.CARD_NUMBER);
const cardNameColumnIndex = getColumnIndex(normalizedColumnMappings, CONST.CSV_IMPORT_COLUMNS.CARD_NAME);
const cardIdentityColumnIndex = cardNumberColumnIndex >= 0 ? cardNumberColumnIndex : cardNameColumnIndex;
const postedDateColumnIndex = getColumnIndex(normalizedColumnMappings, CONST.CSV_IMPORT_COLUMNS.POSTED_DATE);
const originalTransactionDateColumnIndex = getColumnIndex(normalizedColumnMappings, CONST.CSV_IMPORT_COLUMNS.ORIGINAL_TRANSACTION_DATE);
const merchantColumnIndex = getColumnIndex(normalizedColumnMappings, CONST.CSV_IMPORT_COLUMNS.MERCHANT);
Expand All @@ -137,7 +139,7 @@ function buildOptimisticCompanyCardCSVTransactions(
row[externalIDColumnIndex] = transactionID;
}

const cardName = row.at(cardNumberColumnIndex)?.trim();
const cardName = cardIdentityColumnIndex >= 0 ? row.at(cardIdentityColumnIndex)?.trim() : undefined;
const rawPostedDate = row.at(postedDateColumnIndex)?.trim();
const created = rawPostedDate ? parseCSVDate(rawPostedDate) : null;
const merchant = row.at(merchantColumnIndex)?.trim() ?? '';
Expand Down
38 changes: 38 additions & 0 deletions tests/actions/CompanyCardsImportTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,44 @@ describe('actions/CompanyCards importCSVCompanyCards', () => {
apiWriteSpy.mockRestore();
});

it('counts every row that has a card identity when the Card number column is not mapped', () => {
// Given an import that maps Card name (not Card number) plus a mapped Unique ID and a trailing optional column
const apiWriteSpy = jest.spyOn(require('@libs/API'), 'write').mockImplementation(() => Promise.resolve());

// When rows leave that trailing optional column empty
importCSVCompanyCards({
policyID: POLICY_ID,
domainAccountID: DOMAIN_ACCOUNT_ID,
layoutName: 'My Layout',
layoutType: CSV_FEED,
columnMappings: ['externalID', 'cardName', 'postedDate', 'merchant', 'amount', 'currency', 'tag'],
csvData: [
['Unique ID', 'Card Name', 'Date', 'Merchant', 'Amount', 'Currency', 'Tag'],
['txn-1', 'Finance Card', '08/05/2026', 'Coffee Shop', '-6.25', 'USD', ''],
['txn-2', 'Finance Card', '08/06/2026', 'Book Store', '-14.00', 'USD', ''],
['txn-3', 'Travel Card', '08/07/2026', 'Grocery Mart', '-28.40', 'USD', 'Travel'],
],
workspaceCardFeeds: undefined,
});

// Then all three rows are counted, because the card identity comes from Card name rather than the last cell in the row
expect(apiWriteSpy).toHaveBeenCalledWith(
WRITE_COMMANDS.IMPORT_CSV_COMPANY_CARDS,
expect.anything(),
expect.objectContaining({
successData: [
expect.objectContaining({
value: expect.objectContaining({
importFinalModal: expect.objectContaining({promptKeyParams: {count: 3}}),
}),
}),
],
}),
);

apiWriteSpy.mockRestore();
});

describe('externalID', () => {
const sentImports: ImportCSVCompanyCardsParams[] = [];

Expand Down
Loading