Skip to content

Commit 4eb171c

Browse files
authored
Merge pull request Expensify#82548 from software-mansion-labs/Guccio163/onyx-connect/nvp_recent_waypoints/createTransaction
2 parents 859ea74 + 43b1112 commit 4eb171c

2 files changed

Lines changed: 50 additions & 4 deletions

File tree

src/libs/actions/IOU/MoneyRequest.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import CONST from '@src/CONST';
1717
import type {TranslationParameters, TranslationPaths} from '@src/languages/types';
1818
import type {Route} from '@src/ROUTES';
1919
import ROUTES from '@src/ROUTES';
20-
import type {Beta, IntroSelected, LastSelectedDistanceRates, PersonalDetailsList, Policy, QuickAction, Report, Transaction, TransactionViolation} from '@src/types/onyx';
20+
import type {Beta, IntroSelected, LastSelectedDistanceRates, PersonalDetailsList, Policy, QuickAction, RecentWaypoint, Report, Transaction, TransactionViolation} from '@src/types/onyx';
2121
import type {ReportAttributes, ReportAttributesDerivedValue} from '@src/types/onyx/DerivedValues';
2222
import type {Participant} from '@src/types/onyx/IOU';
2323
import type {Unit} from '@src/types/onyx/Policy';
@@ -62,6 +62,7 @@ type CreateTransactionParams = {
6262
isSelfTourViewed: boolean;
6363
betas: OnyxEntry<Beta[]>;
6464
personalDetails: OnyxEntry<PersonalDetailsList>;
65+
recentWaypoints: OnyxEntry<RecentWaypoint[]>;
6566
};
6667

6768
type InitialTransactionParams = {
@@ -173,9 +174,8 @@ function createTransaction({
173174
isSelfTourViewed,
174175
betas,
175176
personalDetails,
177+
recentWaypoints,
176178
}: CreateTransactionParams) {
177-
const recentWaypoints = getRecentWaypoints();
178-
179179
for (const [index, receiptFile] of files.entries()) {
180180
const transaction = transactions.find((item) => item.transactionID === receiptFile.transactionID);
181181
const receipt: Receipt = receiptFile.file ?? {};
@@ -376,6 +376,7 @@ function handleMoneyRequestStepScanParticipants({
376376
lat: successData.coords.latitude,
377377
long: successData.coords.longitude,
378378
};
379+
const recentWaypoints = getRecentWaypoints();
379380
createTransaction({
380381
transactions,
381382
iouType,
@@ -399,11 +400,13 @@ function handleMoneyRequestStepScanParticipants({
399400
isSelfTourViewed,
400401
betas,
401402
personalDetails,
403+
recentWaypoints,
402404
});
403405
},
404406
(errorData) => {
405407
Log.info('[IOURequestStepScan] getCurrentPosition failed', false, errorData);
406408
// When there is an error, the money can still be requested, it just won't include the GPS coordinates
409+
const recentWaypoints = getRecentWaypoints();
407410
createTransaction({
408411
transactions,
409412
iouType,
@@ -424,11 +427,13 @@ function handleMoneyRequestStepScanParticipants({
424427
isSelfTourViewed,
425428
betas,
426429
personalDetails,
430+
recentWaypoints,
427431
});
428432
},
429433
);
430434
return;
431435
}
436+
const recentWaypoints = getRecentWaypoints();
432437
createTransaction({
433438
transactions,
434439
iouType,
@@ -449,6 +454,7 @@ function handleMoneyRequestStepScanParticipants({
449454
isSelfTourViewed,
450455
betas,
451456
personalDetails,
457+
recentWaypoints,
452458
});
453459
return;
454460
}

tests/actions/IOU/MoneyRequestTest.ts

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type {ReceiptFile} from '@pages/iou/request/step/IOURequestStepScan/types
99
import CONST from '@src/CONST';
1010
import ONYXKEYS from '@src/ONYXKEYS';
1111
import ROUTES from '@src/ROUTES';
12-
import type {QuickAction} from '@src/types/onyx';
12+
import type {QuickAction, RecentWaypoint} from '@src/types/onyx';
1313
import type {SplitShares} from '@src/types/onyx/Transaction';
1414
import * as IOU from '../../../src/libs/actions/IOU';
1515
import * as Split from '../../../src/libs/actions/IOU/Split';
@@ -95,8 +95,13 @@ describe('MoneyRequest', () => {
9595
isSelfTourViewed: false,
9696
betas: [CONST.BETAS.ALL],
9797
personalDetails: {},
98+
recentWaypoints: [] as RecentWaypoint[],
9899
};
99100

101+
beforeEach(async () => {
102+
baseParams.recentWaypoints = (await getOnyxValue(ONYXKEYS.NVP_RECENT_WAYPOINTS)) ?? [];
103+
});
104+
100105
afterEach(() => {
101106
jest.clearAllMocks();
102107
});
@@ -248,6 +253,41 @@ describe('MoneyRequest', () => {
248253
}),
249254
);
250255
});
256+
257+
it('should pass billable and reimbursable flags to trackExpense', () => {
258+
createTransaction({
259+
...baseParams,
260+
iouType: CONST.IOU.TYPE.TRACK,
261+
billable: true,
262+
reimbursable: false,
263+
});
264+
265+
expect(IOU.trackExpense).toHaveBeenCalledWith(
266+
expect.objectContaining({
267+
transactionParams: expect.objectContaining({
268+
billable: true,
269+
reimbursable: false,
270+
}),
271+
}),
272+
);
273+
});
274+
275+
it('should pass gpsPoint to trackExpense when provided', () => {
276+
const gpsPoint = {lat: TEST_LATITUDE, long: TEST_LONGITUDE};
277+
createTransaction({
278+
...baseParams,
279+
iouType: CONST.IOU.TYPE.TRACK,
280+
gpsPoint,
281+
});
282+
283+
expect(IOU.trackExpense).toHaveBeenCalledWith(
284+
expect.objectContaining({
285+
transactionParams: expect.objectContaining({
286+
gpsPoint,
287+
}),
288+
}),
289+
);
290+
});
251291
});
252292

253293
describe('handleMoneyRequestStepScanParticipants', () => {

0 commit comments

Comments
 (0)