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
20 changes: 1 addition & 19 deletions src/libs/TravelInvoicingUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,8 @@ import type {BankAccountList, Card, CardList} from '@src/types/onyx';
import type {ExpensifyCardSettingsBase} from '@src/types/onyx/ExpensifyCardSettings';
import addEncryptedAuthTokenToURL from './addEncryptedAuthTokenToURL';
import {getLastFourDigits} from './BankAccountUtils';
import {isDevelopment, isInternalTestBuild, isStaging} from './Environment/Environment';
import fileDownload from './fileDownload';

/**
* Feature flag to enable Travel CVV testing on Dev and Staging environments.
* When enabled, it allows using any card for CVV reveal testing if no specific Travel Card is found.
*
* TODO: Remove this function and associated logic when Travel Invoicing is fully released
*/
function isTravelCVVTestingEnabled(): boolean {
return isDevelopment() || isStaging() || isInternalTestBuild();
}

/**
* Checks whether Travel Invoicing is enabled based on the card settings.
* Returns true if:
Expand Down Expand Up @@ -171,13 +160,7 @@ function getTravelInvoicingCard(cardList: OnyxEntry<CardList>) {
}

const allCards = Object.values(cardList).filter((card): card is Card => !!card && typeof card?.cardID === 'number');
const travelCard = allCards.find((card) => card.nameValuePairs?.feedCountry === CONST.TRAVEL.PROGRAM_TRAVEL_US);
// If no travel card is found and testing is enabled, return the first available card
if (!travelCard && isTravelCVVTestingEnabled()) {
return allCards.find((card) => card.bank === CONST.EXPENSIFY_CARD.BANK);
}

return travelCard;
return allCards.find((card) => card.nameValuePairs?.feedCountry === CONST.TRAVEL.PROGRAM_TRAVEL_US);
}

/**
Expand All @@ -201,7 +184,6 @@ export {
downloadTravelInvoiceStatementPDF,
getTravelInvoicingCard,
isTravelCVVEligible,
isTravelCVVTestingEnabled,
};

export type {TravelSettlementAccountInfo};
50 changes: 0 additions & 50 deletions tests/unit/TravelInvoicingUtilsTest.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import CONST from '@src/CONST';
// Needed for testing usage with jest.spyOn
// eslint-disable-next-line no-restricted-imports
import * as Environment from '@src/libs/Environment/Environment';
import {
getIsTravelInvoicingEnabled,
getTravelInvoicingCard,
Expand All @@ -15,28 +12,7 @@ import {
import type {BankAccountList, CardList} from '@src/types/onyx';
import type {ExpensifyCardSettingsBase} from '@src/types/onyx/ExpensifyCardSettings';

jest.mock('@src/libs/Environment/Environment', () => ({
getEnvironmentURL: jest.fn(() => Promise.resolve('https://new.expensify.com')),
getOldDotEnvironmentURL: jest.fn(() => Promise.resolve('https://www.expensify.com')),
isDevelopment: jest.fn(() => false),
isInternalTestBuild: jest.fn(() => false),
isStaging: jest.fn(() => false),
}));

describe('TravelInvoicingUtils', () => {
let isDevelopmentSpy: jest.SpyInstance;
let isInternalTestBuildSpy: jest.SpyInstance;

beforeAll(() => {
isDevelopmentSpy = jest.spyOn(Environment, 'isDevelopment').mockReturnValue(false);
isInternalTestBuildSpy = jest.spyOn(Environment, 'isInternalTestBuild').mockReturnValue(false);
});

afterEach(() => {
isDevelopmentSpy.mockReturnValue(false);
isInternalTestBuildSpy.mockReturnValue(false);
jest.clearAllMocks();
});
describe('PROGRAM_TRAVEL_US constant', () => {
it('Should be defined as TRAVEL_US', () => {
expect(CONST.TRAVEL.PROGRAM_TRAVEL_US).toBe('TRAVEL_US');
Expand Down Expand Up @@ -298,26 +274,6 @@ describe('TravelInvoicingUtils', () => {
expect(result).toBeDefined();
expect(result?.nameValuePairs?.feedCountry).toBe(CONST.TRAVEL.PROGRAM_TRAVEL_US);
});
it('Should fallback to first available card when testing is enabled and no travel card exists', () => {
isDevelopmentSpy.mockReturnValue(true);

const cardList = {
// eslint-disable-next-line @typescript-eslint/naming-convention
'9999': {
cardID: 9999,
state: 3,
bank: 'Expensify Card',
nameValuePairs: {
isVirtual: true,
feedCountry: 'OTHER_COUNTRY',
},
},
} as unknown as CardList;

const result = getTravelInvoicingCard(cardList);
expect(result).toBeDefined();
expect(result?.cardID).toBe(9999);
});
});

describe('isTravelCVVEligible', () => {
Expand Down Expand Up @@ -370,11 +326,5 @@ describe('TravelInvoicingUtils', () => {
const result = isTravelCVVEligible(true, mockTravelCardList);
expect(result).toBe(true);
});

it('Should return true when testing is enabled and beta is true even if no travel card exists', () => {
isDevelopmentSpy.mockReturnValue(true);
const result = isTravelCVVEligible(true, mockNonTravelCardList);
expect(result).toBe(true);
});
});
});
Loading