diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index ce35c39ff6c0..aa95baf25374 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -168,60 +168,60 @@ const personalDetails: PersonalDetailsList = { }, }; -// const rules = { -// approvalRules: [ -// { -// applyWhen: [ -// { -// condition: 'matches', -// field: 'category', -// value: 'cat1', -// }, -// ], -// approver: 'categoryapprover1@test.com', -// id: '1', -// }, -// { -// applyWhen: [ -// { -// condition: 'matches', -// field: 'tag', -// value: 'tag1', -// }, -// ], -// approver: 'tagapprover1@test.com', -// id: '2', -// }, -// { -// applyWhen: [ -// { -// condition: 'matches', -// field: 'category', -// value: 'cat2', -// }, -// ], -// approver: 'categoryapprover2@test.com', -// id: '3', -// }, -// { -// applyWhen: [ -// { -// condition: 'matches', -// field: 'tag', -// value: 'tag2', -// }, -// ], -// approver: 'tagapprover2@test.com', -// id: '4', -// }, -// ], -// }; +const rules = { + approvalRules: [ + { + applyWhen: [ + { + condition: 'matches', + field: 'category', + value: 'cat1', + }, + ], + approver: 'categoryapprover1@test.com', + id: '1', + }, + { + applyWhen: [ + { + condition: 'matches', + field: 'tag', + value: 'tag1', + }, + ], + approver: 'tagapprover1@test.com', + id: '2', + }, + { + applyWhen: [ + { + condition: 'matches', + field: 'category', + value: 'cat2', + }, + ], + approver: 'categoryapprover2@test.com', + id: '3', + }, + { + applyWhen: [ + { + condition: 'matches', + field: 'tag', + value: 'tag2', + }, + ], + approver: 'tagapprover2@test.com', + id: '4', + }, + ], +}; const employeeAccountID = 2; -// const categoryapprover1Email = 'categoryapprover1@test.com'; -// const categoryapprover2Email = 'categoryapprover2@test.com'; -// const tagapprover1Email = 'tagapprover1@test.com'; -// const tagapprover2Email = 'tagapprover2@test.com'; +const categoryapprover1Email = 'categoryapprover1@test.com'; +const categoryapprover2Email = 'categoryapprover2@test.com'; +const tagapprover1Email = 'tagapprover1@test.com'; +const tagapprover2Email = 'tagapprover2@test.com'; const policy: Policy = { id: '1', @@ -2304,112 +2304,110 @@ describe('ReportUtils', () => { }); // This test is broken, so I am commenting it out. I have opened up https://github.com/Expensify/App/issues/60854 to get the test fixed - // describe('has approver rule', () => { - // describe('has no transaction match with approver rule', () => { - // it('should return list contain submitsTo of ownerAccountID and the forwardsTo of them', () => { - // const policyTest: Policy = { - // ...createRandomPolicy(0), - // approver: 'owner@test.com', - // owner: 'owner@test.com', - // type: CONST.POLICY.TYPE.CORPORATE, - // employeeList, - // rules, - // approvalMode: CONST.POLICY.APPROVAL_MODE.BASIC, - // }; - // const expenseReport: Report = { - // ...createRandomReport(0), - // ownerAccountID: employeeAccountID, - // type: CONST.REPORT.TYPE.EXPENSE, - // }; - // const transaction1: Transaction = { - // ...createRandomTransaction(0), - // category: '', - // tag: '', - // created: testDate, - // reportID: expenseReport.reportID, - // }; - // const transaction2: Transaction = { - // ...createRandomTransaction(1), - // category: '', - // tag: '', - // created: DateUtils.subtractMillisecondsFromDateTime(testDate, 1), - // reportID: expenseReport.reportID, - // }; - // Onyx.multiSet({ - // [ONYXKEYS.PERSONAL_DETAILS_LIST]: personalDetails, - // [ONYXKEYS.COLLECTION.TRANSACTION]: { - // [transaction1.transactionID]: transaction1, - // [transaction2.transactionID]: transaction2, - // }, - // }).then(() => { - // const result = ['owner@test.com']; - // expect(getApprovalChain(policyTest, expenseReport)).toStrictEqual(result); - // }); - // }); - // }); - // describe('has transaction match with approver rule', () => { - // const policyTest: Policy = { - // ...createRandomPolicy(1), - // approver: 'owner@test.com', - // owner: 'owner@test.com', - // type: CONST.POLICY.TYPE.CORPORATE, - // employeeList, - // rules, - // approvalMode: CONST.POLICY.APPROVAL_MODE.ADVANCED, - // }; - // const expenseReport: Report = { - // ...createRandomReport(100), - // ownerAccountID: employeeAccountID, - // type: CONST.REPORT.TYPE.EXPENSE, - // }; - // const transaction1: Transaction = { - // ...createRandomTransaction(2), - // category: 'cat1', - // tag: '', - // created: testDate, - // reportID: expenseReport.reportID, - // inserted: DateUtils.subtractMillisecondsFromDateTime(testDate, 1), - // }; - // const transaction2: Transaction = { - // ...createRandomTransaction(3), - // category: '', - // tag: 'tag1', - // created: DateUtils.subtractMillisecondsFromDateTime(testDate, 1), - // reportID: expenseReport.reportID, - // inserted: DateUtils.subtractMillisecondsFromDateTime(testDate, 1), - // }; - // const transaction3: Transaction = { - // ...createRandomTransaction(4), - // category: 'cat2', - // tag: '', - // created: testDate, - // reportID: expenseReport.reportID, - // inserted: DateUtils.subtractMillisecondsFromDateTime(testDate, 2), - // }; - // const transaction4: Transaction = { - // ...createRandomTransaction(5), - // category: '', - // tag: 'tag2', - // created: DateUtils.subtractMillisecondsFromDateTime(testDate, 1), - // reportID: expenseReport.reportID, - // inserted: DateUtils.subtractMillisecondsFromDateTime(testDate, 2), - // }; - - // beforeAll(async () => { - // await Onyx.merge(ONYXKEYS.COLLECTION.TRANSACTION, { - // [transaction1.transactionID]: transaction1, - // [transaction2.transactionID]: transaction2, - // [transaction3.transactionID]: transaction3, - // [transaction4.transactionID]: transaction4, - // }); - // }); - - // it('should return the list with correct order of category/tag approver sorted by created/inserted of the transaction', () => { - // const result = [categoryapprover2Email, categoryapprover1Email, tagapprover2Email, tagapprover1Email, 'admin@test.com']; - // expect(getApprovalChain(policyTest, expenseReport)).toStrictEqual(result); - // }); - // }); - // }); + describe('has approver rule', () => { + describe('has no transaction match with approver rule', () => { + it('should return list contain submitsTo of ownerAccountID and the forwardsTo of them', () => { + const policyTest: Policy = { + ...createRandomPolicy(0), + approver: 'owner@test.com', + owner: 'owner@test.com', + type: CONST.POLICY.TYPE.CORPORATE, + employeeList, + rules, + approvalMode: CONST.POLICY.APPROVAL_MODE.BASIC, + }; + const expenseReport: Report = { + ...createRandomReport(0), + ownerAccountID: employeeAccountID, + type: CONST.REPORT.TYPE.EXPENSE, + }; + const transaction1: Transaction = { + ...createRandomTransaction(0), + category: '', + tag: '', + created: testDate, + reportID: expenseReport.reportID, + }; + const transaction2: Transaction = { + ...createRandomTransaction(1), + category: '', + tag: '', + created: DateUtils.subtractMillisecondsFromDateTime(testDate, 1), + reportID: expenseReport.reportID, + }; + Onyx.multiSet({ + [ONYXKEYS.PERSONAL_DETAILS_LIST]: personalDetails, + [ONYXKEYS.COLLECTION.TRANSACTION]: { + [transaction1.transactionID]: transaction1, + [transaction2.transactionID]: transaction2, + }, + }).then(() => { + const result = ['owner@test.com']; + expect(getApprovalChain(policyTest, expenseReport)).toStrictEqual(result); + }); + }); + }); + describe('has transaction match with approver rule', () => { + it('should return the list with correct order of category/tag approver sorted by created/inserted of the transaction', () => { + const policyTest: Policy = { + ...createRandomPolicy(1), + approver: 'owner@test.com', + owner: 'owner@test.com', + type: CONST.POLICY.TYPE.CORPORATE, + employeeList, + rules, + approvalMode: CONST.POLICY.APPROVAL_MODE.ADVANCED, + }; + const expenseReport: Report = { + ...createRandomReport(100), + ownerAccountID: employeeAccountID, + type: CONST.REPORT.TYPE.EXPENSE, + }; + const transaction1: Transaction = { + ...createRandomTransaction(1), + category: 'cat1', + tag: '', + created: testDate, + reportID: expenseReport.reportID, + inserted: DateUtils.subtractMillisecondsFromDateTime(testDate, 1), + }; + const transaction2: Transaction = { + ...createRandomTransaction(2), + category: '', + tag: 'tag1', + created: DateUtils.subtractMillisecondsFromDateTime(testDate, 1), + reportID: expenseReport.reportID, + inserted: DateUtils.subtractMillisecondsFromDateTime(testDate, 1), + }; + const transaction3: Transaction = { + ...createRandomTransaction(3), + category: 'cat2', + tag: '', + created: testDate, + reportID: expenseReport.reportID, + inserted: DateUtils.subtractMillisecondsFromDateTime(testDate, 2), + }; + const transaction4: Transaction = { + ...createRandomTransaction(4), + category: '', + tag: 'tag2', + created: DateUtils.subtractMillisecondsFromDateTime(testDate, 1), + reportID: expenseReport.reportID, + inserted: DateUtils.subtractMillisecondsFromDateTime(testDate, 2), + }; + + Onyx.mergeCollection(ONYXKEYS.COLLECTION.TRANSACTION, { + transactions_1: transaction1, + transactions_2: transaction2, + transactions_3: transaction3, + transactions_4: transaction4, + }).then(() => { + const result = [categoryapprover2Email, categoryapprover1Email, tagapprover2Email, tagapprover1Email, 'admin@test.com']; + expect(getApprovalChain(policyTest, expenseReport)).toStrictEqual(result); + }); + }); + }); + }); }); });