From 43534fa5024eb5d4b705d292135ea5b126cfec1c Mon Sep 17 00:00:00 2001 From: Z3RO-O Date: Thu, 24 Oct 2024 02:02:22 +0530 Subject: [PATCH] fix: tests --- .../add-edit-expense-2.spec.ts | 18 ++++++ .../add-edit-expense-3.spec.ts | 63 +++++++++---------- 2 files changed, 46 insertions(+), 35 deletions(-) diff --git a/src/app/fyle/add-edit-expense/add-edit-expense-2.spec.ts b/src/app/fyle/add-edit-expense/add-edit-expense-2.spec.ts index ee8805c33a..80f65948c3 100644 --- a/src/app/fyle/add-edit-expense/add-edit-expense-2.spec.ts +++ b/src/app/fyle/add-edit-expense/add-edit-expense-2.spec.ts @@ -582,6 +582,24 @@ export function TestCases2(getTestBed) { done(); }); }); + + it('should update txn date with invoice_dt', (done) => { + const mockedTxn = cloneDeep(transformedExpenseWithExtractedData2); + const extractedDate = new Date('2023-01-24'); + + mockedTxn.tx.txn_dt = new Date('2023-01-23'); + mockedTxn.tx.extracted_data.invoice_dt = new Date('2023-01-23'); + mockedTxn.tx.extracted_data.date = extractedDate; + expensesService.getExpenseById.and.returnValue(of(platformExpenseWithExtractedData2)); + transactionService.transformExpense.and.returnValue(mockedTxn); + dateService.getUTCDate.and.returnValue(mockedTxn.tx.extracted_data.invoice_dt); + + component.getEditExpenseObservable().subscribe((res) => { + expect(res).toEqual(mockedTxn); + expect(mockedTxn.tx.txn_dt).toEqual(mockedTxn.tx.extracted_data.invoice_dt); + done(); + }); + }); }); it('goToPrev(): should go to the previous txn', () => { diff --git a/src/app/fyle/add-edit-expense/add-edit-expense-3.spec.ts b/src/app/fyle/add-edit-expense/add-edit-expense-3.spec.ts index 6a393cd42b..d091ac2fe0 100644 --- a/src/app/fyle/add-edit-expense/add-edit-expense-3.spec.ts +++ b/src/app/fyle/add-edit-expense/add-edit-expense-3.spec.ts @@ -113,7 +113,6 @@ import { receiptInfoData2 } from 'src/app/core/mock-data/receipt-info.data'; import { ExpensesService } from 'src/app/core/services/platform/v1/spender/expenses.service'; import { AdvanceWalletsService } from 'src/app/core/services/platform/v1/spender/advance-wallets.service'; import { platformExpenseWithExtractedData } from 'src/app/core/mock-data/platform/v1/expense.data'; -import { RefinerService } from 'src/app/core/services/refiner.service'; export function TestCases3(getTestBed) { return describe('AddEditExpensePage-3', () => { @@ -165,7 +164,6 @@ export function TestCases3(getTestBed) { let launchDarklyService: jasmine.SpyObj; let expensesService: jasmine.SpyObj; let advanceWalletsService: jasmine.SpyObj; - let refinerService: jasmine.SpyObj; beforeEach(() => { const TestBed = getTestBed(); @@ -223,7 +221,6 @@ export function TestCases3(getTestBed) { storageService = TestBed.inject(StorageService) as jasmine.SpyObj; launchDarklyService = TestBed.inject(LaunchDarklyService) as jasmine.SpyObj; expensesService = TestBed.inject(ExpensesService) as jasmine.SpyObj; - refinerService = TestBed.inject(RefinerService) as jasmine.SpyObj; component.fg = formBuilder.group({ currencyObj: [, component.currencyObjValidator], @@ -914,38 +911,6 @@ export function TestCases3(getTestBed) { }); }); - describe('triggerNpsSurvey', () => { - it('should start survey if nps_survey feature flag is enabled and user is not an ADMIN', () => { - const roles = ['USER']; - authService.getRoles.and.returnValue(of(roles)); - launchDarklyService.getVariation.and.returnValue(of(true)); - - component.triggerNpsSurvey(); - - expect(refinerService.startSurvey).toHaveBeenCalledWith({ actionName: 'Save Expense' }); - }); - - it('should not start survey if nps_survey feature flag is disabled', () => { - const roles = ['USER']; - authService.getRoles.and.returnValue(of(roles)); - launchDarklyService.getVariation.and.returnValue(of(false)); - - component.triggerNpsSurvey(); - - expect(refinerService.startSurvey).not.toHaveBeenCalled(); - }); - - it('should not start survey if user is an ADMIN', () => { - const roles = ['ADMIN']; - authService.getRoles.and.returnValue(of(roles)); - launchDarklyService.getVariation.and.returnValue(of(true)); - - component.triggerNpsSurvey(); - - expect(refinerService.startSurvey).not.toHaveBeenCalled(); - }); - }); - describe('getCategoryOnAdd():', () => { it('should return category if provided as parameter', (done) => { component.getCategoryOnAdd(orgCategoryData).subscribe((res) => { @@ -1189,6 +1154,34 @@ export function TestCases3(getTestBed) { }, }); }); + + it('should set default comment if user wants to continue with violations but does not provide a comment', (done) => { + loaderService.hideLoader.and.resolveTo(); + loaderService.showLoader.and.resolveTo(); + component.etxn$ = of(unflattenedTxnData2); + spyOn(component, 'continueWithPolicyViolations').and.resolveTo({ comment: '' }); + spyOn(component, 'generateEtxnFromFg').and.returnValue(of(unflattenedExpData)); + + component + .policyViolationErrorHandler( + { + policyViolations: criticalPolicyViolation1, + policyAction: policyViolation1.data.final_desired_state, + }, + of(customFieldData2) + ) + .subscribe((result) => { + expect(loaderService.hideLoader).toHaveBeenCalledTimes(1); + expect(loaderService.showLoader).toHaveBeenCalledTimes(1); + expect(component.continueWithPolicyViolations).toHaveBeenCalledOnceWith( + criticalPolicyViolation1, + policyViolation1.data.final_desired_state + ); + expect(component.generateEtxnFromFg).toHaveBeenCalledTimes(1); + expect(result.comment).toBe('No policy violation explanation provided'); + done(); + }); + }); }); describe('viewAttachments():', () => {