Skip to content
Merged
12 changes: 9 additions & 3 deletions src/libs/actions/IOU/MoneyRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import CONST from '@src/CONST';
import type {TranslationParameters, TranslationPaths} from '@src/languages/types';
import type {Route} from '@src/ROUTES';
import ROUTES from '@src/ROUTES';
import type {Beta, IntroSelected, LastSelectedDistanceRates, PersonalDetailsList, Policy, QuickAction, Report, Transaction, TransactionViolation} from '@src/types/onyx';
import type {Beta, IntroSelected, LastSelectedDistanceRates, PersonalDetailsList, Policy, QuickAction, RecentWaypoint, Report, Transaction, TransactionViolation} from '@src/types/onyx';
import type {ReportAttributes, ReportAttributesDerivedValue} from '@src/types/onyx/DerivedValues';
import type {Participant} from '@src/types/onyx/IOU';
import type {Unit} from '@src/types/onyx/Policy';
Expand Down Expand Up @@ -62,6 +62,7 @@ type CreateTransactionParams = {
isSelfTourViewed: boolean;
betas: OnyxEntry<Beta[]>;
personalDetails: OnyxEntry<PersonalDetailsList>;
recentWaypoints: OnyxEntry<RecentWaypoint[]>;
};

type InitialTransactionParams = {
Expand Down Expand Up @@ -173,9 +174,8 @@ function createTransaction({
isSelfTourViewed,
betas,
personalDetails,
recentWaypoints,
}: CreateTransactionParams) {
const recentWaypoints = getRecentWaypoints();

for (const [index, receiptFile] of files.entries()) {
const transaction = transactions.find((item) => item.transactionID === receiptFile.transactionID);
const receipt: Receipt = receiptFile.file ?? {};
Expand Down Expand Up @@ -376,6 +376,7 @@ function handleMoneyRequestStepScanParticipants({
lat: successData.coords.latitude,
long: successData.coords.longitude,
};
const recentWaypoints = getRecentWaypoints();
createTransaction({
transactions,
iouType,
Expand All @@ -399,11 +400,13 @@ function handleMoneyRequestStepScanParticipants({
isSelfTourViewed,
betas,
personalDetails,
recentWaypoints,
});
},
(errorData) => {
Log.info('[IOURequestStepScan] getCurrentPosition failed', false, errorData);
// When there is an error, the money can still be requested, it just won't include the GPS coordinates
const recentWaypoints = getRecentWaypoints();
createTransaction({
transactions,
iouType,
Expand All @@ -424,11 +427,13 @@ function handleMoneyRequestStepScanParticipants({
isSelfTourViewed,
betas,
personalDetails,
recentWaypoints,
});
},
);
return;
}
const recentWaypoints = getRecentWaypoints();
createTransaction({
transactions,
iouType,
Expand All @@ -449,6 +454,7 @@ function handleMoneyRequestStepScanParticipants({
isSelfTourViewed,
betas,
personalDetails,
recentWaypoints,
});
return;
}
Expand Down
42 changes: 41 additions & 1 deletion tests/actions/IOU/MoneyRequestTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type {ReceiptFile} from '@pages/iou/request/step/IOURequestStepScan/types
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {QuickAction} from '@src/types/onyx';
import type {QuickAction, RecentWaypoint} from '@src/types/onyx';
import type {SplitShares} from '@src/types/onyx/Transaction';
import * as IOU from '../../../src/libs/actions/IOU';
import * as Split from '../../../src/libs/actions/IOU/Split';
Expand Down Expand Up @@ -95,8 +95,13 @@ describe('MoneyRequest', () => {
isSelfTourViewed: false,
betas: [CONST.BETAS.ALL],
personalDetails: {},
recentWaypoints: [] as RecentWaypoint[],
};

beforeEach(async () => {
baseParams.recentWaypoints = (await getOnyxValue(ONYXKEYS.NVP_RECENT_WAYPOINTS)) ?? [];
});

afterEach(() => {
jest.clearAllMocks();
});
Expand Down Expand Up @@ -248,6 +253,41 @@ describe('MoneyRequest', () => {
}),
);
});

it('should pass billable and reimbursable flags to trackExpense', () => {
createTransaction({
...baseParams,
iouType: CONST.IOU.TYPE.TRACK,
billable: true,
reimbursable: false,
});

expect(IOU.trackExpense).toHaveBeenCalledWith(
expect.objectContaining({
transactionParams: expect.objectContaining({
billable: true,
reimbursable: false,
}),
}),
);
});

it('should pass gpsPoint to trackExpense when provided', () => {
const gpsPoint = {lat: TEST_LATITUDE, long: TEST_LONGITUDE};
createTransaction({
...baseParams,
iouType: CONST.IOU.TYPE.TRACK,
gpsPoint,
});

expect(IOU.trackExpense).toHaveBeenCalledWith(
expect.objectContaining({
transactionParams: expect.objectContaining({
gpsPoint,
}),
}),
);
});
});

describe('handleMoneyRequestStepScanParticipants', () => {
Expand Down
Loading