From 5d51206ee1aba442630b0e17b90b7597e91b16dd Mon Sep 17 00:00:00 2001 From: Sibtain Ali Date: Sun, 17 Sep 2023 01:55:17 +0500 Subject: [PATCH 1/9] feat: add unit tests for edit money request and payment via vbba --- src/libs/actions/IOU.js | 11 +- tests/actions/IOUTest.js | 421 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 428 insertions(+), 4 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 3cefcd00ed60..60491a2546f5 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -1139,21 +1139,24 @@ function editMoneyRequest(transactionID, transactionThreadReportID, transactionC onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThread.reportID}`, value: { - [updatedReportAction.reportActionID]: updatedReportAction, + [updatedReportAction.reportActionID]: { + ...updatedReportAction, + errors: ErrorUtils.getMicroSecondOnyxError('iou.error.genericEditFailureMessage'), + }, }, }, { - onyxMethod: Onyx.METHOD.MERGE, + onyxMethod: Onyx.METHOD.SET, key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, value: transaction, }, { - onyxMethod: Onyx.METHOD.MERGE, + onyxMethod: Onyx.METHOD.SET, key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport.reportID}`, value: iouReport, }, { - onyxMethod: Onyx.METHOD.MERGE, + onyxMethod: Onyx.METHOD.SET, key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport.chatReportID}`, value: chatReport, }, diff --git a/tests/actions/IOUTest.js b/tests/actions/IOUTest.js index afb06cdb6fb3..b9e84d9aead6 100644 --- a/tests/actions/IOUTest.js +++ b/tests/actions/IOUTest.js @@ -8,6 +8,7 @@ import * as TestHelper from '../utils/TestHelper'; import DateUtils from '../../src/libs/DateUtils'; import * as NumberUtils from '../../src/libs/NumberUtils'; import * as ReportActions from '../../src/libs/actions/ReportActions'; +import * as ReportUtils from '../../src/libs/ReportUtils'; import * as Report from '../../src/libs/actions/Report'; import OnyxUpdateManager from '../../src/libs/actions/OnyxUpdateManager'; @@ -1372,4 +1373,424 @@ describe('actions/IOU', () => { ); }); }); + + describe('edit requestMoney', () => { + const amount = 10000; + const comment = '💸💸💸💸'; + const merchant = 'NASDAQ'; + + it('updates the IOU request and IOU report when offline', () => { + let thread = {}; + let iouReport = {}; + let iouAction = {}; + let transaction = {}; + + fetch.pause(); + IOU.requestMoney({}, amount, CONST.CURRENCY.USD, '', merchant, RORY_EMAIL, RORY_ACCOUNT_ID, {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, comment); + return waitForPromisesToResolve() + .then(() => { + Onyx.set(ONYXKEYS.SESSION, {email: RORY_EMAIL, accountID: RORY_ACCOUNT_ID}); + return waitForPromisesToResolve(); + }) + .then( + () => + new Promise((resolve) => { + const connectionID = Onyx.connect({ + key: ONYXKEYS.COLLECTION.REPORT, + waitForCollectionCallback: true, + callback: (allReports) => { + Onyx.disconnect(connectionID); + iouReport = _.find(allReports, (report) => report.type === CONST.REPORT.TYPE.IOU); + + resolve(); + }, + }); + }), + ) + .then( + () => + new Promise((resolve) => { + const connectionID = Onyx.connect({ + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReport.reportID}`, + waitForCollectionCallback: true, + callback: (reportActionsForIOUReport) => { + Onyx.disconnect(connectionID); + + [iouAction] = _.filter(reportActionsForIOUReport, (reportAction) => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU); + resolve(); + }, + }); + }), + ) + .then( + () => + new Promise((resolve) => { + const connectionID = Onyx.connect({ + key: ONYXKEYS.COLLECTION.TRANSACTION, + waitForCollectionCallback: true, + callback: (allTransactions) => { + Onyx.disconnect(connectionID); + + transaction = _.find(allTransactions, (t) => !_.isEmpty(t)); + resolve(); + }, + }); + }), + ) + .then(() => { + thread = ReportUtils.buildTransactionThread(iouAction, iouReport.reportID); + Onyx.set(`report_${thread.reportID}`, thread); + return waitForPromisesToResolve(); + }) + .then(() => { + IOU.editMoneyRequest(transaction.transactionID, thread.reportID, {amount: 20000, comment: 'Double the amount!'}); + return waitForPromisesToResolve(); + }) + .then( + () => + new Promise((resolve) => { + const connectionID = Onyx.connect({ + key: ONYXKEYS.COLLECTION.TRANSACTION, + waitForCollectionCallback: true, + callback: (allTransactions) => { + Onyx.disconnect(connectionID); + + const updatedTransaction = _.find(allTransactions, (t) => !_.isEmpty(t)); + expect(updatedTransaction.modifiedAmount).toBe(20000); + expect(updatedTransaction.comment).toMatchObject({comment: 'Double the amount!'}); + resolve(); + }, + }); + }), + ) + .then( + () => + new Promise((resolve) => { + const connectionID = Onyx.connect({ + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${thread.reportID}`, + waitForCollectionCallback: true, + callback: (allActions) => { + Onyx.disconnect(connectionID); + const updatedAction = _.find(allActions, (reportAction) => !_.isEmpty(reportAction)); + expect(updatedAction.originalMessage).toEqual( + expect.objectContaining({amount: 20000, newComment: 'Double the amount!', oldAmount: amount, oldComment: comment}), + ); + resolve(); + }, + }); + }), + ) + .then( + () => + new Promise((resolve) => { + const connectionID = Onyx.connect({ + key: ONYXKEYS.COLLECTION.REPORT, + waitForCollectionCallback: true, + callback: (allReports) => { + Onyx.disconnect(connectionID); + const updatedIOUReport = _.find(allReports, (report) => report.type === CONST.REPORT.TYPE.IOU); + const updatedChatReport = _.find(allReports, (report) => report.reportID === iouReport.chatReportID); + expect(updatedIOUReport).toEqual( + expect.objectContaining({ + total: 20000, + cachedTotal: '$200.00', + lastMessageHtml: 'requested $200.00', + lastMessageText: 'requested $200.00', + }), + ); + expect(updatedChatReport).toEqual( + expect.objectContaining({ + lastMessageHtml: 'undefined owes $200.00', + lastMessageText: 'undefined owes $200.00', + }), + ); + resolve(); + }, + }); + }), + ) + .then(() => { + fetch.resume(); + }); + }); + + it('resets the IOU request and IOU report when api returns an error', () => { + let thread = {}; + let iouReport = {}; + let iouAction = {}; + let transaction = {}; + + IOU.requestMoney({}, amount, CONST.CURRENCY.USD, '', merchant, RORY_EMAIL, RORY_ACCOUNT_ID, {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, comment); + return waitForPromisesToResolve() + .then(() => { + Onyx.set(ONYXKEYS.SESSION, {email: RORY_EMAIL, accountID: RORY_ACCOUNT_ID}); + return waitForPromisesToResolve(); + }) + .then( + () => + new Promise((resolve) => { + const connectionID = Onyx.connect({ + key: ONYXKEYS.COLLECTION.REPORT, + waitForCollectionCallback: true, + callback: (allReports) => { + Onyx.disconnect(connectionID); + [iouReport] = _.filter(allReports, (report) => report.type === CONST.REPORT.TYPE.IOU); + resolve(); + }, + }); + }), + ) + .then( + () => + new Promise((resolve) => { + const connectionID = Onyx.connect({ + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReport.reportID}`, + waitForCollectionCallback: true, + callback: (reportActionsForIOUReport) => { + Onyx.disconnect(connectionID); + + [iouAction] = _.filter(reportActionsForIOUReport, (reportAction) => reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU); + resolve(); + }, + }); + }), + ) + .then( + () => + new Promise((resolve) => { + const connectionID = Onyx.connect({ + key: ONYXKEYS.COLLECTION.TRANSACTION, + waitForCollectionCallback: true, + callback: (allTransactions) => { + Onyx.disconnect(connectionID); + + transaction = _.find(allTransactions, (t) => !_.isEmpty(t)); + resolve(); + }, + }); + }), + ) + .then(() => { + thread = ReportUtils.buildTransactionThread(iouAction, iouReport.reportID); + Onyx.set(`report_${thread.reportID}`, thread); + return waitForPromisesToResolve(); + }) + .then(() => { + fetch.fail(); + IOU.editMoneyRequest(transaction.transactionID, thread.reportID, {amount: 20000, comment: 'Double the amount!'}); + return waitForPromisesToResolve(); + }) + .then( + () => + new Promise((resolve) => { + const connectionID = Onyx.connect({ + key: ONYXKEYS.COLLECTION.TRANSACTION, + waitForCollectionCallback: true, + callback: (allTransactions) => { + Onyx.disconnect(connectionID); + + const updatedTransaction = _.find(allTransactions, (t) => !_.isEmpty(t)); + expect(updatedTransaction.modifiedAmount).toBe(undefined); + expect(updatedTransaction.amount).toBe(10000); + expect(updatedTransaction.comment).toMatchObject({comment}); + resolve(); + }, + }); + }), + ) + .then( + () => + new Promise((resolve) => { + const connectionID = Onyx.connect({ + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${thread.reportID}`, + waitForCollectionCallback: true, + callback: (allActions) => { + Onyx.disconnect(connectionID); + const updatedAction = _.find(allActions, (reportAction) => !_.isEmpty(reportAction)); + expect(Object.values(updatedAction.errors)).toEqual(expect.arrayContaining(['iou.error.genericEditFailureMessage'])); + resolve(); + }, + }); + }), + ) + .then( + () => + new Promise((resolve) => { + const connectionID = Onyx.connect({ + key: ONYXKEYS.COLLECTION.REPORT, + waitForCollectionCallback: true, + callback: (allReports) => { + Onyx.disconnect(connectionID); + const updatedIOUReport = _.find(allReports, (report) => report.type === CONST.REPORT.TYPE.IOU); + const updatedChatReport = _.find(allReports, (report) => report.reportID === iouReport.chatReportID); + expect(updatedIOUReport).toEqual( + expect.objectContaining({ + total: 10000, + cachedTotal: '$100.00', + lastMessageHtml: `requested $${amount / 100}.00 for ${comment}`, + lastMessageText: `requested $${amount / 100}.00 for ${comment}`, + }), + ); + expect(updatedChatReport).toEqual( + expect.objectContaining({ + lastMessageHtml: '', + }), + ); + resolve(); + }, + }); + }), + ); + }); + }); + + describe('pay iou report via ACH', () => { + const amount = 10000; + const comment = '💸💸💸💸'; + const merchant = 'NASDAQ'; + + it('updates the IOU request and IOU report when paid while offline', () => { + let iouReport = {}; + let chatReport = {}; + + fetch.pause(); + IOU.requestMoney({}, amount, CONST.CURRENCY.USD, '', merchant, RORY_EMAIL, RORY_ACCOUNT_ID, {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, comment); + return waitForPromisesToResolve() + .then(() => { + Onyx.set(ONYXKEYS.SESSION, {email: RORY_EMAIL, accountID: RORY_ACCOUNT_ID}); + return waitForPromisesToResolve(); + }) + .then( + () => + new Promise((resolve) => { + const connectionID = Onyx.connect({ + key: ONYXKEYS.COLLECTION.REPORT, + waitForCollectionCallback: true, + callback: (allReports) => { + Onyx.disconnect(connectionID); + iouReport = _.find(allReports, (report) => report.type === CONST.REPORT.TYPE.IOU); + chatReport = _.find(allReports, (report) => report.type === CONST.REPORT.TYPE.CHAT); + + resolve(); + }, + }); + }), + ) + .then(() => { + IOU.payMoneyRequest(CONST.IOU.PAYMENT_TYPE.VBBA, chatReport, iouReport); + return waitForPromisesToResolve(); + }) + .then( + () => + new Promise((resolve) => { + const connectionID = Onyx.connect({ + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReport.reportID}`, + waitForCollectionCallback: true, + callback: (allActions) => { + Onyx.disconnect(connectionID); + expect(Object.values(allActions)).toEqual( + expect.arrayContaining([ + expect.objectContaining({ + message: expect.arrayContaining([ + expect.objectContaining({ + html: `paid $${amount / 100}.00 with Expensify`, + text: `paid $${amount / 100}.00 with Expensify`, + }), + ]), + originalMessage: expect.objectContaining({ + amount, + paymentType: CONST.IOU.PAYMENT_TYPE.VBBA, + type: 'pay', + }), + }), + ]), + ); + resolve(); + }, + }); + }), + ) + .then( + () => + new Promise((resolve) => { + const connectionID = Onyx.connect({ + key: ONYXKEYS.COLLECTION.REPORT, + waitForCollectionCallback: true, + callback: (allReports) => { + Onyx.disconnect(connectionID); + const updatedIOUReport = _.find(allReports, (report) => report.type === CONST.REPORT.TYPE.IOU); + const updatedChatReport = _.find(allReports, (report) => report.reportID === iouReport.chatReportID); + expect(updatedIOUReport).toEqual( + expect.objectContaining({ + lastMessageHtml: `paid $${amount / 100}.00 with Expensify`, + lastMessageText: `paid $${amount / 100}.00 with Expensify`, + state: CONST.REPORT.STATE.SUBMITTED, + statusNum: CONST.REPORT.STATUS.REIMBURSED, + stateNum: CONST.REPORT.STATE_NUM.PROCESSING, + }), + ); + expect(updatedChatReport).toEqual( + expect.objectContaining({ + lastMessageHtml: `paid $${amount / 100}.00 with Expensify`, + lastMessageText: `paid $${amount / 100}.00 with Expensify`, + }), + ); + resolve(); + }, + }); + }), + ) + .then(() => { + fetch.resume(); + }); + }); + + it('shows an error when paying results in an error', () => { + let iouReport = {}; + let chatReport = {}; + + IOU.requestMoney({}, amount, CONST.CURRENCY.USD, '', merchant, RORY_EMAIL, RORY_ACCOUNT_ID, {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, comment); + return waitForPromisesToResolve() + .then(() => { + Onyx.set(ONYXKEYS.SESSION, {email: RORY_EMAIL, accountID: RORY_ACCOUNT_ID}); + return waitForPromisesToResolve(); + }) + .then( + () => + new Promise((resolve) => { + const connectionID = Onyx.connect({ + key: ONYXKEYS.COLLECTION.REPORT, + waitForCollectionCallback: true, + callback: (allReports) => { + Onyx.disconnect(connectionID); + iouReport = _.find(allReports, (report) => report.type === CONST.REPORT.TYPE.IOU); + chatReport = _.find(allReports, (report) => report.type === CONST.REPORT.TYPE.CHAT); + + resolve(); + }, + }); + }), + ) + .then(() => { + fetch.fail(); + IOU.payMoneyRequest('ACH', chatReport, iouReport); + return waitForPromisesToResolve(); + }) + .then( + () => + new Promise((resolve) => { + const connectionID = Onyx.connect({ + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReport.reportID}`, + waitForCollectionCallback: true, + callback: (allActions) => { + Onyx.disconnect(connectionID); + const erroredAction = Object.values(allActions).find((action) => !_.isEmpty(action.errors)); + expect(Object.values(erroredAction.errors)).toEqual(expect.arrayContaining(['iou.error.other'])); + resolve(); + }, + }); + }), + ); + }); + }); }); From e26835fda402b0749a55c5c4530d6c2203f3ff7e Mon Sep 17 00:00:00 2001 From: Sibtain Ali Date: Sun, 17 Sep 2023 02:09:17 +0500 Subject: [PATCH 2/9] fix: lint errors --- tests/actions/IOUTest.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/actions/IOUTest.js b/tests/actions/IOUTest.js index b9e84d9aead6..1ac80578caa4 100644 --- a/tests/actions/IOUTest.js +++ b/tests/actions/IOUTest.js @@ -1607,7 +1607,7 @@ describe('actions/IOU', () => { callback: (allActions) => { Onyx.disconnect(connectionID); const updatedAction = _.find(allActions, (reportAction) => !_.isEmpty(reportAction)); - expect(Object.values(updatedAction.errors)).toEqual(expect.arrayContaining(['iou.error.genericEditFailureMessage'])); + expect(_.values(updatedAction.errors)).toEqual(expect.arrayContaining(['iou.error.genericEditFailureMessage'])); resolve(); }, }); @@ -1688,7 +1688,7 @@ describe('actions/IOU', () => { waitForCollectionCallback: true, callback: (allActions) => { Onyx.disconnect(connectionID); - expect(Object.values(allActions)).toEqual( + expect(_.values(allActions)).toEqual( expect.arrayContaining([ expect.objectContaining({ message: expect.arrayContaining([ @@ -1784,8 +1784,8 @@ describe('actions/IOU', () => { waitForCollectionCallback: true, callback: (allActions) => { Onyx.disconnect(connectionID); - const erroredAction = Object.values(allActions).find((action) => !_.isEmpty(action.errors)); - expect(Object.values(erroredAction.errors)).toEqual(expect.arrayContaining(['iou.error.other'])); + const erroredAction = _.find(_.values(allActions), (action) => !_.isEmpty(action.errors)); + expect(_.values(erroredAction.errors)).toEqual(expect.arrayContaining(['iou.error.other'])); resolve(); }, }); From 1bb71f6c68ba585147cbf8699e80f8780412bcb6 Mon Sep 17 00:00:00 2001 From: Sibtain Ali Date: Sun, 8 Oct 2023 12:14:36 +0500 Subject: [PATCH 3/9] feat: resolve conflicts --- tests/actions/IOUTest.js | 41 +++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/tests/actions/IOUTest.js b/tests/actions/IOUTest.js index fdb1e6db07b0..2a9d7cca5513 100644 --- a/tests/actions/IOUTest.js +++ b/tests/actions/IOUTest.js @@ -1395,6 +1395,10 @@ describe('actions/IOU', () => { const comment = '💸💸💸💸'; const merchant = 'NASDAQ'; + afterEach(() => { + fetch.resume(); + }); + it('updates the IOU request and IOU report when offline', () => { let thread = {}; let iouReport = {}; @@ -1403,10 +1407,10 @@ describe('actions/IOU', () => { fetch.pause(); IOU.requestMoney({}, amount, CONST.CURRENCY.USD, '', merchant, RORY_EMAIL, RORY_ACCOUNT_ID, {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, comment); - return waitForPromisesToResolve() + return waitForBatchedUpdates() .then(() => { Onyx.set(ONYXKEYS.SESSION, {email: RORY_EMAIL, accountID: RORY_ACCOUNT_ID}); - return waitForPromisesToResolve(); + return waitForBatchedUpdates(); }) .then( () => @@ -1456,11 +1460,11 @@ describe('actions/IOU', () => { .then(() => { thread = ReportUtils.buildTransactionThread(iouAction, iouReport.reportID); Onyx.set(`report_${thread.reportID}`, thread); - return waitForPromisesToResolve(); + return waitForBatchedUpdates(); }) .then(() => { IOU.editMoneyRequest(transaction.transactionID, thread.reportID, {amount: 20000, comment: 'Double the amount!'}); - return waitForPromisesToResolve(); + return waitForBatchedUpdates(); }) .then( () => @@ -1537,10 +1541,10 @@ describe('actions/IOU', () => { let transaction = {}; IOU.requestMoney({}, amount, CONST.CURRENCY.USD, '', merchant, RORY_EMAIL, RORY_ACCOUNT_ID, {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, comment); - return waitForPromisesToResolve() + return waitForBatchedUpdates() .then(() => { Onyx.set(ONYXKEYS.SESSION, {email: RORY_EMAIL, accountID: RORY_ACCOUNT_ID}); - return waitForPromisesToResolve(); + return waitForBatchedUpdates(); }) .then( () => @@ -1589,12 +1593,12 @@ describe('actions/IOU', () => { .then(() => { thread = ReportUtils.buildTransactionThread(iouAction, iouReport.reportID); Onyx.set(`report_${thread.reportID}`, thread); - return waitForPromisesToResolve(); + return waitForBatchedUpdates(); }) .then(() => { fetch.fail(); IOU.editMoneyRequest(transaction.transactionID, thread.reportID, {amount: 20000, comment: 'Double the amount!'}); - return waitForPromisesToResolve(); + return waitForBatchedUpdates(); }) .then( () => @@ -1665,16 +1669,20 @@ describe('actions/IOU', () => { const comment = '💸💸💸💸'; const merchant = 'NASDAQ'; + afterEach(() => { + fetch.resume(); + }); + it('updates the IOU request and IOU report when paid while offline', () => { let iouReport = {}; let chatReport = {}; fetch.pause(); IOU.requestMoney({}, amount, CONST.CURRENCY.USD, '', merchant, RORY_EMAIL, RORY_ACCOUNT_ID, {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, comment); - return waitForPromisesToResolve() + return waitForBatchedUpdates() .then(() => { Onyx.set(ONYXKEYS.SESSION, {email: RORY_EMAIL, accountID: RORY_ACCOUNT_ID}); - return waitForPromisesToResolve(); + return waitForBatchedUpdates(); }) .then( () => @@ -1694,7 +1702,7 @@ describe('actions/IOU', () => { ) .then(() => { IOU.payMoneyRequest(CONST.IOU.PAYMENT_TYPE.VBBA, chatReport, iouReport); - return waitForPromisesToResolve(); + return waitForBatchedUpdates(); }) .then( () => @@ -1756,9 +1764,6 @@ describe('actions/IOU', () => { }); }), ) - .then(() => { - fetch.resume(); - }); }); it('shows an error when paying results in an error', () => { @@ -1766,10 +1771,10 @@ describe('actions/IOU', () => { let chatReport = {}; IOU.requestMoney({}, amount, CONST.CURRENCY.USD, '', merchant, RORY_EMAIL, RORY_ACCOUNT_ID, {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, comment); - return waitForPromisesToResolve() + return waitForBatchedUpdates() .then(() => { Onyx.set(ONYXKEYS.SESSION, {email: RORY_EMAIL, accountID: RORY_ACCOUNT_ID}); - return waitForPromisesToResolve(); + return waitForBatchedUpdates(); }) .then( () => @@ -1790,7 +1795,7 @@ describe('actions/IOU', () => { .then(() => { fetch.fail(); IOU.payMoneyRequest('ACH', chatReport, iouReport); - return waitForPromisesToResolve(); + return waitForBatchedUpdates(); }) .then( () => @@ -1810,8 +1815,6 @@ describe('actions/IOU', () => { }); }); - - describe('deleteMoneyRequest', () => { const amount = 10000; const comment = 'Send me money please'; From c1701eee44d2818ed5616c1a26a268c440cc764d Mon Sep 17 00:00:00 2001 From: Sibtain Ali Date: Sun, 8 Oct 2023 12:25:14 +0500 Subject: [PATCH 4/9] fix: lint issues --- tests/actions/IOUTest.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/actions/IOUTest.js b/tests/actions/IOUTest.js index 2a9d7cca5513..baabb464e865 100644 --- a/tests/actions/IOUTest.js +++ b/tests/actions/IOUTest.js @@ -1390,7 +1390,7 @@ describe('actions/IOU', () => { }); }); - describe('edit requestMoney', () => { + describe('edit money request', () => { const amount = 10000; const comment = '💸💸💸💸'; const merchant = 'NASDAQ'; @@ -1763,7 +1763,7 @@ describe('actions/IOU', () => { }, }); }), - ) + ); }); it('shows an error when paying results in an error', () => { From 3b04dfd6bcf1f328a1c7a872ce164ebad8d00b63 Mon Sep 17 00:00:00 2001 From: Sibtain Ali Date: Sun, 8 Oct 2023 13:20:52 +0500 Subject: [PATCH 5/9] fix: handle comment suggestions --- tests/actions/IOUTest.js | 49 +++++++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/tests/actions/IOUTest.js b/tests/actions/IOUTest.js index baabb464e865..30d5301e293b 100644 --- a/tests/actions/IOUTest.js +++ b/tests/actions/IOUTest.js @@ -18,6 +18,7 @@ import * as User from '../../src/libs/actions/User'; import PusherHelper from '../utils/PusherHelper'; import Navigation from '../../src/libs/Navigation/Navigation'; import ROUTES from '../../src/ROUTES'; +import { createWorkspace } from '../../src/libs/actions/Policy'; jest.mock('../../src/libs/Navigation/Navigation', () => ({ navigate: jest.fn(), @@ -1492,6 +1493,7 @@ describe('actions/IOU', () => { callback: (allActions) => { Onyx.disconnect(connectionID); const updatedAction = _.find(allActions, (reportAction) => !_.isEmpty(reportAction)); + expect(updatedAction.actionName).toEqual("MODIFIEDEXPENSE"); expect(updatedAction.originalMessage).toEqual( expect.objectContaining({amount: 20000, newComment: 'Double the amount!', oldAmount: amount, oldComment: comment}), ); @@ -1627,6 +1629,7 @@ describe('actions/IOU', () => { callback: (allActions) => { Onyx.disconnect(connectionID); const updatedAction = _.find(allActions, (reportAction) => !_.isEmpty(reportAction)); + expect(updatedAction.actionName).toEqual("MODIFIEDEXPENSE"); expect(_.values(updatedAction.errors)).toEqual(expect.arrayContaining(['iou.error.genericEditFailureMessage'])); resolve(); }, @@ -1678,10 +1681,28 @@ describe('actions/IOU', () => { let chatReport = {}; fetch.pause(); - IOU.requestMoney({}, amount, CONST.CURRENCY.USD, '', merchant, RORY_EMAIL, RORY_ACCOUNT_ID, {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, comment); + Onyx.set(ONYXKEYS.SESSION, {email: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}); return waitForBatchedUpdates() .then(() => { - Onyx.set(ONYXKEYS.SESSION, {email: RORY_EMAIL, accountID: RORY_ACCOUNT_ID}); + createWorkspace(CARLOS_EMAIL, true, "Carlos's Workspace"); + return waitForBatchedUpdates(); + }) + .then(() => + new Promise((resolve) => { + const connectionID = Onyx.connect({ + key: ONYXKEYS.COLLECTION.REPORT, + waitForCollectionCallback: true, + callback: (allReports) => { + Onyx.disconnect(connectionID); + chatReport = _.find(allReports, (report) => report.chatType === CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT); + + resolve(); + }, + }); + }), + ) + .then(() => { + IOU.requestMoney(chatReport, amount, CONST.CURRENCY.USD, '', merchant, RORY_EMAIL, RORY_ACCOUNT_ID, {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, comment); return waitForBatchedUpdates(); }) .then( @@ -1693,7 +1714,6 @@ describe('actions/IOU', () => { callback: (allReports) => { Onyx.disconnect(connectionID); iouReport = _.find(allReports, (report) => report.type === CONST.REPORT.TYPE.IOU); - chatReport = _.find(allReports, (report) => report.type === CONST.REPORT.TYPE.CHAT); resolve(); }, @@ -1770,10 +1790,28 @@ describe('actions/IOU', () => { let iouReport = {}; let chatReport = {}; - IOU.requestMoney({}, amount, CONST.CURRENCY.USD, '', merchant, RORY_EMAIL, RORY_ACCOUNT_ID, {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, comment); + Onyx.set(ONYXKEYS.SESSION, {email: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}); return waitForBatchedUpdates() .then(() => { - Onyx.set(ONYXKEYS.SESSION, {email: RORY_EMAIL, accountID: RORY_ACCOUNT_ID}); + createWorkspace(CARLOS_EMAIL, true, "Carlos's Workspace"); + return waitForBatchedUpdates(); + }) + .then(() => + new Promise((resolve) => { + const connectionID = Onyx.connect({ + key: ONYXKEYS.COLLECTION.REPORT, + waitForCollectionCallback: true, + callback: (allReports) => { + Onyx.disconnect(connectionID); + chatReport = _.find(allReports, (report) => report.chatType === CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT); + + resolve(); + }, + }); + }), + ) + .then(() => { + IOU.requestMoney(chatReport, amount, CONST.CURRENCY.USD, '', merchant, RORY_EMAIL, RORY_ACCOUNT_ID, {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, comment); return waitForBatchedUpdates(); }) .then( @@ -1785,7 +1823,6 @@ describe('actions/IOU', () => { callback: (allReports) => { Onyx.disconnect(connectionID); iouReport = _.find(allReports, (report) => report.type === CONST.REPORT.TYPE.IOU); - chatReport = _.find(allReports, (report) => report.type === CONST.REPORT.TYPE.CHAT); resolve(); }, From b9d1a0af11d65b9b6a99a15493a4677c31e93fed Mon Sep 17 00:00:00 2001 From: Sibtain Ali Date: Sun, 8 Oct 2023 13:25:24 +0500 Subject: [PATCH 6/9] fix: lint issues --- tests/actions/IOUTest.js | 56 +++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/tests/actions/IOUTest.js b/tests/actions/IOUTest.js index 30d5301e293b..7bab881d2cf0 100644 --- a/tests/actions/IOUTest.js +++ b/tests/actions/IOUTest.js @@ -18,7 +18,7 @@ import * as User from '../../src/libs/actions/User'; import PusherHelper from '../utils/PusherHelper'; import Navigation from '../../src/libs/Navigation/Navigation'; import ROUTES from '../../src/ROUTES'; -import { createWorkspace } from '../../src/libs/actions/Policy'; +import {createWorkspace} from '../../src/libs/actions/Policy'; jest.mock('../../src/libs/Navigation/Navigation', () => ({ navigate: jest.fn(), @@ -1493,7 +1493,7 @@ describe('actions/IOU', () => { callback: (allActions) => { Onyx.disconnect(connectionID); const updatedAction = _.find(allActions, (reportAction) => !_.isEmpty(reportAction)); - expect(updatedAction.actionName).toEqual("MODIFIEDEXPENSE"); + expect(updatedAction.actionName).toEqual('MODIFIEDEXPENSE'); expect(updatedAction.originalMessage).toEqual( expect.objectContaining({amount: 20000, newComment: 'Double the amount!', oldAmount: amount, oldComment: comment}), ); @@ -1629,7 +1629,7 @@ describe('actions/IOU', () => { callback: (allActions) => { Onyx.disconnect(connectionID); const updatedAction = _.find(allActions, (reportAction) => !_.isEmpty(reportAction)); - expect(updatedAction.actionName).toEqual("MODIFIEDEXPENSE"); + expect(updatedAction.actionName).toEqual('MODIFIEDEXPENSE'); expect(_.values(updatedAction.errors)).toEqual(expect.arrayContaining(['iou.error.genericEditFailureMessage'])); resolve(); }, @@ -1687,19 +1687,20 @@ describe('actions/IOU', () => { createWorkspace(CARLOS_EMAIL, true, "Carlos's Workspace"); return waitForBatchedUpdates(); }) - .then(() => - new Promise((resolve) => { - const connectionID = Onyx.connect({ - key: ONYXKEYS.COLLECTION.REPORT, - waitForCollectionCallback: true, - callback: (allReports) => { - Onyx.disconnect(connectionID); - chatReport = _.find(allReports, (report) => report.chatType === CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT); + .then( + () => + new Promise((resolve) => { + const connectionID = Onyx.connect({ + key: ONYXKEYS.COLLECTION.REPORT, + waitForCollectionCallback: true, + callback: (allReports) => { + Onyx.disconnect(connectionID); + chatReport = _.find(allReports, (report) => report.chatType === CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT); - resolve(); - }, - }); - }), + resolve(); + }, + }); + }), ) .then(() => { IOU.requestMoney(chatReport, amount, CONST.CURRENCY.USD, '', merchant, RORY_EMAIL, RORY_ACCOUNT_ID, {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, comment); @@ -1796,19 +1797,20 @@ describe('actions/IOU', () => { createWorkspace(CARLOS_EMAIL, true, "Carlos's Workspace"); return waitForBatchedUpdates(); }) - .then(() => - new Promise((resolve) => { - const connectionID = Onyx.connect({ - key: ONYXKEYS.COLLECTION.REPORT, - waitForCollectionCallback: true, - callback: (allReports) => { - Onyx.disconnect(connectionID); - chatReport = _.find(allReports, (report) => report.chatType === CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT); + .then( + () => + new Promise((resolve) => { + const connectionID = Onyx.connect({ + key: ONYXKEYS.COLLECTION.REPORT, + waitForCollectionCallback: true, + callback: (allReports) => { + Onyx.disconnect(connectionID); + chatReport = _.find(allReports, (report) => report.chatType === CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT); - resolve(); - }, - }); - }), + resolve(); + }, + }); + }), ) .then(() => { IOU.requestMoney(chatReport, amount, CONST.CURRENCY.USD, '', merchant, RORY_EMAIL, RORY_ACCOUNT_ID, {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, comment); From 64c105344fc6ae0eb6a128d3d1d347fef37f2d59 Mon Sep 17 00:00:00 2001 From: Sibtain Ali Date: Sun, 8 Oct 2023 13:31:07 +0500 Subject: [PATCH 7/9] fix: more lint issues --- tests/actions/IOUTest.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/actions/IOUTest.js b/tests/actions/IOUTest.js index 7bab881d2cf0..4ada0fc5d98e 100644 --- a/tests/actions/IOUTest.js +++ b/tests/actions/IOUTest.js @@ -18,7 +18,7 @@ import * as User from '../../src/libs/actions/User'; import PusherHelper from '../utils/PusherHelper'; import Navigation from '../../src/libs/Navigation/Navigation'; import ROUTES from '../../src/ROUTES'; -import {createWorkspace} from '../../src/libs/actions/Policy'; +import * as PolicyActions from '../../src/libs/actions/Policy'; jest.mock('../../src/libs/Navigation/Navigation', () => ({ navigate: jest.fn(), @@ -1684,7 +1684,7 @@ describe('actions/IOU', () => { Onyx.set(ONYXKEYS.SESSION, {email: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}); return waitForBatchedUpdates() .then(() => { - createWorkspace(CARLOS_EMAIL, true, "Carlos's Workspace"); + PolicyActions.createWorkspace(CARLOS_EMAIL, true, "Carlos's Workspace"); return waitForBatchedUpdates(); }) .then( @@ -1794,7 +1794,7 @@ describe('actions/IOU', () => { Onyx.set(ONYXKEYS.SESSION, {email: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}); return waitForBatchedUpdates() .then(() => { - createWorkspace(CARLOS_EMAIL, true, "Carlos's Workspace"); + PolicyActions.createWorkspace(CARLOS_EMAIL, true, "Carlos's Workspace"); return waitForBatchedUpdates(); }) .then( From 9c2df995b6324eb371d92920dc5422f31785d72b Mon Sep 17 00:00:00 2001 From: Sibtain Ali Date: Sun, 22 Oct 2023 22:01:24 +0500 Subject: [PATCH 8/9] fix: remove duplicated policy utils import --- tests/actions/IOUTest.js | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/actions/IOUTest.js b/tests/actions/IOUTest.js index a8eae4a9388f..1dcd83d2add4 100644 --- a/tests/actions/IOUTest.js +++ b/tests/actions/IOUTest.js @@ -19,7 +19,6 @@ import * as User from '../../src/libs/actions/User'; import PusherHelper from '../utils/PusherHelper'; import Navigation from '../../src/libs/Navigation/Navigation'; import ROUTES from '../../src/ROUTES'; -import * as PolicyActions from '../../src/libs/actions/Policy'; jest.mock('../../src/libs/Navigation/Navigation', () => ({ navigate: jest.fn(), From c54734aae57a0d3a1dac26e75f4d85f28efda8af Mon Sep 17 00:00:00 2001 From: Sibtain Ali Date: Mon, 23 Oct 2023 00:06:24 +0500 Subject: [PATCH 9/9] fix: handle comment suggestions --- tests/actions/IOUTest.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/actions/IOUTest.js b/tests/actions/IOUTest.js index 1dcd83d2add4..71a5558e921e 100644 --- a/tests/actions/IOUTest.js +++ b/tests/actions/IOUTest.js @@ -1667,7 +1667,7 @@ describe('actions/IOU', () => { }); }); - describe('pay iou report via ACH', () => { + describe('pay expense report via ACH', () => { const amount = 10000; const comment = '💸💸💸💸'; const merchant = 'NASDAQ'; @@ -1676,8 +1676,8 @@ describe('actions/IOU', () => { fetch.resume(); }); - it('updates the IOU request and IOU report when paid while offline', () => { - let iouReport = {}; + it('updates the expense request and expense report when paid while offline', () => { + let expenseReport = {}; let chatReport = {}; fetch.pause(); @@ -1714,7 +1714,7 @@ describe('actions/IOU', () => { waitForCollectionCallback: true, callback: (allReports) => { Onyx.disconnect(connectionID); - iouReport = _.find(allReports, (report) => report.type === CONST.REPORT.TYPE.IOU); + expenseReport = _.find(allReports, (report) => report.type === CONST.REPORT.TYPE.IOU); resolve(); }, @@ -1722,14 +1722,14 @@ describe('actions/IOU', () => { }), ) .then(() => { - IOU.payMoneyRequest(CONST.IOU.PAYMENT_TYPE.VBBA, chatReport, iouReport); + IOU.payMoneyRequest(CONST.IOU.PAYMENT_TYPE.VBBA, chatReport, expenseReport); return waitForBatchedUpdates(); }) .then( () => new Promise((resolve) => { const connectionID = Onyx.connect({ - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReport.reportID}`, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport.reportID}`, waitForCollectionCallback: true, callback: (allActions) => { Onyx.disconnect(connectionID); @@ -1764,7 +1764,7 @@ describe('actions/IOU', () => { callback: (allReports) => { Onyx.disconnect(connectionID); const updatedIOUReport = _.find(allReports, (report) => report.type === CONST.REPORT.TYPE.IOU); - const updatedChatReport = _.find(allReports, (report) => report.reportID === iouReport.chatReportID); + const updatedChatReport = _.find(allReports, (report) => report.reportID === expenseReport.chatReportID); expect(updatedIOUReport).toEqual( expect.objectContaining({ lastMessageHtml: `paid $${amount / 100}.00 with Expensify`, @@ -1788,7 +1788,7 @@ describe('actions/IOU', () => { }); it('shows an error when paying results in an error', () => { - let iouReport = {}; + let expenseReport = {}; let chatReport = {}; Onyx.set(ONYXKEYS.SESSION, {email: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}); @@ -1824,7 +1824,7 @@ describe('actions/IOU', () => { waitForCollectionCallback: true, callback: (allReports) => { Onyx.disconnect(connectionID); - iouReport = _.find(allReports, (report) => report.type === CONST.REPORT.TYPE.IOU); + expenseReport = _.find(allReports, (report) => report.type === CONST.REPORT.TYPE.IOU); resolve(); }, @@ -1833,14 +1833,14 @@ describe('actions/IOU', () => { ) .then(() => { fetch.fail(); - IOU.payMoneyRequest('ACH', chatReport, iouReport); + IOU.payMoneyRequest('ACH', chatReport, expenseReport); return waitForBatchedUpdates(); }) .then( () => new Promise((resolve) => { const connectionID = Onyx.connect({ - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReport.reportID}`, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${expenseReport.reportID}`, waitForCollectionCallback: true, callback: (allActions) => { Onyx.disconnect(connectionID);