From 22d9ec83a21d81226ef7819e0919a6c41e916462 Mon Sep 17 00:00:00 2001 From: Suyash Patil <127177049+suyashpatil78@users.noreply.github.com> Date: Mon, 26 Feb 2024 11:18:18 +0530 Subject: [PATCH] feat: removal of old split code - Part 2 (#2770) * feat: removal of old split code - Part 2 * feat: removal of old split code - Part 3 (#2771) * feat: removal of old split code - Part 3 * feat: removal of old split code - Part 4 (#2772) * feat: removal of old split code - Part 4 * feat: removal of old split code - Part 5 (#2773) * feat: removal of old split code - Part 5 * feat: removal of old split code - Part 6 (#2774) * feat: removal of old split code - Part 6 * feat: removal of old split code - Part 7 (#2775) * feat: removal of old split code - Part 7 * feat: removal of old split code - Part 8 (#2776) * feat: removal of old split code - Part 8 * feat: removal of old split code - Part 9 (#2777) * feat: removal of old split code - Part 9 * feat: removal of old split code - Part 10 (#2778) * feat: removal of old split code - Part 10 * feat: removal of old split code - Part 11 (#2779) * feat: removal of old split code - Part 11 * karma ignore * feat: removal of old split code - Part 12 (#2780) * feat: removal of old split code - Part 12 * feat: removal of old split code - Part 14 (#2781) * feat: removal of old split code - Part 14 * minor --- .../services/split-expense.service.spec.ts | 275 ----------- .../core/services/split-expense.service.ts | 188 +------- .../split-expense/split-expense.page.spec.ts | 449 +----------------- .../fyle/split-expense/split-expense.page.ts | 76 --- ...expense-policy-violation.component.spec.ts | 9 - 5 files changed, 7 insertions(+), 990 deletions(-) diff --git a/src/app/core/services/split-expense.service.spec.ts b/src/app/core/services/split-expense.service.spec.ts index cee2192a42..782074a5d4 100644 --- a/src/app/core/services/split-expense.service.spec.ts +++ b/src/app/core/services/split-expense.service.spec.ts @@ -166,56 +166,6 @@ describe('SplitExpenseService', () => { expect(splitExpenseService).toBeTruthy(); }); - describe('linkTxnWithFiles():', () => { - it('should link transactions with files', (done) => { - transactionService.uploadBase64File - .withArgs(fileTxns.txns[0].id, fileTxns.files[0].name, fileTxns.files[0].content) - .and.returnValue(of(splitExpFile2)); - transactionService.uploadBase64File - .withArgs(fileTxns.txns[1].id, fileTxns.files[0].name, fileTxns.files[0].content) - .and.returnValue(of(splitExpFile3)); - - splitExpenseService.linkTxnWithFiles(fileTxns).subscribe((res) => { - expect(res).toEqual([splitExpFile2, splitExpFile3]); - expect(transactionService.uploadBase64File).toHaveBeenCalledWith( - fileTxns.txns[0].id, - fileTxns.files[0].name, - fileTxns.files[0].content - ); - expect(transactionService.uploadBase64File).toHaveBeenCalledWith( - fileTxns.txns[1].id, - fileTxns.files[0].name, - fileTxns.files[0].content - ); - expect(transactionService.uploadBase64File).toHaveBeenCalledTimes(2); - done(); - }); - }); - - it('should return null if no files are present', (done) => { - splitExpenseService.linkTxnWithFiles({ ...fileTxns, files: null }).subscribe((res) => { - expect(res).toEqual([null]); - done(); - }); - }); - }); - - it('getBase64Content(): should get base 64 string of txn files', (done) => { - fileService.base64Download.withArgs(splitExpFileObj[0].id).and.returnValue(of({ content: 'base64encodedcontent' })); - - splitExpenseService.getBase64Content(splitExpFileObj).subscribe((res) => { - expect(res).toEqual([ - { - id: 'fijCeF0G0jTl', - name: '000.jpeg', - content: 'base64encodedcontent', - }, - ]); - expect(fileService.base64Download).toHaveBeenCalledOnceWith(splitExpFileObj[0].id); - done(); - }); - }); - it('postComment(): should post a comment', (done) => { statusService.post.and.returnValue(of(txnStatusData)); @@ -231,25 +181,6 @@ describe('SplitExpenseService', () => { }); }); - it('postCommentsFromUsers(): should post comments from users', (done) => { - const postCommentSpy = spyOn(splitExpenseService, 'postComment'); - postCommentSpy.withArgs(violationComment2).and.returnValue(of(txnStatusData1)); - postCommentSpy.withArgs(violationComment3).and.returnValue(of(txnStatusData2)); - - splitExpenseService - .postCommentsFromUsers(['txxkBruL0EO9', 'txNVtsqF8Siq'], { - txxkBruL0EO9: 'another comment', - txNVtsqF8Siq: '', - }) - .subscribe((res) => { - expect(res).toEqual([txnStatusData1, txnStatusData2]); - expect(postCommentSpy).toHaveBeenCalledWith(violationComment2); - expect(postCommentSpy).toHaveBeenCalledWith(violationComment3); - expect(postCommentSpy).toHaveBeenCalledTimes(2); - done(); - }); - }); - describe('formatDisplayName(): ', () => { it('should get display name from list of categories', () => { categoriesService.filterByOrgCategoryId.and.returnValue(transformedOrgCategories[0]); @@ -359,212 +290,6 @@ describe('SplitExpenseService', () => { }); }); - it('checkPolicyForTransaction(): should check policy for a transaction', (done) => { - policyService.transformTo.and.returnValue(splitExpensePolicyExp); - transactionService.checkPolicy.and.returnValue(of(splitExpPolicyData)); - - splitExpenseService.checkPolicyForTransaction(splitPolicyExp).subscribe((res) => { - expect(res).toEqual({ - txqhb1IwrujH: policyViolation1, - }); - expect(policyService.transformTo).toHaveBeenCalledOnceWith(splitPolicyExp); - expect(transactionService.checkPolicy).toHaveBeenCalledOnceWith(splitExpensePolicyExp); - done(); - }); - }); - - it('checkPolicyForTransactions(): should check policy for multiple transactions', (done) => { - spyOn(splitExpenseService, 'checkPolicyForTransaction').and.returnValue( - of({ - txqhb1IwrujH: policyViolation1, - }) - ); - - splitExpenseService.checkPolicyForTransactions([splitPolicyExp]).subscribe((res) => { - expect(res).toEqual({ - txqhb1IwrujH: policyViolation1, - }); - expect(splitExpenseService.checkPolicyForTransaction).toHaveBeenCalledOnceWith(splitPolicyExp); - done(); - }); - }); - - describe('mapViolationDataWithEtxn(): ', () => { - beforeEach(() => { - const formatDisplayNameSpy = spyOn(splitExpenseService, 'formatDisplayName'); - formatDisplayNameSpy.and.returnValue('Food / Travelling - Inland'); - }); - it('should map violation data with expenses', () => { - expect( - splitExpenseService.mapViolationDataWithEtxn(policyVoilationData2, splitExpData, transformedOrgCategories) - ).toEqual(policyVoilationData2); - expect(splitExpenseService.formatDisplayName).toHaveBeenCalledWith( - splitExpData[0].tx_org_category_id, - transformedOrgCategories - ); - expect(splitExpenseService.formatDisplayName).toHaveBeenCalledWith( - splitExpData[1].tx_org_category_id, - transformedOrgCategories - ); - expect(splitExpenseService.formatDisplayName).toHaveBeenCalledTimes(2); - }); - it('should map violation data with expenses', () => { - const { tx_orig_amount, tx_orig_currency, ...newSplitData } = splitExpData[0]; - - expect( - splitExpenseService.mapViolationDataWithEtxn(policyVoilationData2, [newSplitData], transformedOrgCategories) - ).toEqual(policyVoilationData2); - expect(splitExpenseService.formatDisplayName).toHaveBeenCalledOnceWith( - newSplitData.tx_org_category_id, - transformedOrgCategories - ); - }); - it('should not map violation data with expenses if tx_id is undefined', () => { - expect( - splitExpenseService.mapViolationDataWithEtxn(policyVoilationData2, [undefined], transformedOrgCategories) - ).toEqual(policyVoilationData2); - expect(splitExpenseService.formatDisplayName).not.toHaveBeenCalled(); - }); - }); - - it('formatPolicyViolations(): should format policy violations', () => { - policyService.getPolicyRules.and.returnValue(criticalPolicyViolation1); - policyService.getCriticalPolicyRules.and.returnValue(criticalPolicyViolation2); - - expect(splitExpenseService.formatPolicyViolations(policyViolationData3)).toEqual(formattedTxnViolations); - expect(policyService.getPolicyRules).toHaveBeenCalledWith(policyViolationData3.txc2KIogxUAy); - expect(policyService.getPolicyRules).toHaveBeenCalledWith(policyViolationData3.txgfkvuYteta); - expect(policyService.getPolicyRules).toHaveBeenCalledTimes(2); - expect(policyService.getCriticalPolicyRules).toHaveBeenCalledWith(policyViolationData3.txc2KIogxUAy); - expect(policyService.getCriticalPolicyRules).toHaveBeenCalledWith(policyViolationData3.txgfkvuYteta); - expect(policyService.getCriticalPolicyRules).toHaveBeenCalledTimes(2); - }); - - it('formatPolicyViolations(): should format policy violations without critical policy violations', () => { - policyService.getPolicyRules.and.returnValue(criticalPolicyViolation1); - policyService.getCriticalPolicyRules.and.returnValue(null); - - expect(splitExpenseService.formatPolicyViolations(policyViolationData3)).toEqual(formattedTxnViolations2); - expect(policyService.getPolicyRules).toHaveBeenCalledWith(policyViolationData3.txc2KIogxUAy); - expect(policyService.getPolicyRules).toHaveBeenCalledWith(policyViolationData3.txgfkvuYteta); - expect(policyService.getPolicyRules).toHaveBeenCalledTimes(2); - expect(policyService.getCriticalPolicyRules).toHaveBeenCalledWith(policyViolationData3.txc2KIogxUAy); - expect(policyService.getCriticalPolicyRules).toHaveBeenCalledWith(policyViolationData3.txgfkvuYteta); - expect(policyService.getCriticalPolicyRules).toHaveBeenCalledTimes(2); - }); - - describe('runPolicyCheck():', () => { - it('should run policy check on expenses', (done) => { - dataTransformService.unflatten.withArgs(splitExpData2[0]).and.returnValue(unflattenExp1); - dataTransformService.unflatten.withArgs(splitExpData2[1]).and.returnValue(unflattenExp2); - - spyOn(splitExpenseService, 'checkPolicyForTransactions').and.returnValue(of(policyViolationData4)); - - splitExpenseService.runPolicyCheck(splitExpData2, fileObject4).subscribe((res) => { - expect(res).toEqual(policyViolationData4); - expect(dataTransformService.unflatten).toHaveBeenCalledWith(splitExpData2[0]); - expect(dataTransformService.unflatten).toHaveBeenCalledWith(splitExpData2[1]); - expect(dataTransformService.unflatten).toHaveBeenCalledTimes(2); - expect(splitExpenseService.checkPolicyForTransactions).toHaveBeenCalledOnceWith([ - unflattenExp1.tx, - unflattenExp2.tx, - ]); - done(); - }); - }); - - it('should return empty object when no expenses are provided', (done) => { - splitExpenseService.runPolicyCheck([], fileObject4).subscribe((res) => { - expect(res).toEqual({}); - done(); - }); - }); - - it('should run policy check on expenses when files are not present', (done) => { - dataTransformService.unflatten.withArgs(splitExpData2[0]).and.returnValue(unflattenExp1); - dataTransformService.unflatten.withArgs(splitExpData2[1]).and.returnValue(unflattenExp2); - - spyOn(splitExpenseService, 'checkPolicyForTransactions').and.returnValue(of(policyViolationData4)); - - splitExpenseService.runPolicyCheck(splitExpData2, []).subscribe((res) => { - expect(res).toEqual(policyViolationData4); - expect(dataTransformService.unflatten).toHaveBeenCalledWith(splitExpData2[0]); - expect(dataTransformService.unflatten).toHaveBeenCalledWith(splitExpData2[1]); - expect(dataTransformService.unflatten).toHaveBeenCalledTimes(2); - expect(splitExpenseService.checkPolicyForTransactions).toHaveBeenCalledOnceWith([ - unflattenExp1.tx, - unflattenExp2.tx, - ]); - done(); - }); - }); - - it('should run policy check on expenses when files and user_amount are not defined', (done) => { - const mockUnflattenExp1 = cloneDeep(unflattenExp1); - mockUnflattenExp1.tx.user_amount = undefined; - dataTransformService.unflatten.withArgs(splitExpData2[0]).and.returnValue(mockUnflattenExp1); - dataTransformService.unflatten.withArgs(splitExpData2[1]).and.returnValue(unflattenExp2); - - spyOn(splitExpenseService, 'checkPolicyForTransactions').and.returnValue(of(policyViolationData4)); - - splitExpenseService.runPolicyCheck(splitExpData2, undefined).subscribe((res) => { - expect(res).toEqual(policyViolationData4); - expect(dataTransformService.unflatten).toHaveBeenCalledWith(splitExpData2[0]); - expect(dataTransformService.unflatten).toHaveBeenCalledWith(splitExpData2[1]); - expect(dataTransformService.unflatten).toHaveBeenCalledTimes(2); - expect(splitExpenseService.checkPolicyForTransactions).toHaveBeenCalledOnceWith([ - mockUnflattenExp1.tx, - unflattenExp2.tx, - ]); - done(); - }); - }); - - it('should return empty object when expenses are undefined', (done) => { - splitExpenseService.runPolicyCheck(undefined, fileObject4).subscribe((res) => { - expect(res).toEqual({}); - done(); - }); - }); - }); - - it('executePolicyCheck(): should execute policy check', (done) => { - spyOn(splitExpenseService, 'runPolicyCheck').and.returnValue(of(policyViolationData4)); - spyOn(splitExpenseService, 'mapViolationDataWithEtxn').and.returnValue(policyViolationData4); - - splitExpenseService.executePolicyCheck(splitExpData2, fileObject4, transformedOrgCategories).subscribe((res) => { - expect(res).toEqual(policyViolationData4); - expect(splitExpenseService.runPolicyCheck).toHaveBeenCalledOnceWith(splitExpData2, fileObject4); - expect(splitExpenseService.mapViolationDataWithEtxn).toHaveBeenCalledOnceWith( - policyViolationData4, - splitExpData2, - transformedOrgCategories - ); - done(); - }); - }); - - it('checkForPolicyViolations(): check for policy violations', (done) => { - transactionService.getEtxn.withArgs(splitExpData2[0].tx_id).and.returnValue(of(splitExpData2[0])); - transactionService.getEtxn.withArgs(splitExpData2[1].tx_id).and.returnValue(of(splitExpData2[1])); - spyOn(splitExpenseService, 'executePolicyCheck').and.returnValue(of(policyViolationData4)); - - splitExpenseService - .checkForPolicyViolations([splitExpData2[0].tx_id, splitExpData2[1].tx_id], fileObject4, transformedOrgCategories) - .subscribe((res) => { - expect(res).toEqual(policyViolationData4); - expect(transactionService.getEtxn).toHaveBeenCalledWith(splitExpData2[0].tx_id); - expect(transactionService.getEtxn).toHaveBeenCalledWith(splitExpData2[1].tx_id); - expect(transactionService.getEtxn).toHaveBeenCalledTimes(2); - expect(splitExpenseService.executePolicyCheck).toHaveBeenCalledOnceWith( - [splitExpData2[0], splitExpData2[1]], - fileObject4, - transformedOrgCategories - ); - done(); - }); - }); - describe('createTxns(): ', () => { beforeEach(() => { spyOn(splitExpenseService, 'setUpSplitExpenseBillable').and.returnValue(true); diff --git a/src/app/core/services/split-expense.service.ts b/src/app/core/services/split-expense.service.ts index e21cd3e94b..737b95115b 100644 --- a/src/app/core/services/split-expense.service.ts +++ b/src/app/core/services/split-expense.service.ts @@ -1,13 +1,9 @@ import { Injectable } from '@angular/core'; import { forkJoin, from, Observable, of } from 'rxjs'; -import { concatMap, map, reduce, switchMap, toArray } from 'rxjs/operators'; -import { Expense } from '../models/expense.model'; +import { concatMap, toArray } from 'rxjs/operators'; import { FileObject } from '../models/file-obj.model'; -import { FileTransaction } from '../models/file-txn.model'; -import { FormattedPolicyViolation } from '../models/formatted-policy-violation.model'; import { PolicyViolationComment } from '../models/policy-violation-comment.model'; import { PolicyViolation } from '../models/policy-violation.model'; -import { PublicPolicyExpense } from '../models/public-policy-expense.model'; import { TransactionStatus } from '../models/transaction-status.model'; import { OrgCategory } from '../models/v1/org-category.model'; import { Transaction } from '../models/v1/transaction.model'; @@ -17,7 +13,6 @@ import { FileService } from './file.service'; import { PolicyService } from './policy.service'; import { StatusService } from './status.service'; import { TransactionService } from './transaction.service'; -import { PolicyViolationTxn } from '../models/policy-violation-txn.model'; import { UtilityService } from './utility.service'; import { ExpensesService } from './platform/v1/spender/expenses.service'; import { ExpenseField } from '../models/v1/expense-field.model'; @@ -49,196 +44,15 @@ export class SplitExpenseService { private expensesService: ExpensesService ) {} - linkTxnWithFiles(data: Partial): Observable { - const observables = []; - const files = data.files; - const txns = data.txns; - - if (files && files.length > 0) { - files.forEach((file) => { - txns.forEach((txn) => { - observables.push(this.transactionService.uploadBase64File(txn.id, file.name, file.content)); - }); - }); - } else { - observables.push(of(null)); - } - - return forkJoin(observables); - } - - getBase64Content(fileObjs: FileObject[]): Observable { - const fileObservables: Observable<{ content: string }>[] = []; - const newFileObjs: FileObject[] = fileObjs.map((fileObj) => ({ - id: fileObj.id, - name: fileObj.name, - content: '', - })); - - newFileObjs.forEach((fileObj) => { - fileObservables.push(this.fileService.base64Download(fileObj.id)); - }); - - return forkJoin(fileObservables).pipe( - map((data) => { - newFileObjs.forEach((fileObj: FileObject, index) => { - fileObj.content = data[index].content; - }); - - return newFileObjs; - }) - ); - } - - checkPolicyForTransaction(etxn: PublicPolicyExpense): Observable { - const policyResponse = {}; - - /* - Expense creation has not moved to platform yet and since policy is moved to platform, - it expects the expense object in terms of platform world. Until then, the method - `transformTo` act as a bridge by translating the public expense object to platform - expense. - */ - const platformPolicyExpense = this.policyService.transformTo(etxn); - return this.transactionService.checkPolicy(platformPolicyExpense).pipe( - map((policyViolationresponse) => { - policyResponse[etxn.id] = policyViolationresponse; - return policyResponse; - }) - ); - } - postComment(apiPayload: PolicyViolationComment): Observable { return this.statusService.post(apiPayload.objectType, apiPayload.txnId, apiPayload.comment, apiPayload.notify); } - postCommentsFromUsers( - transactionIDs: string[], - comments: { [transactionID: string]: string } - ): Observable { - const payloadData = []; - transactionIDs.forEach((transactionID) => { - const comment = - comments[transactionID] && comments[transactionID] !== '' - ? this.prependPolicyViolationMessage + comments[transactionID] - : this.defaultPolicyViolationMessage; - const apiPayload = { - objectType: 'transactions', - txnId: transactionID, - comment: { comment }, - notify: true, - }; - payloadData.push(apiPayload); - }); - - return from(payloadData).pipe( - concatMap((payload: PolicyViolationComment) => this.postComment(payload)), - toArray() - ); - } - - formatPolicyViolations(violations: PolicyViolationTxn): { - [transactionID: string]: FormattedPolicyViolation; - } { - const formattedViolations = {}; - - for (const key of Object.keys(violations)) { - if (violations.hasOwnProperty(key)) { - // check for popup field for all polices - const rules = this.policyService.getPolicyRules(violations[key]); - const criticalPolicyRules = this.policyService.getCriticalPolicyRules(violations[key]); - const isCriticalPolicyViolation = criticalPolicyRules?.length > 0; - - formattedViolations[key] = { - rules, - action: violations[key].data, - type: violations[key].type, - name: violations[key].name, - currency: violations[key].currency, - amount: violations[key].amount, - isCriticalPolicyViolation, - isExpanded: false, - }; - } - } - return formattedViolations; - } - formatDisplayName(model: number, categoryList: OrgCategory[]): string { const category = this.categoriesService.filterByOrgCategoryId(model, categoryList); return category?.displayName; } - mapViolationDataWithEtxn( - policyViolation: PolicyViolationTxn, - etxns: Expense[], - categoryList: OrgCategory[] - ): { [transactionID: string]: PolicyViolation } { - etxns.forEach((etxn) => { - for (const key of Object.keys(policyViolation)) { - if (policyViolation.hasOwnProperty(key) && key === etxn?.tx_id) { - policyViolation[key].amount = etxn.tx_orig_amount || etxn.tx_amount; - policyViolation[key].currency = etxn.tx_orig_currency || etxn.tx_currency; - policyViolation[key].name = this.formatDisplayName(etxn.tx_org_category_id, categoryList); - policyViolation[key].type = 'category'; - break; - } - } - }); - return policyViolation; - } - - executePolicyCheck( - etxns: Expense[], - fileObjs: FileObject[], - categoryList: OrgCategory[] - ): Observable { - return this.runPolicyCheck(etxns, fileObjs).pipe( - map((policyViolation) => this.mapViolationDataWithEtxn(policyViolation, etxns, categoryList)) - ); - } - - checkForPolicyViolations( - txnIds: string[], - fileObjs: FileObject[], - categoryList: OrgCategory[] - ): Observable { - return from(txnIds).pipe( - concatMap((txnId) => this.transactionService.getEtxn(txnId)), - toArray(), - switchMap((etxns) => this.executePolicyCheck(etxns, fileObjs, categoryList)) - ); - } - - checkPolicyForTransactions(etxns: PublicPolicyExpense[]): Observable { - return from(etxns).pipe( - concatMap((etxn) => this.checkPolicyForTransaction(etxn)), - reduce((accumulator, violation) => { - accumulator = { ...accumulator, ...violation }; - return accumulator; - }, {}) - ); - } - - runPolicyCheck(etxns: Expense[], fileObjs: FileObject[]): Observable { - if (etxns?.length > 0) { - const platformExpensesList: PublicPolicyExpense[] = []; - etxns.forEach((etxn) => { - // transformTo method requires unflattend transaction object - const platformExpense = this.dataTransformService.unflatten<{ tx: PublicPolicyExpense }, Expense>(etxn).tx; - platformExpense.num_files = fileObjs ? fileObjs.length : 0; - - // Since expense has already been created in split expense flow, taking user_amount here. - platformExpense.amount = - typeof platformExpense.user_amount === 'number' ? platformExpense.user_amount : platformExpense.amount; - platformExpensesList.push(platformExpense); - }); - return this.checkPolicyForTransactions(platformExpensesList); - } else { - return of({}); - } - } - createSplitTxns( sourceTxn: Transaction, totalSplitAmount: number, diff --git a/src/app/fyle/split-expense/split-expense.page.spec.ts b/src/app/fyle/split-expense/split-expense.page.spec.ts index ff23d76fbf..596cca1271 100644 --- a/src/app/fyle/split-expense/split-expense.page.spec.ts +++ b/src/app/fyle/split-expense/split-expense.page.spec.ts @@ -208,11 +208,6 @@ describe('SplitExpensePage', () => { const dateServiceSpy = jasmine.createSpyObj('DateService', ['getUTCDate', 'addDaysToDate']); const splitExpenseServiceSpy = jasmine.createSpyObj('SplitExpenseService', [ 'createSplitTxns', - 'createSplitTxns', - 'linkTxnWithFiles', - 'formatPolicyViolations', - 'checkForPolicyViolations', - 'getBase64Content', 'splitExpense', 'postSplitExpenseComments', 'filteredMissingFieldsViolations', @@ -702,236 +697,6 @@ describe('SplitExpensePage', () => { expect(component.categoryList).toEqual(expectedOrgCategoriesPaginated); }); - describe('createAndLinkTxnsWithFiles():', () => { - beforeEach(() => { - component.expenseFields = expenseFieldResponse; - }); - - it('should link transaction with files when the receipt is attached and, the txn state is COMPLETE but the report id is not present', (done) => { - const splitExpData = [splitExpenseTxn1, splitExpenseTxn1_1]; - component.transaction = txnAmount1; - component.reportId = null; - component.totalSplitAmount = 436342.464; - splitExpenseService.createSplitTxns.and.returnValue(of(fileTxns3.txns)); - - component.fileObjs = fileObject6; - splitExpenseService.getBase64Content.and.returnValue( - of([ - { - id: 'fiI9e9ZytdXM', - name: '000.jpeg', - content: 'someData', - }, - ]) - ); - - const mockCompleteTxnIds = ['txPazncEIY9Q', 'tx12SqYytrm']; - splitExpenseService.linkTxnWithFiles.and.returnValue(of(fileObject7)); - component.createAndLinkTxnsWithFiles(splitExpData).subscribe((result) => { - expect(splitExpenseService.createSplitTxns).toHaveBeenCalledOnceWith( - txnAmount1, - component.totalSplitAmount, - splitExpData, - expenseFieldResponse - ); - expect(splitExpenseService.getBase64Content).toHaveBeenCalledOnceWith(fileObject6); - expect(component.splitExpenseTxn).toEqual(fileTxns3.txns); - expect(component.completeTxnIds).toEqual(mockCompleteTxnIds); - expect(splitExpenseService.linkTxnWithFiles).toHaveBeenCalledOnceWith(fileTxns3); - expect(result).toEqual(mockCompleteTxnIds); - done(); - }); - }); - - it('should link transaction with files when the receipt is attached,the txn state is COMPLETE and the report id is present', (done) => { - const splitExpData = [splitExpenseTxn1, splitExpenseTxn1_1]; - component.transaction = txnAmount1; - component.reportId = 'rpba4MnwQ0FO'; - component.totalSplitAmount = 436342.464; - splitExpenseService.createSplitTxns.and.returnValue(of(fileTxns3.txns)); - - component.fileObjs = fileObject6; - reportService.addTransactions.and.returnValue(of(undefined)); - splitExpenseService.getBase64Content.and.returnValue( - of([ - { - id: 'fiI9e9ZytdXM', - name: '000.jpeg', - content: 'someData', - }, - ]) - ); - - const mockCompleteTxnIds = ['txPazncEIY9Q', 'tx12SqYytrm']; - splitExpenseService.linkTxnWithFiles.and.returnValue(of(fileObject7)); - component.createAndLinkTxnsWithFiles(splitExpData).subscribe((result) => { - expect(splitExpenseService.createSplitTxns).toHaveBeenCalledOnceWith( - txnAmount1, - component.totalSplitAmount, - splitExpData, - expenseFieldResponse - ); - expect(splitExpenseService.getBase64Content).toHaveBeenCalledOnceWith(fileObject6); - expect(component.splitExpenseTxn).toEqual(fileTxns3.txns); - expect(component.completeTxnIds).toEqual(mockCompleteTxnIds); - expect(reportService.addTransactions).toHaveBeenCalledOnceWith(component.reportId, mockCompleteTxnIds); - expect(splitExpenseService.linkTxnWithFiles).toHaveBeenCalledOnceWith(fileTxns3); - expect(result).toEqual(mockCompleteTxnIds); - done(); - }); - }); - - it('should link transaction to files when the receipt is not attached and report id is not present', (done) => { - const splitExpData = [splitExpenseTxn1, splitExpenseTxn1_1]; - component.fileObjs = []; - component.reportId = null; - component.transaction = txnAmount1; - splitExpenseService.createSplitTxns.and.returnValue(of(fileTxns4.txns)); - component.totalSplitAmount = 436342.464; - - const mockCompleteTxnIds = ['txPazncEIY9Q', 'tx12SqYytrm']; - splitExpenseService.linkTxnWithFiles.and.returnValue(of([null])); - component.createAndLinkTxnsWithFiles(splitExpData).subscribe((result) => { - expect(splitExpenseService.createSplitTxns).toHaveBeenCalledWith( - txnAmount1, - component.totalSplitAmount, - splitExpData, - expenseFieldResponse - ); - expect(splitExpenseService.createSplitTxns).toHaveBeenCalledTimes(1); - expect(splitExpenseService.getBase64Content).not.toHaveBeenCalled(); - expect(component.splitExpenseTxn).toEqual(fileTxns4.txns); - expect(component.completeTxnIds).toEqual(mockCompleteTxnIds); - expect(splitExpenseService.linkTxnWithFiles).toHaveBeenCalledOnceWith(fileTxns4); - expect(result).toEqual(mockCompleteTxnIds); - done(); - }); - }); - - it('should link transaction to files when the receipt is not attached and report is present', (done) => { - const splitExpData = [splitExpenseTxn1, splitExpenseTxn1_1]; - component.fileObjs = []; - component.transaction = txnAmount1; - component.reportId = 'rpba4MnwQ0FO'; - - splitExpenseService.createSplitTxns.and.returnValue(of(fileTxns4.txns)); - component.totalSplitAmount = 436342.464; - splitExpenseService.linkTxnWithFiles.and.returnValue(of([null])); - reportService.addTransactions.and.returnValue(of(undefined)); - - const mockCompleteTxnIds = ['txPazncEIY9Q', 'tx12SqYytrm']; - component.createAndLinkTxnsWithFiles(splitExpData).subscribe((result) => { - expect(splitExpenseService.createSplitTxns).toHaveBeenCalledOnceWith( - txnAmount1, - component.totalSplitAmount, - splitExpData, - expenseFieldResponse - ); - expect(splitExpenseService.getBase64Content).not.toHaveBeenCalled(); - expect(component.splitExpenseTxn).toEqual(fileTxns4.txns); - expect(component.completeTxnIds).toEqual(mockCompleteTxnIds); - expect(reportService.addTransactions).toHaveBeenCalledOnceWith(component.reportId, mockCompleteTxnIds); - expect(splitExpenseService.linkTxnWithFiles).toHaveBeenCalledOnceWith(fileTxns4); - expect(result).toEqual(mockCompleteTxnIds); - done(); - }); - }); - - it('should link transaction with files when the receipt is attached,the txn state is COMPLETE and the report id is present and the expense is split in three', (done) => { - const splitExpData = [splitExpenseTxn2, splitExpenseTxn2_2, splitExpenseTxn2_3]; - component.fileObjs = fileObject8; - component.transaction = txnAmount2; - component.reportId = 'rpPNBrdR9NaE'; - component.totalSplitAmount = 6000; - reportService.addTransactions.and.returnValue(of(undefined)); - splitExpenseService.createSplitTxns.and.returnValue(of(fileTxns6.txns)); - splitExpenseService.getBase64Content.and.returnValue( - of([ - { - id: 'fiI9e9ZytdXM', - name: '000.jpeg', - content: 'someData', - }, - ]) - ); - const mockCompleteTxnIds = ['txmsakgYZeCV', 'tx78mWdbfw1N', 'txwyRuUnVCbo']; - splitExpenseService.linkTxnWithFiles.and.returnValue(of(fileObject8)); - component.createAndLinkTxnsWithFiles(splitExpData).subscribe((result) => { - expect(splitExpenseService.createSplitTxns).toHaveBeenCalledOnceWith( - txnAmount2, - component.totalSplitAmount, - splitExpData, - expenseFieldResponse - ); - expect(splitExpenseService.getBase64Content).toHaveBeenCalledOnceWith(fileObject8); - expect(component.splitExpenseTxn).toEqual(fileTxns6.txns); - expect(component.completeTxnIds).toEqual(mockCompleteTxnIds); - expect(reportService.addTransactions).toHaveBeenCalledOnceWith(component.reportId, mockCompleteTxnIds); - expect(splitExpenseService.linkTxnWithFiles).toHaveBeenCalledOnceWith(fileTxns6); - expect(result).toEqual(mockCompleteTxnIds); - done(); - }); - }); - - it('should link transaction with files when only one of the txn state is COMPLETE and should only add this transaction to report', (done) => { - const splitExpData = splitExpenseTxn3; - component.transaction = amtTxn3; - - component.reportId = 'rpPNBrdR9NaE'; - component.totalSplitAmount = 635; - reportService.addTransactions.and.returnValue(of(undefined)); - splitExpenseService.createSplitTxns.and.returnValue(of(fileTxns7.txns)); - - const mockCompleteTxnIds = ['txegSZ66da1T']; - splitExpenseService.linkTxnWithFiles.and.returnValue(of([null])); - - component.createAndLinkTxnsWithFiles(splitExpData).subscribe((result) => { - expect(splitExpenseService.createSplitTxns).toHaveBeenCalledOnceWith( - amtTxn3, - component.totalSplitAmount, - splitExpData, - expenseFieldResponse - ); - expect(component.splitExpenseTxn).toEqual(fileTxns7.txns); - expect(component.completeTxnIds).toEqual(mockCompleteTxnIds); - expect(reportService.addTransactions).toHaveBeenCalledOnceWith(component.reportId, mockCompleteTxnIds); - expect(splitExpenseService.linkTxnWithFiles).toHaveBeenCalledOnceWith(fileTxns7); - expect(result).toEqual(['tx5qtWJTXRcj', 'txegSZ66da1T']); - done(); - }); - }); - }); - - it('toastWithCTA(): should display the toast with CTA', () => { - const toastMessage = 'Your expense was split successfully. All the split expenses were added to the report'; - const toastMessageData = { - message: toastMessage, - redirectionText: 'View Report', - }; - - matSnackBar.openFromComponent.and.returnValue({ - onAction: () => ({ - subscribe: (callback: () => void) => { - callback(); - }, - }), - } as MatSnackBarRef); - - component.toastWithCTA(toastMessage); - - expect(matSnackBar.openFromComponent).toHaveBeenCalledOnceWith(ToastMessageComponent, { - ...snackbarProperties.setSnackbarProperties('success', toastMessageData), - panelClass: ['msb-success-with-camera-icon'], - }); - expect(trackingService.showToastMessage).toHaveBeenCalledOnceWith({ ToastContent: toastMessage }); - expect(router.navigate).toHaveBeenCalledOnceWith([ - '/', - 'enterprise', - 'my_view_report', - { id: component.reportId, navigateBack: true }, - ]); - }); - it('toastWithoutCTA(): should display the toast without CTA', () => { const message = 'Your expense was split successfully. All the split expenses were added to the report'; const toastType = ToastType.SUCCESS; @@ -985,64 +750,6 @@ describe('SplitExpensePage', () => { }); }); - it('showSplitExpenseViolations(): should show the expense violations when the expense is split', async () => { - const violations = formattedTxnViolations; - spyOn(component, 'showSuccessToast'); - const properties = { - cssClass: 'fy-modal', - showBackdrop: true, - canDismiss: true, - backdropDismiss: true, - animated: true, - initialBreakpoint: 1, - breakpoints: [0, 1], - handle: false, - }; - modalProperties.getModalDefaultProperties.and.returnValue(properties); - const fyCriticalPolicyViolationPopOverSpy = jasmine.createSpyObj('fyCriticalPolicyViolationPopOver', [ - 'present', - 'onWillDismiss', - ]); - fyCriticalPolicyViolationPopOverSpy.onWillDismiss.and.resolveTo({ - data: { - action: 'primary', - }, - }); - - modalController.create.and.resolveTo(fyCriticalPolicyViolationPopOverSpy); - const result = await component.showSplitExpenseViolations(violations); - expect(result).toBeUndefined(); - expect(modalController.create).toHaveBeenCalledOnceWith({ - component: SplitExpensePolicyViolationComponent, - componentProps: { - policyViolations: violations, - }, - mode: 'ios', - presentingElement: await modalController.getTop(), - ...properties, - }); - expect(modalProperties.getModalDefaultProperties).toHaveBeenCalledTimes(1); - expect(component.showSuccessToast).toHaveBeenCalledTimes(1); - }); - - describe('handleSplitExpensePolicyViolations():', () => { - it('should handle polciy violations when the expense is split', () => { - const violations = policyVoilationData2; - spyOn(component, 'showSplitExpenseViolations'); - policyService.checkIfViolationsExist.and.returnValue(true); - splitExpenseService.formatPolicyViolations.and.returnValue(formattedTxnViolations); - component.handleSplitExpensePolicyViolations(violations); - expect(component.showSplitExpenseViolations).toHaveBeenCalledOnceWith(formattedTxnViolations); - }); - - it('should show success toast when the expense is split and there are no violations', () => { - policyService.checkIfViolationsExist.and.returnValue(false); - spyOn(component, 'showSuccessToast'); - component.handleSplitExpensePolicyViolations(policyViolationData3); - expect(component.showSuccessToast).toHaveBeenCalledTimes(1); - }); - }); - it('getActiveCategories(): should get the active categories', (done) => { categoriesService.getAll.and.returnValue(of(filterOrgCategoryParam)); categoriesService.filterRequired.and.returnValue(expectedFilterOrgCategory); @@ -1681,148 +1388,6 @@ describe('SplitExpensePage', () => { }); }); - describe('save():', () => { - beforeEach(() => { - const mockSplitExpForm = formBuilder.group({ - amount: [23, Validators.required], - currency: ['USD'], - percentage: [50], - txn_dt: [new Date(), Validators.compose([Validators.required, component.customDateValidator])], - }); - component.splitExpensesFormArray = new FormArray([mockSplitExpForm]); - spyOn(component, 'generateSplitEtxnFromFg').and.returnValue(of(txnList[0])); - spyOn(component, 'uploadFiles').and.returnValue(of(fileObjectData1)); - spyOn(component, 'createAndLinkTxnsWithFiles').and.returnValue(of(['txSQ9yM7IYEy', 'txbSFbl4vmf1'])); - const mockTransaction = cloneDeep(txnList[0]); - mockTransaction.corporate_credit_card_expense_group_id = 'cccet1B17R8gWZ'; - component.transaction = mockTransaction; - component.selectedCCCTransaction = matchedCCCTransactionData1; - transactionService.delete.and.returnValue(of(expenseList2[0])); - transactionService.matchCCCExpense.and.returnValue(of(null)); - // @ts-ignore - spyOn(component, 'isEvenlySplit').and.returnValue(true); - component.fileObjs = fileObject6; - component.categoryList = transformedOrgCategories; - component.splitType = 'projects'; - spyOn(component, 'handleSplitExpensePolicyViolations'); - component.fileUrls = fileObjectData1; - }); - - it('should show error message and return if amount is not equal to totalSplitAmount', fakeAsync(() => { - component.amount = 2000; - component.totalSplitAmount = 3000; - - component.save(); - - expect(component.showErrorBlock).toBeTrue(); - expect(component.errorMessage).toEqual('Split amount cannot be more than 2000.'); - // Tick is used to wait for the error block to disappear after 2500ms - tick(2500); - expect(component.showErrorBlock).toBeFalse(); - })); - - it('should show an error message and return if the expense amount is less than 0.01', fakeAsync(() => { - component.amount = 2000; - component.totalSplitAmount = 2000; - component.isCorporateCardsEnabled$ = of(false); - const mockSplitExpForm = formBuilder.group({ - amount: [-23, Validators.required], - currency: ['USD'], - percentage: [50], - txn_dt: [new Date(), Validators.compose([Validators.required, component.customDateValidator])], - }); - component.splitExpensesFormArray = new FormArray([mockSplitExpForm]); - - component.save(); - - expect(component.showErrorBlock).toBeTrue(); - expect(component.errorMessage).toEqual('Amount should be greater than 0.01'); - // Tick is used to wait for the error block to disappear after 2500ms - tick(2500); - expect(component.showErrorBlock).toBeFalse(); - })); - - it('should perform split expense and call handleSplitExpensePolicyViolations', () => { - component.amount = 2000; - component.totalSplitAmount = 2000; - component.isCorporateCardsEnabled$ = of(true); - splitExpenseService.checkForPolicyViolations.and.returnValue(of(policyVoilationData2)); - component.save(); - - expect(component.generateSplitEtxnFromFg).toHaveBeenCalledOnceWith(component.splitExpensesFormArray.value[0]); - expect(component.uploadFiles).toHaveBeenCalledOnceWith(fileObjectData1); - expect(component.createAndLinkTxnsWithFiles).toHaveBeenCalledOnceWith([txnList[0]]); - expect(transactionService.delete).toHaveBeenCalledOnceWith(txnList[0].id); - expect(transactionService.matchCCCExpense).toHaveBeenCalledOnceWith( - 'txSQ9yM7IYEy', - matchedCCCTransactionData1.id - ); - expect(splitExpenseService.checkForPolicyViolations).toHaveBeenCalledOnceWith( - ['txSQ9yM7IYEy', 'txbSFbl4vmf1'], - fileObject6, - transformedOrgCategories - ); - expect(trackingService.splittingExpense).toHaveBeenCalledOnceWith({ - Type: 'projects', - 'Is Evenly Split': true, - Asset: 'Mobile', - 'Is part of report': false, - 'Report ID': null, - 'User Role': 'spender', - 'Expense State': 'DRAFT', - }); - expect(component.handleSplitExpensePolicyViolations).toHaveBeenCalledOnceWith(policyVoilationData2); - }); - - it('should throw error and navigate to my_expenses page if createAndLinkTxnsWithFiles fails', fakeAsync(() => { - component.amount = 2000; - component.totalSplitAmount = 2000; - component.isCorporateCardsEnabled$ = of(true); - splitExpenseService.checkForPolicyViolations.and.returnValue( - throwError(() => new Error('Policy Violation checks were failed!')) - ); - spyOn(component, 'toastWithoutCTA'); - - try { - component.save(); - tick(100); - } catch (err) { - expect(err).toEqual(new Error('Policy Violation checks were failed!')); - expect(component.toastWithoutCTA).toHaveBeenCalledOnceWith( - 'We were unable to split your expense. Please try again later.', - ToastType.FAILURE, - 'msb-failure-with-camera-icon' - ); - expect(router.navigate).toHaveBeenCalledOnceWith(['/', 'enterprise', 'my_expenses']); - expect(trackingService.splittingExpense).toHaveBeenCalledOnceWith({ - Type: 'projects', - 'Is Evenly Split': true, - Asset: 'Mobile', - 'Is part of report': false, - 'Report ID': null, - 'User Role': 'spender', - 'Expense State': 'DRAFT', - }); - expect(component.handleSplitExpensePolicyViolations).not.toHaveBeenCalled(); - } - })); - - it('should set all fields as touched if splitExpensesFormArray is invalid', () => { - const mockSplitExpForm = formBuilder.group({ - amount: [, Validators.required], - currency: ['USD'], - percentage: [50], - txn_dt: [new Date(), Validators.compose([Validators.required, component.customDateValidator])], - }); - component.splitExpensesFormArray = new FormArray([mockSplitExpForm]); - spyOn(component.splitExpensesFormArray, 'markAllAsTouched'); - - component.save(); - - expect(component.splitExpensesFormArray.markAllAsTouched).toHaveBeenCalledTimes(1); - }); - }); - describe('generateSplitEtxnFromFg():', () => { beforeEach(() => { const mockTxn = cloneDeep(txnData4); @@ -2198,7 +1763,7 @@ describe('SplitExpensePage', () => { }); }); - describe('saveV2():', () => { + describe('save():', () => { beforeEach(() => { const mockSplitExpForm = formBuilder.group({ amount: [23, Validators.required], @@ -2209,7 +1774,6 @@ describe('SplitExpensePage', () => { component.splitExpensesFormArray = new FormArray([mockSplitExpForm]); spyOn(component, 'generateSplitEtxnFromFg').and.returnValue(of(txnList[0])); spyOn(component, 'uploadFiles').and.returnValue(of(fileObjectData1)); - spyOn(component, 'createAndLinkTxnsWithFiles').and.returnValue(of(['txSQ9yM7IYEy', 'txbSFbl4vmf1'])); spyOn(component, 'correctTotalSplitAmount'); const mockTransaction = cloneDeep(txnList[0]); component.transaction = mockTransaction; @@ -2233,7 +1797,7 @@ describe('SplitExpensePage', () => { component.amount = 2000; component.totalSplitAmount = 3000; - component.saveV2(); + component.save(); expect(component.showErrorBlock).toBeTrue(); expect(component.errorMessage).toEqual('Split amount cannot be more than 2000.'); @@ -2254,7 +1818,7 @@ describe('SplitExpensePage', () => { }); component.splitExpensesFormArray = new FormArray([mockSplitExpForm]); - component.saveV2(); + component.save(); expect(component.showErrorBlock).toBeTrue(); expect(component.errorMessage).toEqual('Amount should be greater than 0.01'); @@ -2267,8 +1831,7 @@ describe('SplitExpensePage', () => { component.amount = 2000; component.totalSplitAmount = 2000; component.isCorporateCardsEnabled$ = of(true); - splitExpenseService.checkForPolicyViolations.and.returnValue(of(policyVoilationData2)); - component.saveV2(); + component.save(); expect(component.generateSplitEtxnFromFg).toHaveBeenCalledOnceWith(component.splitExpensesFormArray.value[0]); expect(component.handlePolicyAndMissingFieldsCheck).toHaveBeenCalledOnceWith(txnList); @@ -2295,7 +1858,7 @@ describe('SplitExpensePage', () => { splitExpenseService.transformSplitTo.and.returnValue(splitPayloadData1); try { - component.saveV2(); + component.save(); tick(100); } catch (err) { expect(err).toEqual(new Error('Policy Violation checks were failed!')); @@ -2327,7 +1890,7 @@ describe('SplitExpensePage', () => { component.splitExpensesFormArray = new FormArray([mockSplitExpForm]); spyOn(component.splitExpensesFormArray, 'markAllAsTouched'); - component.saveV2(); + component.save(); expect(component.splitExpensesFormArray.markAllAsTouched).toHaveBeenCalledTimes(1); }); diff --git a/src/app/fyle/split-expense/split-expense.page.ts b/src/app/fyle/split-expense/split-expense.page.ts index ffb93799e7..b8eae52ece 100644 --- a/src/app/fyle/split-expense/split-expense.page.ts +++ b/src/app/fyle/split-expense/split-expense.page.ts @@ -21,7 +21,6 @@ import { PolicyService } from 'src/app/core/services/policy.service'; import { SplitExpensePolicyViolationComponent } from 'src/app/shared/components/split-expense-policy-violation/split-expense-policy-violation.component'; import { ModalPropertiesService } from 'src/app/core/services/modal-properties.service'; import { OrgCategory, OrgCategoryListItem } from 'src/app/core/models/v1/org-category.model'; -import { FormattedPolicyViolation } from 'src/app/core/models/formatted-policy-violation.model'; import { PolicyViolation } from 'src/app/core/models/policy-violation.model'; import { OrgSettingsService } from 'src/app/core/services/org-settings.service'; import { CurrencyService } from 'src/app/core/services/currency.service'; @@ -471,53 +470,6 @@ export class SplitExpensePage { ); } - createAndLinkTxnsWithFiles(splitExpenses: Transaction[]): Observable { - const splitExpense$: Partial<{ txns: Observable; files: Observable }> = { - txns: this.splitExpenseService.createSplitTxns( - this.transaction, - this.totalSplitAmount, - splitExpenses, - this.expenseFields - ), - }; - - if (this.fileObjs && this.fileObjs.length > 0) { - splitExpense$.files = this.splitExpenseService.getBase64Content(this.fileObjs); - } - - return forkJoin(splitExpense$).pipe( - switchMap((data) => { - this.splitExpenseTxn = data.txns.map((txn) => txn); - this.completeTxnIds = this.splitExpenseTxn.filter((tx) => tx.state === 'COMPLETE').map((txn) => txn.id); - if (this.completeTxnIds.length !== 0 && this.reportId) { - return this.reportService.addTransactions(this.reportId, this.completeTxnIds).pipe(map(() => data)); - } else { - return of(data); - } - }), - switchMap((data) => { - const txnIds = data.txns.map((txn) => txn.id); - return this.splitExpenseService.linkTxnWithFiles(data).pipe(map(() => txnIds)); - }) - ); - } - - toastWithCTA(toastMessage: string): void { - const toastMessageData = { - message: toastMessage, - redirectionText: 'View Report', - }; - - const expensesAddedToReportSnackBar = this.matSnackBar.openFromComponent(ToastMessageComponent, { - ...this.snackbarProperties.setSnackbarProperties('success', toastMessageData), - panelClass: ['msb-success-with-camera-icon'], - }); - this.trackingService.showToastMessage({ ToastContent: toastMessage }); - expensesAddedToReportSnackBar.onAction().subscribe(() => { - this.router.navigate(['/', 'enterprise', 'my_view_report', { id: this.reportId, navigateBack: true }]); - }); - } - toastWithoutCTA(toastMessage: string, toastType: ToastType, panelClass: string): void { const message = toastMessage; @@ -597,34 +549,6 @@ export class SplitExpensePage { ); } - async showSplitExpenseViolations(violations: { [id: string]: FormattedPolicyViolation }): Promise { - const splitExpenseViolationsModal = await this.modalController.create({ - component: SplitExpensePolicyViolationComponent, - componentProps: { - policyViolations: violations, - }, - mode: 'ios', - presentingElement: await this.modalController.getTop(), - ...this.modalProperties.getModalDefaultProperties(), - }); - - await splitExpenseViolationsModal.present(); - - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unused-vars - const { data } = await splitExpenseViolationsModal.onWillDismiss(); - this.showSuccessToast(); - } - - handleSplitExpensePolicyViolations(violations: { [transactionID: string]: PolicyViolation }): void { - const doViolationsExist = this.policyService.checkIfViolationsExist(violations); - if (doViolationsExist) { - const formattedViolations = this.splitExpenseService.formatPolicyViolations(violations); - this.showSplitExpenseViolations(formattedViolations); - } else { - this.showSuccessToast(); - } - } - async showSplitExpensePolicyViolationsAndMissingFields( splitEtxns: Transaction[], policyViolations: { [id: number]: PolicyViolation }, diff --git a/src/app/shared/components/split-expense-policy-violation/split-expense-policy-violation.component.spec.ts b/src/app/shared/components/split-expense-policy-violation/split-expense-policy-violation.component.spec.ts index 2941c3ec18..2bd4459fff 100644 --- a/src/app/shared/components/split-expense-policy-violation/split-expense-policy-violation.component.spec.ts +++ b/src/app/shared/components/split-expense-policy-violation/split-expense-policy-violation.component.spec.ts @@ -7,7 +7,6 @@ import { formattedPolicyViolation2, } from 'src/app/core/mock-data/formatted-policy-violation.data'; import { FormArray, FormBuilder, ReactiveFormsModule } from '@angular/forms'; -import { SplitExpenseService } from 'src/app/core/services/split-expense.service'; import { of } from 'rxjs'; import { cloneDeep } from 'lodash'; import { @@ -23,22 +22,16 @@ describe('SplitExpensePolicyViolationComponent', () => { let component: SplitExpensePolicyViolationComponent; let fixture: ComponentFixture; let modalController: jasmine.SpyObj; - let splitExpenseService: jasmine.SpyObj; let comments: FormArray; beforeEach(waitForAsync(() => { const modalControllerSpy = jasmine.createSpyObj('ModalController', ['dismiss']); - const splitExpenseServiceSpy = jasmine.createSpyObj('SplitExpenseService', ['postCommentsFromUsers']); TestBed.configureTestingModule({ declarations: [SplitExpensePolicyViolationComponent], imports: [IonicModule.forRoot(), ReactiveFormsModule], schemas: [CUSTOM_ELEMENTS_SCHEMA], providers: [ FormBuilder, - { - provide: SplitExpenseService, - useValue: splitExpenseServiceSpy, - }, { provide: ModalController, useValue: modalControllerSpy, @@ -48,7 +41,6 @@ describe('SplitExpensePolicyViolationComponent', () => { fixture = TestBed.createComponent(SplitExpensePolicyViolationComponent); component = fixture.componentInstance; - splitExpenseService = TestBed.inject(SplitExpenseService) as jasmine.SpyObj; modalController = TestBed.inject(ModalController) as jasmine.SpyObj; component.policyViolations = { 0: cloneDeep(filteredSplitPolicyViolationsData), @@ -95,7 +87,6 @@ describe('SplitExpensePolicyViolationComponent', () => { it('should post comments from users and dismiss the modal', () => { comments.at(0).get('comment').setValue('comment1'); comments.at(1).get('comment').setValue('comment2'); - splitExpenseService.postCommentsFromUsers.and.returnValue(of(null)); component.continue();