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
1 change: 1 addition & 0 deletions src/components/ReportActionItem/MoneyRequestView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@ function MoneyRequestView({
currentUserEmailParam,
isASAPSubmitBetaEnabled,
parentReportNextStep,
isOffline,
});
};

Expand Down
6 changes: 6 additions & 0 deletions src/libs/actions/IOU/UpdateMoneyRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type UpdateMoneyRequestDateParams = {
currentUserEmailParam: string;
isASAPSubmitBetaEnabled: boolean;
parentReportNextStep: OnyxEntry<OnyxTypes.ReportNextStepDeprecated>;
isOffline: boolean;
};

/** Updates the created date of an expense */
Expand All @@ -88,6 +89,7 @@ function updateMoneyRequestDate({
currentUserEmailParam,
isASAPSubmitBetaEnabled,
parentReportNextStep,
isOffline,
}: UpdateMoneyRequestDateParams) {
const transactionChanges: TransactionChanges = {
created: value,
Expand All @@ -109,6 +111,7 @@ function updateMoneyRequestDate({
currentUserEmailParam,
isASAPSubmitBetaEnabled,
iouReportNextStep: parentReportNextStep,
isOffline,
});
removeTransactionFromDuplicateTransactionViolation(data.onyxData, transactionID, transactions, transactionViolations);
}
Expand All @@ -129,6 +132,7 @@ function updateMoneyRequestBillable({
currentUserEmailParam,
isASAPSubmitBetaEnabled,
parentReportNextStep,
isOffline,
}: {
transactionID: string | undefined;
transactionThreadReport: OnyxEntry<OnyxTypes.Report>;
Expand All @@ -141,6 +145,7 @@ function updateMoneyRequestBillable({
currentUserEmailParam: string;
isASAPSubmitBetaEnabled: boolean;
parentReportNextStep: OnyxEntry<OnyxTypes.ReportNextStepDeprecated>;
isOffline: boolean;
}) {
if (!transactionID || !transactionThreadReport?.reportID) {
return;
Expand All @@ -160,6 +165,7 @@ function updateMoneyRequestBillable({
currentUserEmailParam,
isASAPSubmitBetaEnabled,
iouReportNextStep: parentReportNextStep,
isOffline,
});
API.write(WRITE_COMMANDS.UPDATE_MONEY_REQUEST_BILLABLE, params, onyxData);
}
Expand Down
3 changes: 3 additions & 0 deletions src/pages/iou/request/step/IOURequestStepDate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {FormInputErrors, FormOnyxValues} from '@components/Form/types';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useDuplicateTransactionsAndViolations from '@hooks/useDuplicateTransactionsAndViolations';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useOnyx from '@hooks/useOnyx';
import usePermissions from '@hooks/usePermissions';
import usePolicy from '@hooks/usePolicy';
Expand Down Expand Up @@ -59,6 +60,7 @@ function IOURequestStepDate({
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
const {isBetaEnabled} = usePermissions();
const isASAPSubmitBetaEnabled = isBetaEnabled(CONST.BETAS.ASAP_SUBMIT);
const {isOffline} = useNetwork();
const isEditing = action === CONST.IOU.ACTION.EDIT;
const isSplitBill = iouType === CONST.IOU.TYPE.SPLIT;
const isSplitExpense = iouType === CONST.IOU.TYPE.SPLIT_EXPENSE;
Expand Down Expand Up @@ -108,6 +110,7 @@ function IOURequestStepDate({
currentUserEmailParam: currentUserPersonalDetails.login ?? '',
isASAPSubmitBetaEnabled,
parentReportNextStep,
isOffline,
});
}

Expand Down
155 changes: 155 additions & 0 deletions tests/actions/IOUTest/UpdateMoneyRequestTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import type {OnyxEntry} from 'react-native-onyx';
import {
updateMoneyRequestAmountAndCurrency,
updateMoneyRequestAttendees,
updateMoneyRequestBillable,
updateMoneyRequestCategory,
updateMoneyRequestDate,
updateMoneyRequestDistance,
updateMoneyRequestTag,
} from '@libs/actions/IOU/UpdateMoneyRequest';
Expand Down Expand Up @@ -728,6 +730,159 @@ describe('actions/IOU/UpdateMoneyRequest', () => {
});
});

describe('updateMoneyRequestDate', () => {
it('should update the transaction created date', async () => {
// Given an expense transaction with an expense report
const transactionID = 'txnDate1';
const transactionThreadReportID = 'threadDate1';
const parentReportID = 'parentDate1';
const policyID = '10';
const originalDate = '2026-01-01';
const newDate = '2026-01-15';

const parentReport: Report = {
...createRandomReport(1, undefined),
reportID: parentReportID,
type: CONST.REPORT.TYPE.EXPENSE,
policyID,
ownerAccountID: RORY_ACCOUNT_ID,
};
const transactionThreadReport: Report = {
...createRandomReport(2, undefined),
reportID: transactionThreadReportID,
parentReportID,
type: CONST.REPORT.TYPE.CHAT,
};
const fakeTransaction: Transaction = {
...createRandomTransaction(3),
transactionID,
reportID: parentReportID,
created: originalDate,
};
const fakePolicy: Policy = createRandomPolicy(Number(policyID));

await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${parentReportID}`, parentReport);
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`, transactionThreadReport);
await Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, fakeTransaction);
await Onyx.set(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, fakePolicy);

// When updating the date
updateMoneyRequestDate({
transactionID,
transactionThreadReport,
parentReport,
transactions: {[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`]: fakeTransaction},
transactionViolations: {},
value: newDate,
policy: fakePolicy,
policyTags: {},
policyCategories: {},
currentUserAccountIDParam: RORY_ACCOUNT_ID,
currentUserEmailParam: RORY_EMAIL,
isASAPSubmitBetaEnabled: false,
parentReportNextStep: undefined,
isOffline: false,
});

await waitForBatchedUpdates();

// Then the modified date on the transaction should be updated
const transactionAfter = await getOnyxValue(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`);
expect(transactionAfter?.modifiedCreated).toBe(newDate);
});
});

describe('updateMoneyRequestBillable', () => {
it('should update the transaction billable field', async () => {
// Given an expense transaction with billable = false
const transactionID = 'txnBillable1';
const transactionThreadReportID = 'threadBillable1';
const parentReportID = 'parentBillable1';
const policyID = '20';

const parentReport: Report = {
...createRandomReport(1, undefined),
reportID: parentReportID,
type: CONST.REPORT.TYPE.EXPENSE,
policyID,
ownerAccountID: RORY_ACCOUNT_ID,
};
const transactionThreadReport: Report = {
...createRandomReport(2, undefined),
reportID: transactionThreadReportID,
parentReportID,
type: CONST.REPORT.TYPE.CHAT,
};
const fakeTransaction: Transaction = {
...createRandomTransaction(3),
transactionID,
reportID: parentReportID,
billable: false,
};
const fakePolicy: Policy = createRandomPolicy(Number(policyID));

await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${parentReportID}`, parentReport);
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`, transactionThreadReport);
await Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, fakeTransaction);
await Onyx.set(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, fakePolicy);

// When updating billable to true
updateMoneyRequestBillable({
transactionID,
transactionThreadReport,
parentReport,
value: true,
policy: fakePolicy,
policyTagList: {},
policyCategories: {},
currentUserAccountIDParam: RORY_ACCOUNT_ID,
currentUserEmailParam: RORY_EMAIL,
isASAPSubmitBetaEnabled: false,
parentReportNextStep: undefined,
isOffline: false,
});

await waitForBatchedUpdates();

// Then the transaction billable field should be updated
const transactionAfter = await getOnyxValue(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`);
expect(transactionAfter?.billable).toBe(true);
});

it('should not update anything if transactionID is missing', async () => {
// Given a transaction
const transactionID = 'txnBillableNoOp';
const fakeTransaction: Transaction = {
...createRandomTransaction(1),
transactionID,
billable: false,
};
await Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, fakeTransaction);

// When updateMoneyRequestBillable is called with an undefined transactionID
updateMoneyRequestBillable({
transactionID: undefined,
transactionThreadReport: {reportID: '1'},
parentReport: undefined,
value: true,
policy: undefined,
policyTagList: {},
policyCategories: {},
currentUserAccountIDParam: RORY_ACCOUNT_ID,
currentUserEmailParam: RORY_EMAIL,
isASAPSubmitBetaEnabled: false,
parentReportNextStep: undefined,
isOffline: false,
});

await waitForBatchedUpdates();

// Then the original transaction billable value should be unchanged
const transactionAfter = await getOnyxValue(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`);
expect(transactionAfter?.billable).toBe(false);
});
});

describe('updateMoneyRequestDistance', () => {
it('should update transaction with distance and waypoints', async () => {
// Given a distance request transaction with valid waypoints and existing data
Expand Down
Loading