diff --git a/src/components/ReportActionItem/MoneyRequestAction.js b/src/components/ReportActionItem/MoneyRequestAction.js index 801f807e36c5..f7d317078d9b 100644 --- a/src/components/ReportActionItem/MoneyRequestAction.js +++ b/src/components/ReportActionItem/MoneyRequestAction.js @@ -2,6 +2,7 @@ import _ from 'underscore'; import React from 'react'; import PropTypes from 'prop-types'; import {withOnyx} from 'react-native-onyx'; +import lodashGet from 'lodash/get'; import ONYXKEYS from '../../ONYXKEYS'; import CONST from '../../CONST'; import {withNetwork} from '../OnyxProvider'; @@ -69,7 +70,7 @@ const defaultProps = { }; const MoneyRequestAction = (props) => { - const hasMultipleParticipants = props.chatReport.participants.length > 1; + const hasMultipleParticipants = lodashGet(props.chatReport, 'participants.length', 0) > 1; const onIOUPreviewPressed = () => { if (hasMultipleParticipants) { Navigation.navigate(ROUTES.getReportParticipantsRoute(props.chatReportID)); diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index b7f7dff45a6d..08b812e5d065 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -112,8 +112,9 @@ function requestMoney(report, amount, currency, payeeEmail, participant, comment }; // Note: The created action must be optimistically generated before the IOU action so there's no chance that the created action appears after the IOU action in the chat - const optimisticCreatedAction = ReportUtils.buildOptimisticCreatedReportAction(payeeEmail); - const optimisticReportAction = ReportUtils.buildOptimisticIOUReportAction( + const optimisticCreatedActionForChat = ReportUtils.buildOptimisticCreatedReportAction(payeeEmail); + const optimisticCreatedActionForIOU = ReportUtils.buildOptimisticCreatedReportAction(payeeEmail); + const optimisticIOUAction = ReportUtils.buildOptimisticIOUReportAction( CONST.IOU.REPORT_ACTION_TYPE.CREATE, amount, currency, @@ -131,8 +132,6 @@ function requestMoney(report, amount, currency, payeeEmail, participant, comment value: { ...chatReport, lastReadTime: DateUtils.getDBTime(), - lastMessageText: optimisticReportAction.message[0].text, - lastMessageHtml: optimisticReportAction.message[0].html, hasOutstandingIOU: moneyRequestReport.total !== 0, iouReportID: moneyRequestReport.reportID, }, @@ -141,23 +140,28 @@ function requestMoney(report, amount, currency, payeeEmail, participant, comment const optimisticIOUReportData = { onyxMethod: chatReport.hasOutstandingIOU ? Onyx.METHOD.MERGE : Onyx.METHOD.SET, key: `${ONYXKEYS.COLLECTION.REPORT}${moneyRequestReport.reportID}`, - value: moneyRequestReport, + value: { + ...moneyRequestReport, + lastMessageText: optimisticIOUAction.message[0].text, + lastMessageHtml: optimisticIOUAction.message[0].html, + }, }; const optimisticReportActionsData = { onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${moneyRequestReport.reportID}`, value: { - [optimisticReportAction.reportActionID]: optimisticReportAction, + ...(chatReport.iouReportID ? {} : {[optimisticCreatedActionForIOU.reportActionID]: optimisticCreatedActionForIOU}), + [optimisticIOUAction.reportActionID]: optimisticIOUAction, }, }; let chatReportSuccessData = {}; const reportActionsSuccessData = { onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${moneyRequestReport.reportID}`, value: { - [optimisticReportAction.reportActionID]: { + [optimisticIOUAction.reportActionID]: { pendingAction: null, }, }, @@ -173,9 +177,9 @@ function requestMoney(report, amount, currency, payeeEmail, participant, comment const reportActionsFailureData = { onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${moneyRequestReport.reportID}`, value: { - [optimisticReportAction.reportActionID]: { + [optimisticIOUAction.reportActionID]: { errors: { [DateUtils.getMicroseconds()]: Localize.translateLocal('iou.error.genericCreateFailureMessage'), }, @@ -210,12 +214,12 @@ function requestMoney(report, amount, currency, payeeEmail, participant, comment }; // Then add an optimistic created action - optimisticReportActionsData.value[optimisticCreatedAction.reportActionID] = optimisticCreatedAction; - reportActionsSuccessData.value[optimisticCreatedAction.reportActionID] = {pendingAction: null}; + optimisticReportActionsData.value[optimisticCreatedActionForChat.reportActionID] = optimisticCreatedActionForChat; + reportActionsSuccessData.value[optimisticCreatedActionForChat.reportActionID] = {pendingAction: null}; // Failure data should feature red brick road - reportActionsFailureData.value[optimisticCreatedAction.reportActionID] = {pendingAction: null}; - reportActionsFailureData.value[optimisticReportAction.reportActionID] = {pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD}; + reportActionsFailureData.value[optimisticCreatedActionForChat.reportActionID] = {pendingAction: null}; + reportActionsFailureData.value[optimisticIOUAction.reportActionID] = {pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD}; } const optimisticData = [optimisticChatReportData, optimisticIOUReportData, optimisticReportActionsData, optimisticTransactionData]; @@ -238,8 +242,8 @@ function requestMoney(report, amount, currency, payeeEmail, participant, comment iouReportID: moneyRequestReport.reportID, chatReportID: chatReport.reportID, transactionID: optimisticTransaction.transactionID, - reportActionID: optimisticReportAction.reportActionID, - createdReportActionID: isNewChat ? optimisticCreatedAction.reportActionID : 0, + reportActionID: optimisticIOUAction.reportActionID, + createdReportActionID: isNewChat ? optimisticCreatedActionForChat.reportActionID : 0, }, {optimisticData, successData, failureData}, ); @@ -649,7 +653,7 @@ function deleteMoneyRequest(chatReportID, iouReportID, moneyRequestAction, shoul // Get the amount we are deleting const amount = moneyRequestAction.originalMessage.amount; - const optimisticReportAction = ReportUtils.buildOptimisticIOUReportAction( + const optimisticIOUAction = ReportUtils.buildOptimisticIOUReportAction( CONST.IOU.REPORT_ACTION_TYPE.DELETE, amount, moneyRequestAction.originalMessage.currency, @@ -660,19 +664,19 @@ function deleteMoneyRequest(chatReportID, iouReportID, moneyRequestAction, shoul iouReportID, ); - const currentUserEmail = optimisticReportAction.actorEmail; + const currentUserEmail = optimisticIOUAction.actorEmail; const updatedIOUReport = IOUUtils.updateIOUOwnerAndTotal(iouReport, currentUserEmail, amount, moneyRequestAction.originalMessage.currency, CONST.IOU.REPORT_ACTION_TYPE.DELETE); - chatReport.lastMessageText = optimisticReportAction.message[0].text; - chatReport.lastMessageHtml = optimisticReportAction.message[0].html; + iouReport.lastMessageText = optimisticIOUAction.message[0].text; + iouReport.lastMessageHtml = optimisticIOUAction.message[0].html; chatReport.hasOutstandingIOU = updatedIOUReport.total !== 0; const optimisticData = [ { onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReportID}`, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReportID}`, value: { - [optimisticReportAction.reportActionID]: { - ...optimisticReportAction, + [optimisticIOUAction.reportActionID]: { + ...optimisticIOUAction, pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, }, }, @@ -696,9 +700,9 @@ function deleteMoneyRequest(chatReportID, iouReportID, moneyRequestAction, shoul const successData = [ { onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReportID}`, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReportID}`, value: { - [optimisticReportAction.reportActionID]: { + [optimisticIOUAction.reportActionID]: { pendingAction: null, }, }, @@ -707,9 +711,9 @@ function deleteMoneyRequest(chatReportID, iouReportID, moneyRequestAction, shoul const failureData = [ { onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReportID}`, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReportID}`, value: { - [optimisticReportAction.reportActionID]: { + [optimisticIOUAction.reportActionID]: { errors: { [DateUtils.getMicroseconds()]: Localize.translateLocal('iou.error.genericDeleteFailureMessage'), }, @@ -720,15 +724,17 @@ function deleteMoneyRequest(chatReportID, iouReportID, moneyRequestAction, shoul onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${chatReportID}`, value: { - lastMessageText: chatReports[`${ONYXKEYS.COLLECTION.REPORT}${chatReportID}`].lastMessageText, - lastMessageHtml: chatReports[`${ONYXKEYS.COLLECTION.REPORT}${chatReportID}`].lastMessageHtml, hasOutstandingIOU: iouReport.total !== 0, }, }, { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${iouReportID}`, - value: iouReport, + value: { + ...iouReport, + lastMessageText: iouReport.lastMessageText, + lastMessageHtml: iouReport.lastMessageHtml, + }, }, { onyxMethod: Onyx.METHOD.SET, @@ -742,7 +748,7 @@ function deleteMoneyRequest(chatReportID, iouReportID, moneyRequestAction, shoul { transactionID, chatReportID, - reportActionID: optimisticReportAction.reportActionID, + reportActionID: optimisticIOUAction.reportActionID, iouReportID: updatedIOUReport.reportID, }, {optimisticData, successData, failureData}, @@ -822,7 +828,7 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType // Note: The created action must be optimistically generated before the IOU action so there's no chance that the created action appears after the IOU action in the chat const optimisticCreatedAction = ReportUtils.buildOptimisticCreatedReportAction(recipientEmail); - const optimisticIOUReportAction = ReportUtils.buildOptimisticIOUReportAction( + const optimisticIOUAction = ReportUtils.buildOptimisticIOUReportAction( CONST.IOU.REPORT_ACTION_TYPE.PAY, amount, currency, @@ -840,33 +846,32 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType value: { ...chatReport, lastReadTime: DateUtils.getDBTime(), - lastVisibleActionCreated: optimisticIOUReportAction.created, - lastMessageText: optimisticIOUReportAction.message[0].text, - lastMessageHtml: optimisticIOUReportAction.message[0].html, }, }; const optimisticIOUReportData = { onyxMethod: Onyx.METHOD.SET, key: `${ONYXKEYS.COLLECTION.REPORT}${optimisticIOUReport.reportID}`, - value: optimisticIOUReport, + value: { + ...optimisticIOUReport, + lastMessageText: optimisticIOUAction.message[0].text, + lastMessageHtml: optimisticIOUAction.message[0].html, + lastVisibleActionCreated: optimisticIOUAction.created, + }, }; const optimisticReportActionsData = { onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${optimisticIOUReport.reportID}`, value: { - [optimisticIOUReportAction.reportActionID]: { - ...optimisticIOUReportAction, - pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, - }, + [optimisticIOUAction.reportActionID]: optimisticIOUAction, }, }; const successData = [ { onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${optimisticIOUReport.reportID}`, value: { - [optimisticIOUReportAction.reportActionID]: { + [optimisticIOUAction.reportActionID]: { pendingAction: null, }, }, @@ -881,9 +886,9 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType const failureData = [ { onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${optimisticIOUReport.reportID}`, value: { - [optimisticIOUReportAction.reportActionID]: { + [optimisticIOUAction.reportActionID]: { errors: { [DateUtils.getMicroseconds()]: Localize.translateLocal('iou.error.other'), }, @@ -933,7 +938,7 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType optimisticReportActionsData.value[optimisticCreatedAction.reportActionID] = optimisticCreatedAction; // If we're going to fail to create the report itself, let's not have redundant error messages for the IOU - failureData[0].value[optimisticIOUReportAction.reportActionID] = {pendingAction: null}; + failureData[0].value[optimisticIOUAction.reportActionID] = {pendingAction: null}; } const optimisticData = [optimisticChatReportData, optimisticIOUReportData, optimisticReportActionsData, optimisticTransactionData]; @@ -942,7 +947,7 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType params: { iouReportID: optimisticIOUReport.reportID, chatReportID: chatReport.reportID, - reportActionID: optimisticIOUReportAction.reportActionID, + reportActionID: optimisticIOUAction.reportActionID, paymentMethodType, transactionID: optimisticTransaction.transactionID, newIOUReportDetails, @@ -963,7 +968,7 @@ function getSendMoneyParams(report, amount, currency, comment, paymentMethodType */ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMethodType) { const optimisticTransaction = TransactionUtils.buildOptimisticTransaction(iouReport.total, iouReport.currency, iouReport.reportID); - const optimisticIOUReportAction = ReportUtils.buildOptimisticIOUReportAction( + const optimisticIOUAction = ReportUtils.buildOptimisticIOUReportAction( CONST.IOU.REPORT_ACTION_TYPE.PAY, iouReport.total, iouReport.currency, @@ -982,19 +987,16 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho value: { ...chatReport, lastReadTime: DateUtils.getDBTime(), - lastVisibleActionCreated: optimisticIOUReportAction.created, - lastMessageText: optimisticIOUReportAction.message[0].text, - lastMessageHtml: optimisticIOUReportAction.message[0].html, hasOutstandingIOU: false, iouReportID: null, }, }, { onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReport.reportID}`, value: { - [optimisticIOUReportAction.reportActionID]: { - ...optimisticIOUReportAction, + [optimisticIOUAction.reportActionID]: { + ...optimisticIOUAction, pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, }, }, @@ -1004,6 +1006,9 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport.reportID}`, value: { ...iouReport, + lastVisibleActionCreated: optimisticIOUAction.created, + lastMessageText: optimisticIOUAction.message[0].text, + lastMessageHtml: optimisticIOUAction.message[0].html, hasOutstandingIOU: false, stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, }, @@ -1018,9 +1023,9 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho const successData = [ { onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReport.reportID}`, value: { - [optimisticIOUReportAction.reportActionID]: { + [optimisticIOUAction.reportActionID]: { pendingAction: null, }, }, @@ -1037,9 +1042,9 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho const failureData = [ { onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReport.reportID}`, value: { - [optimisticIOUReportAction.reportActionID]: { + [optimisticIOUAction.reportActionID]: { pendingAction: null, errors: { [DateUtils.getMicroseconds()]: Localize.translateLocal('iou.error.other'), @@ -1063,7 +1068,7 @@ function getPayMoneyRequestParams(chatReport, iouReport, recipient, paymentMetho params: { iouReportID: iouReport.reportID, chatReportID: chatReport.reportID, - reportActionID: optimisticIOUReportAction.reportActionID, + reportActionID: optimisticIOUAction.reportActionID, paymentMethodType, }, optimisticData, diff --git a/src/pages/iou/IOUDetailsModal.js b/src/pages/iou/IOUDetailsModal.js index 630fb9836071..ffe6d11c7afb 100644 --- a/src/pages/iou/IOUDetailsModal.js +++ b/src/pages/iou/IOUDetailsModal.js @@ -93,7 +93,7 @@ const propTypes = { const defaultProps = { iou: {}, reportActions: {}, - iouReport: undefined, + iouReport: {}, session: { email: null, }, @@ -186,7 +186,7 @@ class IOUDetailsModal extends Component { 1} + isBillSplit={lodashGet(this.props.chatReport, 'participants.length', 0) > 1} isIOUAction={false} pendingAction={pendingAction} /> diff --git a/tests/actions/IOUTest.js b/tests/actions/IOUTest.js index 7d18f5fe77d5..6d3e7a458ebf 100644 --- a/tests/actions/IOUTest.js +++ b/tests/actions/IOUTest.js @@ -32,7 +32,6 @@ describe('actions/IOU', () => { it('creates new chat if needed', () => { const amount = 10000; const comment = 'Giv money plz'; - let chatReportID; let iouReportID; let createdAction; let iouAction; @@ -55,7 +54,6 @@ describe('actions/IOU', () => { expect(_.size(chatReports)).toBe(1); expect(_.size(iouReports)).toBe(1); const chatReport = chatReports[0]; - chatReportID = chatReport.reportID; const iouReport = iouReports[0]; iouReportID = iouReport.reportID; @@ -73,15 +71,15 @@ describe('actions/IOU', () => { () => new Promise((resolve) => { const connectionID = Onyx.connect({ - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReportID}`, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReportID}`, waitForCollectionCallback: true, - callback: (reportActionsForChatReport) => { + callback: (reportActionsForIOUReport) => { Onyx.disconnect(connectionID); - // The chat report should have a CREATED action and IOU action - expect(_.size(reportActionsForChatReport)).toBe(2); - const createdActions = _.filter(reportActionsForChatReport, (reportAction) => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED); - const iouActions = _.filter(reportActionsForChatReport, (reportAction) => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU); + // The IOU report should have a CREATED action and IOU action + expect(_.size(reportActionsForIOUReport)).toBe(2); + const createdActions = _.filter(reportActionsForIOUReport, (reportAction) => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED); + const iouActions = _.filter(reportActionsForIOUReport, (reportAction) => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU); expect(_.size(createdActions)).toBe(1); expect(_.size(iouActions)).toBe(1); createdAction = createdActions[0]; @@ -152,12 +150,12 @@ describe('actions/IOU', () => { () => new Promise((resolve) => { const connectionID = Onyx.connect({ - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReportID}`, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReportID}`, waitForCollectionCallback: true, - callback: (reportActionsForChatReport) => { + callback: (reportActionsForIOUReport) => { Onyx.disconnect(connectionID); - expect(_.size(reportActionsForChatReport)).toBe(2); - _.each(reportActionsForChatReport, (reportAction) => expect(reportAction.pendingAction).toBeFalsy()); + expect(_.size(reportActionsForIOUReport)).toBe(2); + _.each(reportActionsForIOUReport, (reportAction) => expect(reportAction.pendingAction).toBeFalsy()); resolve(); }, }); @@ -236,12 +234,12 @@ describe('actions/IOU', () => { () => new Promise((resolve) => { const connectionID = Onyx.connect({ - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReportID}`, waitForCollectionCallback: true, callback: (allReportActions) => { Onyx.disconnect(connectionID); - // The chat report should have a CREATED and an IOU action + // The IOU report should have an IOU action expect(_.size(allReportActions)).toBe(2); iouAction = _.find(allReportActions, (reportAction) => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU); @@ -309,12 +307,12 @@ describe('actions/IOU', () => { () => new Promise((resolve) => { const connectionID = Onyx.connect({ - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReportID}`, waitForCollectionCallback: true, - callback: (reportActionsForChatReport) => { + callback: (reportActionsForIOUReport) => { Onyx.disconnect(connectionID); - expect(_.size(reportActionsForChatReport)).toBe(2); - _.each(reportActionsForChatReport, (reportAction) => expect(reportAction.pendingAction).toBeFalsy()); + expect(_.size(reportActionsForIOUReport)).toBe(2); + _.each(reportActionsForIOUReport, (reportAction) => expect(reportAction.pendingAction).toBeFalsy()); resolve(); }, }); @@ -427,14 +425,14 @@ describe('actions/IOU', () => { () => new Promise((resolve) => { const connectionID = Onyx.connect({ - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReportID}`, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReportID}`, waitForCollectionCallback: true, - callback: (reportActionsForChatReport) => { + callback: (reportActionsForIOUReport) => { Onyx.disconnect(connectionID); - expect(_.size(reportActionsForChatReport)).toBe(3); + expect(_.size(reportActionsForIOUReport)).toBe(3); newIOUAction = _.find( - reportActionsForChatReport, + reportActionsForIOUReport, (reportAction) => reportAction.reportActionID !== createdAction.reportActionID && reportAction.reportActionID !== iouAction.reportActionID, ); @@ -491,12 +489,12 @@ describe('actions/IOU', () => { () => new Promise((resolve) => { const connectionID = Onyx.connect({ - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReportID}`, waitForCollectionCallback: true, - callback: (reportActionsForChatReport) => { + callback: (reportActionsForIOUReport) => { Onyx.disconnect(connectionID); - expect(_.size(reportActionsForChatReport)).toBe(3); - _.each(reportActionsForChatReport, (reportAction) => expect(reportAction.pendingAction).toBeFalsy()); + expect(_.size(reportActionsForIOUReport)).toBe(3); + _.each(reportActionsForIOUReport, (reportAction) => expect(reportAction.pendingAction).toBeFalsy()); resolve(); }, }); @@ -563,15 +561,15 @@ describe('actions/IOU', () => { () => new Promise((resolve) => { const connectionID = Onyx.connect({ - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReportID}`, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReportID}`, waitForCollectionCallback: true, - callback: (reportActionsForChatReport) => { + callback: (reportActionsForIOUReport) => { Onyx.disconnect(connectionID); // The chat report should have a CREATED action and IOU action - expect(_.size(reportActionsForChatReport)).toBe(2); - const createdActions = _.filter(reportActionsForChatReport, (reportAction) => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED); - const iouActions = _.filter(reportActionsForChatReport, (reportAction) => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU); + expect(_.size(reportActionsForIOUReport)).toBe(2); + const createdActions = _.filter(reportActionsForIOUReport, (reportAction) => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED); + const iouActions = _.filter(reportActionsForIOUReport, (reportAction) => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU); expect(_.size(createdActions)).toBe(1); expect(_.size(iouActions)).toBe(1); createdAction = createdActions[0]; @@ -637,12 +635,12 @@ describe('actions/IOU', () => { () => new Promise((resolve) => { const connectionID = Onyx.connect({ - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReportID}`, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReportID}`, waitForCollectionCallback: true, - callback: (reportActionsForChatReport) => { + callback: (reportActionsForIOUReport) => { Onyx.disconnect(connectionID); - expect(_.size(reportActionsForChatReport)).toBe(2); - iouAction = _.find(reportActionsForChatReport, (reportAction) => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU); + expect(_.size(reportActionsForIOUReport)).toBe(2); + iouAction = _.find(reportActionsForIOUReport, (reportAction) => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU); expect(iouAction.pendingAction).toBe(CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD); resolve(); }, @@ -1193,9 +1191,9 @@ describe('actions/IOU', () => { callback: (allReportActions) => { Onyx.disconnect(connectionID); - const reportActionsForChatReport = allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`]; + const reportActionsForIOUReport = allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReport.reportID}`]; - createIOUAction = _.find(reportActionsForChatReport, (ra) => ra.actionName === CONST.REPORT.ACTIONS.TYPE.IOU); + createIOUAction = _.find(reportActionsForIOUReport, (ra) => ra.actionName === CONST.REPORT.ACTIONS.TYPE.IOU); expect(createIOUAction).toBeTruthy(); expect(createIOUAction.originalMessage.IOUReportID).toBe(iouReport.reportID); @@ -1263,11 +1261,11 @@ describe('actions/IOU', () => { callback: (allReportActions) => { Onyx.disconnect(connectionID); - const reportActionsForChatReport = allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`]; - expect(_.size(reportActionsForChatReport)).toBe(3); + const reportActionsForIOUReport = allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReport.reportID}`]; + expect(_.size(reportActionsForIOUReport)).toBe(3); payIOUAction = _.find( - reportActionsForChatReport, + reportActionsForIOUReport, (ra) => ra.actionName === CONST.REPORT.ACTIONS.TYPE.IOU && ra.originalMessage.type === CONST.IOU.REPORT_ACTION_TYPE.PAY, ); expect(payIOUAction).toBeTruthy(); @@ -1314,11 +1312,11 @@ describe('actions/IOU', () => { callback: (allReportActions) => { Onyx.disconnect(connectionID); - const reportActionsForChatReport = allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport.reportID}`]; - expect(_.size(reportActionsForChatReport)).toBe(3); + const reportActionsForIOUReport = allReportActions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReport.reportID}`]; + expect(_.size(reportActionsForIOUReport)).toBe(3); payIOUAction = _.find( - reportActionsForChatReport, + reportActionsForIOUReport, (ra) => ra.actionName === CONST.REPORT.ACTIONS.TYPE.IOU && ra.originalMessage.type === CONST.IOU.REPORT_ACTION_TYPE.PAY, ); expect(payIOUAction).toBeTruthy();