diff --git a/src/app/core/services/transaction.service.spec.ts b/src/app/core/services/transaction.service.spec.ts index 9e449e76b7..6fe02a94e5 100644 --- a/src/app/core/services/transaction.service.spec.ts +++ b/src/app/core/services/transaction.service.spec.ts @@ -1107,7 +1107,6 @@ describe('TransactionService', () => { expect(expensesService.createFromFile).toHaveBeenCalledOnceWith(mockFileObject[0].id, 'MOBILE_DASHCAM_BULK'); expect(transactionService.upsert).toHaveBeenCalledOnceWith({ ...txnDataCleaned, - file_ids: [fileObjectData1[0].id], id: expenseData.id, }); done(); diff --git a/src/app/fyle/add-edit-mileage/add-edit-mileage-3.spec.ts b/src/app/fyle/add-edit-mileage/add-edit-mileage-3.spec.ts index c307cca1a4..f01e293387 100644 --- a/src/app/fyle/add-edit-mileage/add-edit-mileage-3.spec.ts +++ b/src/app/fyle/add-edit-mileage/add-edit-mileage-3.spec.ts @@ -247,7 +247,7 @@ export function TestCases3(getTestBed) { spyOn(component, 'getCustomFields').and.returnValue(of(txnCustomPropertiesData4)); spyOn(component, 'getCalculatedDistance').and.returnValue(of('10')); component.isConnected$ = of(true); - spyOn(component, 'generateEtxnFromFg').and.returnValue(of(unflattenedTxnData)); + spyOn(component, 'generateEtxnFromFg').and.returnValue(of(cloneDeep(unflattenedTxnData))); spyOn(component, 'checkPolicyViolation').and.returnValue(of(expensePolicyDataWoData)); policyService.getCriticalPolicyRules.and.returnValue([]); policyService.getPolicyRules.and.returnValue([]); @@ -256,11 +256,18 @@ export function TestCases3(getTestBed) { spyOn(component, 'getFormValues').and.returnValue({ report: expectedReportsPaginated[0], }); + const expectedEtxnData = { + ...unflattenedTxnData, + tx: { + ...unflattenedTxnData.tx, + report_id: expectedReportsPaginated[0].id, + }, + }; transactionOutboxService.addEntryAndSync.and.resolveTo(outboxQueueData1[0]); fixture.detectChanges(); component.addExpense('SAVE_MILEAGE').subscribe((res) => { - expect(res).toEqual(unflattenedTxnData); + expect(res).toEqual(expectedEtxnData); expect(component.getCustomFields).toHaveBeenCalledTimes(1); expect(component.getCalculatedDistance).toHaveBeenCalledTimes(1); expect(component.generateEtxnFromFg).toHaveBeenCalledOnceWith( @@ -274,7 +281,7 @@ export function TestCases3(getTestBed) { expect(component.trackCreateExpense).toHaveBeenCalledTimes(1); expect(component.getFormValues).toHaveBeenCalledTimes(1); expect(transactionOutboxService.addEntryAndSync).toHaveBeenCalledOnceWith( - unflattenedTxnData.tx, + expectedEtxnData.tx, unflattenedTxnData.dataUrls as any, [] ); @@ -429,18 +436,25 @@ export function TestCases3(getTestBed) { component.isConnected$ = of(false); spyOn(component, 'getCustomFields').and.returnValue(of(txnCustomPropertiesData4)); spyOn(component, 'getCalculatedDistance').and.returnValue(of('10')); - spyOn(component, 'generateEtxnFromFg').and.returnValue(of(unflattenedTxnData)); + spyOn(component, 'generateEtxnFromFg').and.returnValue(of(cloneDeep(unflattenedTxnData))); spyOn(component, 'checkPolicyViolation').and.returnValue(of(expensePolicyDataWoData)); spyOn(component, 'trackCreateExpense'); authService.getEou.and.resolveTo(apiEouRes); spyOn(component, 'getFormValues').and.returnValue({ report: expectedReportsPaginated[0], }); + const expectedEtxnData = { + ...unflattenedTxnData, + tx: { + ...unflattenedTxnData.tx, + report_id: expectedReportsPaginated[0].id, + }, + }; transactionOutboxService.addEntryAndSync.and.resolveTo(outboxQueueData1[0]); fixture.detectChanges(); component.addExpense('SAVE_MILEAGE').subscribe((res) => { - expect(res).toEqual(unflattenedTxnData); + expect(res).toEqual(expectedEtxnData); expect(component.getCustomFields).toHaveBeenCalledTimes(1); expect(component.getCalculatedDistance).toHaveBeenCalledTimes(1); expect(component.generateEtxnFromFg).toHaveBeenCalledOnceWith( @@ -452,7 +466,7 @@ export function TestCases3(getTestBed) { expect(component.trackCreateExpense).toHaveBeenCalledTimes(1); expect(component.getFormValues).toHaveBeenCalledTimes(1); expect(transactionOutboxService.addEntryAndSync).toHaveBeenCalledOnceWith( - unflattenedTxnData.tx, + expectedEtxnData.tx, unflattenedTxnData.dataUrls as any, [] ); diff --git a/src/app/fyle/add-edit-per-diem/add-edit-per-diem-3.page.spec.ts b/src/app/fyle/add-edit-per-diem/add-edit-per-diem-3.page.spec.ts index cb17c84e18..b884e860a5 100644 --- a/src/app/fyle/add-edit-per-diem/add-edit-per-diem-3.page.spec.ts +++ b/src/app/fyle/add-edit-per-diem/add-edit-per-diem-3.page.spec.ts @@ -77,7 +77,7 @@ import { expectedReportsPaginated } from 'src/app/core/mock-data/platform-report import { PerDiemRedirectedFrom } from 'src/app/core/models/per-diem-redirected-from.enum'; export function TestCases3(getTestBed) { - return describe('add-edit-per-diem test cases set 3', () => { + return fdescribe('add-edit-per-diem test cases set 3', () => { let component: AddEditPerDiemPage; let fixture: ComponentFixture; let activatedRoute: jasmine.SpyObj; @@ -613,18 +613,27 @@ export function TestCases3(getTestBed) { }); describe('addExpense():', () => { - const etxn$ = of({ tx: unflattenedTxnData.tx, ou: unflattenedTxnData.ou, dataUrls: [] }); const customFields$ = of(txnCustomProperties4); + const expectedEtxnDataWithReportId = { + ...unflattenedTxnData, + tx: { + ...unflattenedTxnData.tx, + report_id: expectedReportsPaginated[0].id, + }, + }; beforeEach(() => { + const etxn$ = of({ tx: cloneDeep(unflattenedTxnData.tx), ou: unflattenedTxnData.ou, dataUrls: [] }); spyOn(component, 'generateEtxnFromFg').and.returnValue(etxn$); spyOn(component, 'getCustomFields').and.returnValue(customFields$); component.isConnected$ = of(true); spyOn(component, 'checkPolicyViolation').and.returnValue(of(expensePolicyData)); policyService.getCriticalPolicyRules.and.returnValue(['The expense will be flagged']); policyService.getPolicyRules.and.returnValue(['The expense will be flagged']); - spyOn(component, 'criticalPolicyViolationErrorHandler').and.returnValue(of({ etxn: unflattenedTxnData })); + spyOn(component, 'criticalPolicyViolationErrorHandler').and.returnValue( + of({ etxn: cloneDeep(unflattenedTxnData) }) + ); spyOn(component, 'policyViolationErrorHandler').and.returnValue( - of({ etxn: unflattenedTxnData, comment: 'comment' }) + of({ etxn: cloneDeep(unflattenedTxnData), comment: 'comment' }) ); authService.getEou.and.resolveTo(apiEouRes); spyOn(component, 'getFormValues').and.returnValue({ @@ -670,7 +679,7 @@ export function TestCases3(getTestBed) { expect(authService.getEou).toHaveBeenCalledTimes(1); expect(trackingService.createExpense).toHaveBeenCalledOnceWith(createExpenseProperties3); expect(transactionOutboxService.addEntryAndSync).toHaveBeenCalledOnceWith( - unflattenedTxnData.tx, + expectedEtxnDataWithReportId.tx, undefined, [] ); @@ -712,7 +721,7 @@ export function TestCases3(getTestBed) { expect(authService.getEou).toHaveBeenCalledTimes(1); expect(trackingService.createExpense).toHaveBeenCalledOnceWith(createExpenseProperties3); expect(transactionOutboxService.addEntryAndSync).toHaveBeenCalledOnceWith( - unflattenedTxnData.tx, + expectedEtxnDataWithReportId.tx, undefined, ['comment'] ); @@ -757,7 +766,7 @@ export function TestCases3(getTestBed) { expect(authService.getEou).toHaveBeenCalledTimes(1); expect(trackingService.createExpense).toHaveBeenCalledOnceWith(createExpenseProperties3); expect(transactionOutboxService.addEntryAndSync).toHaveBeenCalledOnceWith( - unflattenedTxnData.tx, + expectedEtxnDataWithReportId.tx, undefined, ['comment'] ); @@ -800,7 +809,7 @@ export function TestCases3(getTestBed) { expect(authService.getEou).toHaveBeenCalledTimes(1); expect(trackingService.createExpense).toHaveBeenCalledOnceWith(createExpenseProperties3); expect(transactionOutboxService.addEntryAndSync).toHaveBeenCalledOnceWith( - unflattenedTxnData.tx, + expectedEtxnDataWithReportId.tx, undefined, ['comment'] ); @@ -839,7 +848,7 @@ export function TestCases3(getTestBed) { expect(authService.getEou).toHaveBeenCalledTimes(1); expect(trackingService.createExpense).toHaveBeenCalledOnceWith(createExpenseProperties3); expect(transactionOutboxService.addEntryAndSync).toHaveBeenCalledOnceWith( - unflattenedTxnData.tx, + expectedEtxnDataWithReportId.tx, undefined, ['comment'] ); @@ -882,7 +891,11 @@ export function TestCases3(getTestBed) { expect(authService.getEou).toHaveBeenCalledTimes(1); expect(trackingService.createExpense).toHaveBeenCalledOnceWith(createExpenseProperties3); - expect(transactionOutboxService.addEntryAndSync).toHaveBeenCalledOnceWith(unflattenedTxnData.tx, [], []); + expect(transactionOutboxService.addEntryAndSync).toHaveBeenCalledOnceWith( + expectedEtxnDataWithReportId.tx, + [], + [] + ); expect(res).toEqual(outboxQueueData1[0]); done(); }); @@ -912,7 +925,11 @@ export function TestCases3(getTestBed) { expect(authService.getEou).toHaveBeenCalledTimes(1); expect(trackingService.createExpense).toHaveBeenCalledOnceWith(createExpenseProperties3); - expect(transactionOutboxService.addEntryAndSync).toHaveBeenCalledOnceWith(unflattenedTxnData.tx, [], []); + expect(transactionOutboxService.addEntryAndSync).toHaveBeenCalledOnceWith( + expectedEtxnDataWithReportId.tx, + [], + [] + ); expect(res).toEqual(outboxQueueData1[0]); done(); }); @@ -923,6 +940,7 @@ export function TestCases3(getTestBed) { policyService.getPolicyRules.and.returnValue([]); const mockTxnData = cloneDeep(unflattenedTxnData); mockTxnData.tx.policy_amount = 0.1; + mockTxnData.tx.report_id = expectedReportsPaginated[0].id; component.generateEtxnFromFg = jasmine .createSpy() .and.returnValue(of({ tx: mockTxnData.tx, ou: unflattenedTxnData.ou, dataUrls: [] })); diff --git a/src/app/fyle/add-edit-per-diem/add-edit-per-diem.page.ts b/src/app/fyle/add-edit-per-diem/add-edit-per-diem.page.ts index 0c661f3052..ee9a115bfe 100644 --- a/src/app/fyle/add-edit-per-diem/add-edit-per-diem.page.ts +++ b/src/app/fyle/add-edit-per-diem/add-edit-per-diem.page.ts @@ -1971,15 +1971,16 @@ export class AddEditPerDiemPage implements OnInit { } const formValue = this.getFormValues(); + const transaction = cloneDeep(etxn.tx); if ( formValue.report && (etxn.tx.policy_amount === null || (etxn.tx.policy_amount && !(etxn.tx.policy_amount < 0.0001))) ) { - etxn.tx.report_id = formValue.report.id; + transaction.report_id = formValue.report.id; } return of( this.transactionsOutboxService.addEntryAndSync( - etxn.tx, + transaction, etxn.dataUrls as { url: string; type: string }[], comments )