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
2 changes: 1 addition & 1 deletion src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11630,7 +11630,7 @@ function saveSplitTransactions(draftTransaction: OnyxEntry<OnyxTypes.Transaction
};

const {report, participantParams, policyParams, transactionParams} = requestMoneyInformation;
const parsedComment = getParsedComment(transactionParams.comment ?? '');
const parsedComment = getParsedComment(Parser.htmlToMarkdown(transactionParams.comment ?? ''));
transactionParams.comment = parsedComment;

const currentChatReport = getReportOrDraftReport(report?.chatReportID);
Expand Down
97 changes: 97 additions & 0 deletions tests/actions/IOUTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
replaceReceipt,
requestMoney,
resolveDuplicates,
saveSplitTransactions,
sendInvoice,
setDraftSplitTransaction,
setMoneyRequestCategory,
Expand Down Expand Up @@ -6245,5 +6246,101 @@ describe('actions/IOU', () => {
expect(isMoneyRequestAction(updatedIOUReportActionOnSelfDMReport) ? getOriginalMessage(updatedIOUReportActionOnSelfDMReport)?.IOUTransactionID : undefined).toBe(undefined);
expect(updatedTrackExpenseActionableWhisper).toBe(undefined);
});

describe('saveSplitTransactions', () => {
it("should update split transaction's description correctly ", async () => {
const amount = 10000;
let expenseReport: OnyxEntry<Report>;
let chatReport: OnyxEntry<Report>;
let originalTransactionID;

const policyID = generatePolicyID();
createWorkspace(CARLOS_EMAIL, true, "Carlos's Workspace", policyID);

// Change the approval mode for the policy since default is Submit and Close
setWorkspaceApprovalMode(policyID, CARLOS_EMAIL, CONST.POLICY.APPROVAL_MODE.BASIC);
await waitForBatchedUpdates();
await getOnyxData({
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (allReports) => {
chatReport = Object.values(allReports ?? {}).find((report) => report?.chatType === CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT);
},
});
requestMoney({
report: chatReport,
participantParams: {
payeeEmail: RORY_EMAIL,
payeeAccountID: RORY_ACCOUNT_ID,
participant: {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID, isPolicyExpenseChat: true, reportID: chatReport?.reportID},
},
transactionParams: {
amount,
attendees: [],
currency: CONST.CURRENCY.USD,
created: '',
merchant: 'NASDAQ',
comment: '*hey* `hey`',
},
});
await waitForBatchedUpdates();
await getOnyxData({
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (allReports) => {
expenseReport = Object.values(allReports ?? {}).find((report) => report?.type === CONST.REPORT.TYPE.EXPENSE);
},
});
await getOnyxData({
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport?.reportID}`,
waitForCollectionCallback: false,
callback: (allReportsAction) => {
const iouActions = Object.values(allReportsAction ?? {}).filter((reportAction): reportAction is ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.IOU> =>
isMoneyRequestAction(reportAction),
);
const originalMessage = isMoneyRequestAction(iouActions?.at(0)) ? getOriginalMessage(iouActions?.at(0)) : undefined;
originalTransactionID = originalMessage?.IOUTransactionID;
},
});

const originalTransaction = await getOnyxValue(`${ONYXKEYS.COLLECTION.TRANSACTION}${originalTransactionID}`);
const draftTransaction: Transaction = {
reportID: originalTransaction?.reportID ?? '456',
transactionID: originalTransaction?.transactionID ?? '234',
amount,
created: originalTransaction?.created ?? DateUtils.getDBTime(),
currency: CONST.CURRENCY.USD,
merchant: originalTransaction?.merchant ?? '',
comment: {
originalTransactionID,
comment: originalTransaction?.comment?.comment ?? '',
splitExpenses: [
{
transactionID: '235',
amount: amount / 2,
description: '<strong>hey</strong><br /><code>hey</code>',
created: DateUtils.getDBTime(),
},
{
transactionID: '234',
amount: amount / 2,
description: '*hey1* `hey`',
created: DateUtils.getDBTime(),
},
],
attendees: [],
type: CONST.TRANSACTION.TYPE.CUSTOM_UNIT,
},
};

saveSplitTransactions(draftTransaction, -2);
await waitForBatchedUpdates();

const split1 = await getOnyxValue(`${ONYXKEYS.COLLECTION.TRANSACTION}235`);
expect(split1?.comment?.comment).toBe('<strong>hey</strong><br /><code>hey</code>');
const split2 = await getOnyxValue(`${ONYXKEYS.COLLECTION.TRANSACTION}234`);
expect(split2?.comment?.comment).toBe('<strong>hey1</strong> <code>hey</code>');
});
});
});
});