From 02316f3d0a71878e7e955e27c71fc8a246ec1154 Mon Sep 17 00:00:00 2001 From: Gandalf Date: Wed, 23 Oct 2024 17:56:59 +0530 Subject: [PATCH 1/4] add unit test for automatically approved expense --- package.json | 1 + tests/unit/ReportUtilsTest.ts | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/package.json b/package.json index b5e950df4151..e14d24eebcb2 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "ios-build": "bundle exec fastlane ios build_unsigned", "android-build": "bundle exec fastlane android build_local", "test": "TZ=utc NODE_OPTIONS=--experimental-vm-modules jest", + "test:unit": "TZ=utc NODE_OPTIONS=--experimental-vm-modules jest tests/unit/ReportUtilsTest.ts", "typecheck": "NODE_OPTIONS=--max_old_space_size=8192 tsc", "lint": "NODE_OPTIONS=--max_old_space_size=8192 eslint . --max-warnings=0 --cache --cache-location=node_modules/.cache/eslint", "lint-changed": "NODE_OPTIONS=--max_old_space_size=8192 eslint --max-warnings=0 --config ./.eslintrc.changed.js $(git diff --diff-filter=AM --name-only origin/main HEAD -- \"*.ts\" \"*.tsx\")", diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index e4eee7241d80..3c4215a79bd0 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -294,6 +294,29 @@ describe('ReportUtils', () => { }); }); + describe('Automatically approved report message is', () => { + test('Automatically Approved Report message', () => { + const threadOfSubmittedReportAction = { + ...LHNTestUtils.getFakeReport(), + type: CONST.REPORT.TYPE.EXPENSE, + stateNum: CONST.REPORT.STATE_NUM.APPROVED, + statusNum: CONST.REPORT.STATUS_NUM.APPROVED, + parentReportID: '101', + policyID: policy.id, + }; + const submittedParentReportAction = { + actionName: CONST.REPORT.ACTIONS.TYPE.APPROVED, + originalMessage: { + amount: 169, + currency: 'USD', + automaticAction: true, + }, + } as ReportAction; + + expect(ReportUtils.getReportName(threadOfSubmittedReportAction, policy, submittedParentReportAction)).toBe('automatically approved $1.69 via workspace rules'); + }) + }) + describe('requiresAttentionFromCurrentUser', () => { afterEach(async () => { await Onyx.clear(); From 7270293858ad00793c5b11cd3696b472528e72cf Mon Sep 17 00:00:00 2001 From: Gandalf Date: Wed, 23 Oct 2024 18:08:46 +0530 Subject: [PATCH 2/4] add unit test --- tests/unit/ReportUtilsTest.ts | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 3c4215a79bd0..4052a5983995 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -294,7 +294,7 @@ describe('ReportUtils', () => { }); }); - describe('Automatically approved report message is', () => { + describe('Automatically approved report message via automatic action is', () => { test('Automatically Approved Report message', () => { const threadOfSubmittedReportAction = { ...LHNTestUtils.getFakeReport(), @@ -314,8 +314,31 @@ describe('ReportUtils', () => { } as ReportAction; expect(ReportUtils.getReportName(threadOfSubmittedReportAction, policy, submittedParentReportAction)).toBe('automatically approved $1.69 via workspace rules'); - }) - }) + }); + }); + + describe('Automatically approved report message via harvesting is', () => { + test('Automatically Approved Report message', () => { + const threadOfSubmittedReportAction = { + ...LHNTestUtils.getFakeReport(), + type: CONST.REPORT.TYPE.EXPENSE, + stateNum: CONST.REPORT.STATE_NUM.APPROVED, + statusNum: CONST.REPORT.STATUS_NUM.APPROVED, + parentReportID: '101', + policyID: policy.id, + }; + const submittedParentReportAction = { + actionName: CONST.REPORT.ACTIONS.TYPE.APPROVED, + originalMessage: { + amount: 169, + currency: 'USD', + harvesting: true, + }, + } as ReportAction; + + expect(ReportUtils.getReportName(threadOfSubmittedReportAction, policy, submittedParentReportAction)).toBe('approved $1.69'); + }); + }); describe('requiresAttentionFromCurrentUser', () => { afterEach(async () => { From 7d7df77f63800a8902ebafae23839172517b8278 Mon Sep 17 00:00:00 2001 From: Gandalf Date: Wed, 23 Oct 2024 18:46:45 +0530 Subject: [PATCH 3/4] add more test cases and fix test params --- tests/unit/ReportUtilsTest.ts | 39 +++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 4052a5983995..fef97f6c9fff 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -294,8 +294,8 @@ describe('ReportUtils', () => { }); }); - describe('Automatically approved report message via automatic action is', () => { - test('Automatically Approved Report message', () => { + describe('Automatically approved report message via automatic (not by a human) action is', () => { + test('Automatically Approved Report message when report is approved and forwarded (Control feature)', () => { const threadOfSubmittedReportAction = { ...LHNTestUtils.getFakeReport(), type: CONST.REPORT.TYPE.EXPENSE, @@ -305,7 +305,7 @@ describe('ReportUtils', () => { policyID: policy.id, }; const submittedParentReportAction = { - actionName: CONST.REPORT.ACTIONS.TYPE.APPROVED, + actionName: CONST.REPORT.ACTIONS.TYPE.FORWARDED, originalMessage: { amount: 169, currency: 'USD', @@ -317,18 +317,39 @@ describe('ReportUtils', () => { }); }); - describe('Automatically approved report message via harvesting is', () => { - test('Automatically Approved Report message', () => { + describe('Automatically approved report message via harvesting (delayed submit) is', () => { + test('Automatically Approved Report message for report type submitted and status is submitted', () => { const threadOfSubmittedReportAction = { ...LHNTestUtils.getFakeReport(), type: CONST.REPORT.TYPE.EXPENSE, - stateNum: CONST.REPORT.STATE_NUM.APPROVED, - statusNum: CONST.REPORT.STATUS_NUM.APPROVED, + stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, + statusNum: CONST.REPORT.STATUS_NUM.SUBMITTED, + parentReportID: '101', + policyID: policy.id, + }; + const submittedParentReportAction = { + actionName: CONST.REPORT.ACTIONS.TYPE.SUBMITTED, + originalMessage: { + amount: 169, + currency: 'USD', + harvesting: true, + }, + } as ReportAction; + + expect(ReportUtils.getReportName(threadOfSubmittedReportAction, policy, submittedParentReportAction)).toBe('automatically submitted $1.69 via delayed submission'); + }); + + test('Automatically Approved Report message for report type submitted and status is closed', () => { + const threadOfSubmittedReportAction = { + ...LHNTestUtils.getFakeReport(), + type: CONST.REPORT.TYPE.EXPENSE, + stateNum: CONST.REPORT.STATE_NUM.SUBMITTED, + statusNum: CONST.REPORT.STATUS_NUM.CLOSED, parentReportID: '101', policyID: policy.id, }; const submittedParentReportAction = { - actionName: CONST.REPORT.ACTIONS.TYPE.APPROVED, + actionName: CONST.REPORT.ACTIONS.TYPE.SUBMITTED_AND_CLOSED, originalMessage: { amount: 169, currency: 'USD', @@ -336,7 +357,7 @@ describe('ReportUtils', () => { }, } as ReportAction; - expect(ReportUtils.getReportName(threadOfSubmittedReportAction, policy, submittedParentReportAction)).toBe('approved $1.69'); + expect(ReportUtils.getReportName(threadOfSubmittedReportAction, policy, submittedParentReportAction)).toBe('automatically submitted $1.69 via delayed submission'); }); }); From f333ee5f54eebfc8c70f4b422cc655f11df2e23c Mon Sep 17 00:00:00 2001 From: Gandalf Date: Wed, 23 Oct 2024 18:55:48 +0530 Subject: [PATCH 4/4] add new test case for approved automaticAction --- tests/unit/ReportUtilsTest.ts | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index fef97f6c9fff..b5e7bce2383e 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -295,7 +295,7 @@ describe('ReportUtils', () => { }); describe('Automatically approved report message via automatic (not by a human) action is', () => { - test('Automatically Approved Report message when report is approved and forwarded (Control feature)', () => { + test('Automatically Approved Report message when report is forwarded (Control feature)', () => { const threadOfSubmittedReportAction = { ...LHNTestUtils.getFakeReport(), type: CONST.REPORT.TYPE.EXPENSE, @@ -315,6 +315,27 @@ describe('ReportUtils', () => { expect(ReportUtils.getReportName(threadOfSubmittedReportAction, policy, submittedParentReportAction)).toBe('automatically approved $1.69 via workspace rules'); }); + + test('Automatically Approved Report message when report is approved', () => { + const threadOfSubmittedReportAction = { + ...LHNTestUtils.getFakeReport(), + type: CONST.REPORT.TYPE.EXPENSE, + stateNum: CONST.REPORT.STATE_NUM.APPROVED, + statusNum: CONST.REPORT.STATUS_NUM.APPROVED, + parentReportID: '101', + policyID: policy.id, + }; + const submittedParentReportAction = { + actionName: CONST.REPORT.ACTIONS.TYPE.APPROVED, + originalMessage: { + amount: 169, + currency: 'USD', + automaticAction: true, + }, + } as ReportAction; + + expect(ReportUtils.getReportName(threadOfSubmittedReportAction, policy, submittedParentReportAction)).toBe('automatically approved $1.69 via workspace rules'); + }); }); describe('Automatically approved report message via harvesting (delayed submit) is', () => {