From 9e33e2c1247419b0d1a4764e10af9b0aeec5d695 Mon Sep 17 00:00:00 2001 From: aastha Date: Thu, 18 Apr 2024 09:03:01 +0530 Subject: [PATCH 01/46] Minor --- .../services/platform/v1/spender/reports.service.ts | 11 +++++++++++ .../fyle/add-edit-expense/add-edit-expense.page.ts | 9 +++++---- .../fyle/add-edit-mileage/add-edit-mileage.page.ts | 9 +++++---- .../fyle/add-edit-per-diem/add-edit-per-diem.page.ts | 9 +++++---- src/app/fyle/view-expense/view-expense.page.ts | 6 ++++-- src/app/fyle/view-mileage/view-mileage.page.ts | 6 ++++-- src/app/fyle/view-per-diem/view-per-diem.page.ts | 6 ++++-- 7 files changed, 38 insertions(+), 18 deletions(-) diff --git a/src/app/core/services/platform/v1/spender/reports.service.ts b/src/app/core/services/platform/v1/spender/reports.service.ts index ad15b48e5c..264299a5df 100644 --- a/src/app/core/services/platform/v1/spender/reports.service.ts +++ b/src/app/core/services/platform/v1/spender/reports.service.ts @@ -59,4 +59,15 @@ export class ReportsService { .post>('/reports', data) .pipe(map((res) => res.data)); } + + ejectExpenses(rptId: string, txnId: string, comment?: string[]): Observable { + const params = { + data: { + id: rptId, + expense_ids: [txnId], + }, + reason: comment, + }; + return this.spenderPlatformV1ApiService.post('/reports/eject_expenses', params); + } } diff --git a/src/app/fyle/add-edit-expense/add-edit-expense.page.ts b/src/app/fyle/add-edit-expense/add-edit-expense.page.ts index 19196dc299..522da72ed6 100644 --- a/src/app/fyle/add-edit-expense/add-edit-expense.page.ts +++ b/src/app/fyle/add-edit-expense/add-edit-expense.page.ts @@ -471,7 +471,8 @@ export class AddEditExpensePage implements OnInit { private storageService: StorageService, private launchDarklyService: LaunchDarklyService, private platformHandlerService: PlatformHandlerService, - private expensesService: ExpensesService + private expensesService: ExpensesService, + private reportsService: ReportsService ) {} get isExpandedView(): boolean { @@ -3900,7 +3901,7 @@ export class AddEditExpensePage implements OnInit { } if (txnCopy.tx.report_id && selectedReportId && txnCopy.tx.report_id !== selectedReportId) { - return this.reportService.removeTransaction(txnCopy.tx.report_id, tx.id).pipe( + return this.reportsService.ejectExpenses(txnCopy.tx.report_id, tx.id).pipe( switchMap(() => this.reportService.addTransactions(selectedReportId, [tx.id])), tap(() => this.trackingService.addToExistingReportAddEditExpense()), map(() => tx) @@ -3908,7 +3909,7 @@ export class AddEditExpensePage implements OnInit { } if (txnCopy.tx.report_id && !selectedReportId) { - return this.reportService.removeTransaction(txnCopy.tx.report_id, tx.id).pipe( + return this.reportsService.ejectExpenses(txnCopy.tx.report_id, tx.id).pipe( tap(() => this.trackingService.removeFromExistingReportEditExpense()), map(() => tx) ); @@ -4672,7 +4673,7 @@ export class AddEditExpensePage implements OnInit { ctaLoadingText: config.ctaLoadingText, deleteMethod: (): Observable => { if (removeExpenseFromReport) { - return this.reportService.removeTransaction(reportId, this.activatedRoute.snapshot.params.id as string); + return this.reportsService.ejectExpenses(reportId, this.activatedRoute.snapshot.params.id as string); } return this.transactionService.delete(this.activatedRoute.snapshot.params.id as string); }, diff --git a/src/app/fyle/add-edit-mileage/add-edit-mileage.page.ts b/src/app/fyle/add-edit-mileage/add-edit-mileage.page.ts index 20d5be8b53..98f1ec98bf 100644 --- a/src/app/fyle/add-edit-mileage/add-edit-mileage.page.ts +++ b/src/app/fyle/add-edit-mileage/add-edit-mileage.page.ts @@ -325,7 +325,8 @@ export class AddEditMileagePage implements OnInit { private storageService: StorageService, private employeesService: EmployeesService, private expensesService: ExpensesService, - private changeDetectorRef: ChangeDetectorRef + private changeDetectorRef: ChangeDetectorRef, + private reportsService: ReportsService ) {} get showSaveAndNext(): boolean { @@ -2578,7 +2579,7 @@ export class AddEditMileagePage implements OnInit { } if (txnCopy.tx.report_id && selectedReportId && txnCopy.tx.report_id !== selectedReportId) { - return this.reportService.removeTransaction(txnCopy.tx.report_id, tx.id).pipe( + return this.reportsService.ejectExpenses(txnCopy.tx.report_id, tx.id).pipe( switchMap(() => this.reportService.addTransactions(selectedReportId, [tx.id])), tap(() => this.trackingService.addToExistingReportAddEditExpense()), map(() => tx) @@ -2586,7 +2587,7 @@ export class AddEditMileagePage implements OnInit { } if (txnCopy.tx.report_id && !selectedReportId) { - return this.reportService.removeTransaction(txnCopy.tx.report_id, tx.id).pipe( + return this.reportsService.ejectExpenses(txnCopy.tx.report_id, tx.id).pipe( tap(() => this.trackingService.removeFromExistingReportEditExpense()), map(() => tx) ); @@ -2876,7 +2877,7 @@ export class AddEditMileagePage implements OnInit { ctaLoadingText: config.ctaLoadingText, deleteMethod: (): Observable => { if (config.removeMileageFromReport) { - return this.reportService.removeTransaction(config.reportId, config.id); + return this.reportsService.ejectExpenses(config.reportId, config.id); } return this.transactionService.delete(config.id); }, 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 3df4275334..1eeed12dae 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 @@ -286,7 +286,8 @@ export class AddEditPerDiemPage implements OnInit { private orgSettingsService: OrgSettingsService, private platform: Platform, private storageService: StorageService, - private expensesService: ExpensesService + private expensesService: ExpensesService, + private reportsService: ReportsService ) {} get minPerDiemDate(): string { @@ -2061,7 +2062,7 @@ export class AddEditPerDiemPage implements OnInit { } if (txnCopy.tx.report_id && selectedReportId && selectedReportId !== txnCopy.tx.report_id) { - return this.reportService.removeTransaction(txnCopy.tx.report_id, tx.id).pipe( + return this.reportsService.ejectExpenses(txnCopy.tx.report_id, tx.id).pipe( switchMap(() => this.reportService.addTransactions(selectedReportId, [tx.id])), tap(() => this.trackingService.addToExistingReportAddEditExpense()), map(() => tx) @@ -2069,7 +2070,7 @@ export class AddEditPerDiemPage implements OnInit { } if (txnCopy.tx.report_id && !selectedReportId) { - return this.reportService.removeTransaction(txnCopy.tx.report_id, tx.id).pipe( + return this.reportsService.ejectExpenses(txnCopy.tx.report_id, tx.id).pipe( tap(() => this.trackingService.removeFromExistingReportEditExpense()), map(() => tx) ); @@ -2278,7 +2279,7 @@ export class AddEditPerDiemPage implements OnInit { ctaLoadingText: config.ctaLoadingText, deleteMethod: (): Observable => { if (removePerDiemFromReport) { - return this.reportService.removeTransaction(reportId, id); + return this.reportsService.ejectExpenses(reportId, id); } return this.transactionService.delete(id); }, diff --git a/src/app/fyle/view-expense/view-expense.page.ts b/src/app/fyle/view-expense/view-expense.page.ts index 0d59cf1352..c4784ea428 100644 --- a/src/app/fyle/view-expense/view-expense.page.ts +++ b/src/app/fyle/view-expense/view-expense.page.ts @@ -35,6 +35,7 @@ import { Expense, TransactionStatus } from 'src/app/core/models/platform/v1/expe import { AccountType } from 'src/app/core/models/platform/v1/account.model'; import { ExpenseState } from 'src/app/core/models/expense-state.enum'; import { TransactionStatusInfoPopoverComponent } from 'src/app/shared/components/transaction-status-info-popover/transaction-status-info-popover.component'; +import { ReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; @Component({ selector: 'app-view-expense', @@ -150,7 +151,8 @@ export class ViewExpensePage { private categoriesService: CategoriesService, private dependentFieldsService: DependentFieldsService, private spenderExpensesService: SpenderExpensesService, - private approverExpensesService: ApproverExpensesService + private approverExpensesService: ApproverExpensesService, + private reportsService: ReportsService ) {} get ExpenseView(): typeof ExpenseView { @@ -465,7 +467,7 @@ export class ViewExpensePage { infoMessage: 'The report amount will be adjusted accordingly.', ctaText: 'Remove', ctaLoadingText: 'Removing', - deleteMethod: (): Observable => this.reportService.removeTransaction(this.reportId, this.expenseId), + deleteMethod: (): Observable => this.reportsService.ejectExpenses(this.reportId, this.expenseId), }, }; } diff --git a/src/app/fyle/view-mileage/view-mileage.page.ts b/src/app/fyle/view-mileage/view-mileage.page.ts index 57e3c47475..98ecdb1b0e 100644 --- a/src/app/fyle/view-mileage/view-mileage.page.ts +++ b/src/app/fyle/view-mileage/view-mileage.page.ts @@ -37,6 +37,7 @@ import { AccountType } from 'src/app/core/models/platform/v1/account.model'; import { ExpenseState } from 'src/app/core/models/expense-state.enum'; import { MileageRatesService } from 'src/app/core/services/mileage-rates.service'; import { PlatformMileageRates } from 'src/app/core/models/platform/platform-mileage-rates.model'; +import { ReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; @Component({ selector: 'app-view-mileage', @@ -130,7 +131,8 @@ export class ViewMileagePage { private fileService: FileService, private approverExpensesService: ApproverExpensesService, private spenderExpensesService: SpenderExpensesService, - private mileageRatesService: MileageRatesService + private mileageRatesService: MileageRatesService, + private reportsService: ReportsService ) {} get ExpenseView(): typeof ExpenseView { @@ -217,7 +219,7 @@ export class ViewMileagePage { infoMessage: 'The report amount will be adjusted accordingly.', ctaText: 'Remove', ctaLoadingText: 'Removing', - deleteMethod: (): Observable => this.reportService.removeTransaction(this.reportId, this.expenseId), + deleteMethod: (): Observable => this.reportsService.ejectExpenses(this.reportId, this.expenseId), }, }; } diff --git a/src/app/fyle/view-per-diem/view-per-diem.page.ts b/src/app/fyle/view-per-diem/view-per-diem.page.ts index d6209aa7ea..6bec468a30 100644 --- a/src/app/fyle/view-per-diem/view-per-diem.page.ts +++ b/src/app/fyle/view-per-diem/view-per-diem.page.ts @@ -33,6 +33,7 @@ import { ExpensesService as ApproverExpensesService } from 'src/app/core/service import { ExpensesService as SpenderExpensesService } from 'src/app/core/services/platform/v1/spender/expenses.service'; import { AccountType } from 'src/app/core/models/platform/v1/account.model'; import { ExpenseState } from 'src/app/core/models/expense-state.enum'; +import { ReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; @Component({ selector: 'app-view-per-diem', @@ -116,7 +117,8 @@ export class ViewPerDiemPage { private orgSettingsService: OrgSettingsService, private dependentFieldsService: DependentFieldsService, private spenderExpensesService: SpenderExpensesService, - private approverExpensesService: ApproverExpensesService + private approverExpensesService: ApproverExpensesService, + private reportsService: ReportsService ) {} get ExpenseView(): typeof ExpenseView { @@ -352,7 +354,7 @@ export class ViewPerDiemPage { infoMessage: 'The report amount will be adjusted accordingly.', ctaText: 'Remove', ctaLoadingText: 'Removing', - deleteMethod: (): Observable => this.reportService.removeTransaction(this.reportId, this.expenseId), + deleteMethod: (): Observable => this.reportsService.ejectExpenses(this.reportId, this.expenseId), }, }; } From e0851cdbd59f68593b6caa95c49c67186cb9f056 Mon Sep 17 00:00:00 2001 From: Aastha Bist Date: Thu, 18 Apr 2024 12:27:18 +0530 Subject: [PATCH 02/46] Update reports.service.ts --- src/app/core/services/platform/v1/spender/reports.service.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/core/services/platform/v1/spender/reports.service.ts b/src/app/core/services/platform/v1/spender/reports.service.ts index 264299a5df..b1eac04b41 100644 --- a/src/app/core/services/platform/v1/spender/reports.service.ts +++ b/src/app/core/services/platform/v1/spender/reports.service.ts @@ -61,13 +61,13 @@ export class ReportsService { } ejectExpenses(rptId: string, txnId: string, comment?: string[]): Observable { - const params = { + const payload = { data: { id: rptId, expense_ids: [txnId], }, reason: comment, }; - return this.spenderPlatformV1ApiService.post('/reports/eject_expenses', params); + return this.spenderPlatformV1ApiService.post('/reports/eject_expenses', payload); } } From 510af5d6879fc0ed718a1ddf348749e40774206a Mon Sep 17 00:00:00 2001 From: aastha Date: Thu, 18 Apr 2024 16:43:32 +0530 Subject: [PATCH 03/46] Minor --- src/app/fyle/view-per-diem/view-per-diem.page.spec.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/app/fyle/view-per-diem/view-per-diem.page.spec.ts b/src/app/fyle/view-per-diem/view-per-diem.page.spec.ts index ba50516d47..c6d40aa0b8 100644 --- a/src/app/fyle/view-per-diem/view-per-diem.page.spec.ts +++ b/src/app/fyle/view-per-diem/view-per-diem.page.spec.ts @@ -44,6 +44,7 @@ import { perDiemExpense } from 'src/app/core/mock-data/platform/v1/expense.data' import { ExpenseState } from 'src/app/core/models/expense-state.enum'; import { AccountType } from 'src/app/core/models/platform/v1/account.model'; import { CustomInput } from 'src/app/core/models/custom-input.model'; +import { ReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; describe('ViewPerDiemPage', () => { let component: ViewPerDiemPage; @@ -54,6 +55,7 @@ describe('ViewPerDiemPage', () => { let perDiemService: jasmine.SpyObj; let policyService: jasmine.SpyObj; let reportService: jasmine.SpyObj; + let platformReportsService: jasmine.SpyObj; let router: jasmine.SpyObj; let popoverController: jasmine.SpyObj; let statusService: jasmine.SpyObj; @@ -98,7 +100,7 @@ describe('ViewPerDiemPage', () => { ]); const spenderExpensesServiceSpy = jasmine.createSpyObj('SpenderExpensesService', ['getExpenseById']); const approverExpensesServiceSpy = jasmine.createSpyObj('ApproverExpensesService', ['getExpenseById']); - + const platformReportsServiceSpy = jasmine.createSpyObj('ReportsService', ['ejectExpenses']); TestBed.configureTestingModule({ declarations: [ViewPerDiemPage], imports: [IonicModule.forRoot()], @@ -120,6 +122,7 @@ describe('ViewPerDiemPage', () => { { provide: DependentFieldsService, useValue: dependentFieldsServiceSpy }, { provide: SpenderExpensesService, useValue: spenderExpensesServiceSpy }, { provide: ApproverExpensesService, useValue: approverExpensesServiceSpy }, + { provide: ReportsService, useValue: platformReportsServiceSpy }, { provide: ActivatedRoute, useValue: { @@ -144,6 +147,7 @@ describe('ViewPerDiemPage', () => { perDiemService = TestBed.inject(PerDiemService) as jasmine.SpyObj; policyService = TestBed.inject(PolicyService) as jasmine.SpyObj; reportService = TestBed.inject(ReportService) as jasmine.SpyObj; + platformReportsService = TestBed.inject(ReportsService) as jasmine.SpyObj; router = TestBed.inject(Router) as jasmine.SpyObj; popoverController = TestBed.inject(PopoverController) as jasmine.SpyObj; statusService = TestBed.inject(StatusService) as jasmine.SpyObj; @@ -670,7 +674,7 @@ describe('ViewPerDiemPage', () => { it('getDeleteDialogProps(): should return modal params', () => { const props = component.getDeleteDialogProps(); props.componentProps.deleteMethod(); - expect(reportService.removeTransaction).toHaveBeenCalledOnceWith(component.reportId, component.expenseId); + expect(platformReportsService.ejectExpenses).toHaveBeenCalledOnceWith(component.reportId, component.expenseId); }); it('removeExpenseFromReport(): should remove the expense from report', fakeAsync(() => { From 3ee69720919c7a357eda4350ca311323e8f719ac Mon Sep 17 00:00:00 2001 From: aastha Date: Fri, 19 Apr 2024 10:12:46 +0530 Subject: [PATCH 04/46] Minor --- .../v1/approver/reports.service.spec.ts | 22 +++++++++++++++++ .../platform/v1/approver/reports.service.ts | 21 ++++++++++++++++ .../v1/spender/reports.service.spec.ts | 10 ++++---- .../platform/v1/spender/reports.service.ts | 2 +- .../add-edit-expense-5.spec.ts | 6 ++--- .../add-edit-expense/add-edit-expense.page.ts | 6 ++--- .../add-edit-expense.setup.spec.ts | 6 ++--- .../add-edit-mileage-5.spec.ts | 6 ++--- .../add-edit-mileage.page.setup.spec.ts | 8 +++---- .../add-edit-mileage/add-edit-mileage.page.ts | 6 ++--- .../add-edit-per-diem-2.page.spec.ts | 6 ++--- .../add-edit-per-diem.page.setup.spec.ts | 8 +++---- .../add-edit-per-diem.page.ts | 6 ++--- .../view-expense/view-expense.page.spec.ts | 10 +++++++- .../fyle/view-expense/view-expense.page.ts | 4 ++-- .../view-mileage/view-mileage.page.spec.ts | 10 +++++++- .../fyle/view-mileage/view-mileage.page.ts | 4 ++-- .../view-per-diem/view-per-diem.page.spec.ts | 12 +++++----- .../fyle/view-per-diem/view-per-diem.page.ts | 4 ++-- .../fy-add-to-report.component.spec.ts | 24 +++++++++---------- .../fy-add-to-report.component.ts | 4 ++-- 21 files changed, 122 insertions(+), 63 deletions(-) create mode 100644 src/app/core/services/platform/v1/approver/reports.service.spec.ts create mode 100644 src/app/core/services/platform/v1/approver/reports.service.ts diff --git a/src/app/core/services/platform/v1/approver/reports.service.spec.ts b/src/app/core/services/platform/v1/approver/reports.service.spec.ts new file mode 100644 index 0000000000..1f0c7c4877 --- /dev/null +++ b/src/app/core/services/platform/v1/approver/reports.service.spec.ts @@ -0,0 +1,22 @@ +import { TestBed } from '@angular/core/testing'; +import { ApproverReportsService } from './reports.service'; +import { ApproverPlatformApiService } from '../../../approver-platform-api.service'; + +describe('ApproverReportsService', () => { + let reportsService: ApproverReportsService; + const approverPlatformApiService = jasmine.createSpyObj('ApproverPlatformApiService', ['get']); + + beforeEach(() => { + TestBed.configureTestingModule({ + providers: [ + ApproverReportsService, + { provide: ApproverPlatformApiService, useValue: approverPlatformApiService }, + ], + }); + reportsService = TestBed.inject(ApproverReportsService); + }); + + it('should be created', () => { + expect(reportsService).toBeTruthy(); + }); +}); diff --git a/src/app/core/services/platform/v1/approver/reports.service.ts b/src/app/core/services/platform/v1/approver/reports.service.ts new file mode 100644 index 0000000000..108d59dd57 --- /dev/null +++ b/src/app/core/services/platform/v1/approver/reports.service.ts @@ -0,0 +1,21 @@ +import { Injectable } from '@angular/core'; +import { Observable } from 'rxjs'; +import { ApproverPlatformApiService } from '../../../approver-platform-api.service'; + +@Injectable({ + providedIn: 'root', +}) +export class ApproverReportsService { + constructor(private approverPlatformApiService: ApproverPlatformApiService) {} + + ejectExpenses(rptId: string, txnId: string, comment?: string[]): Observable { + const payload = { + data: { + id: rptId, + expense_ids: [txnId], + }, + reason: comment, + }; + return this.approverPlatformApiService.post('/reports/eject_expenses', payload); + } +} diff --git a/src/app/core/services/platform/v1/spender/reports.service.spec.ts b/src/app/core/services/platform/v1/spender/reports.service.spec.ts index 1b50a17c9c..2db0203baa 100644 --- a/src/app/core/services/platform/v1/spender/reports.service.spec.ts +++ b/src/app/core/services/platform/v1/spender/reports.service.spec.ts @@ -1,5 +1,5 @@ import { TestBed } from '@angular/core/testing'; -import { ReportsService } from './reports.service'; +import { SpenderReportsService } from './reports.service'; import { SpenderPlatformV1ApiService } from '../../../spender-platform-v1-api.service'; import { of } from 'rxjs'; import { PAGINATION_SIZE } from 'src/app/constants'; @@ -13,19 +13,19 @@ import { } from 'src/app/core/mock-data/platform-report.data'; import { ReportsQueryParams } from 'src/app/core/models/platform/v1/reports-query-params.model'; -describe('ReportsService', () => { - let reportsService: ReportsService; +describe('SpenderReportsService', () => { + let reportsService: SpenderReportsService; const spenderPlatformV1ApiServiceMock = jasmine.createSpyObj('SpenderPlatformV1ApiService', ['get']); beforeEach(() => { TestBed.configureTestingModule({ providers: [ - ReportsService, + SpenderReportsService, { provide: PAGINATION_SIZE, useValue: 2 }, { provide: SpenderPlatformV1ApiService, useValue: spenderPlatformV1ApiServiceMock }, ], }); - reportsService = TestBed.inject(ReportsService); + reportsService = TestBed.inject(SpenderReportsService); }); it('should be created', () => { diff --git a/src/app/core/services/platform/v1/spender/reports.service.ts b/src/app/core/services/platform/v1/spender/reports.service.ts index b1eac04b41..21225ffcf5 100644 --- a/src/app/core/services/platform/v1/spender/reports.service.ts +++ b/src/app/core/services/platform/v1/spender/reports.service.ts @@ -12,7 +12,7 @@ import { PlatformApiPayload } from 'src/app/core/models/platform/platform-api-pa @Injectable({ providedIn: 'root', }) -export class ReportsService { +export class SpenderReportsService { constructor( @Inject(PAGINATION_SIZE) private paginationSize: number, private spenderPlatformV1ApiService: SpenderPlatformV1ApiService diff --git a/src/app/fyle/add-edit-expense/add-edit-expense-5.spec.ts b/src/app/fyle/add-edit-expense/add-edit-expense-5.spec.ts index e7a626f770..8985b70b1f 100644 --- a/src/app/fyle/add-edit-expense/add-edit-expense-5.spec.ts +++ b/src/app/fyle/add-edit-expense/add-edit-expense-5.spec.ts @@ -84,7 +84,7 @@ import { ProjectsService } from 'src/app/core/services/projects.service'; import { RecentLocalStorageItemsService } from 'src/app/core/services/recent-local-storage-items.service'; import { RecentlyUsedItemsService } from 'src/app/core/services/recently-used-items.service'; import { ReportService } from 'src/app/core/services/report.service'; -import { ReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; +import { SpenderReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; import { SnackbarPropertiesService } from 'src/app/core/services/snackbar-properties.service'; import { StatusService } from 'src/app/core/services/status.service'; import { StorageService } from 'src/app/core/services/storage.service'; @@ -121,7 +121,7 @@ export function TestCases5(getTestBed) { let dateService: jasmine.SpyObj; let projectsService: jasmine.SpyObj; let reportService: jasmine.SpyObj; - let platformReportService: jasmine.SpyObj; + let platformReportService: jasmine.SpyObj; let customInputsService: jasmine.SpyObj; let customFieldsService: jasmine.SpyObj; let transactionService: jasmine.SpyObj; @@ -172,7 +172,7 @@ export function TestCases5(getTestBed) { categoriesService = TestBed.inject(CategoriesService) as jasmine.SpyObj; dateService = TestBed.inject(DateService) as jasmine.SpyObj; reportService = TestBed.inject(ReportService) as jasmine.SpyObj; - platformReportService = TestBed.inject(ReportsService) as jasmine.SpyObj; + platformReportService = TestBed.inject(SpenderReportsService) as jasmine.SpyObj; projectsService = TestBed.inject(ProjectsService) as jasmine.SpyObj; customInputsService = TestBed.inject(CustomInputsService) as jasmine.SpyObj; customFieldsService = TestBed.inject(CustomFieldsService) as jasmine.SpyObj; diff --git a/src/app/fyle/add-edit-expense/add-edit-expense.page.ts b/src/app/fyle/add-edit-expense/add-edit-expense.page.ts index 522da72ed6..f43f0f07ed 100644 --- a/src/app/fyle/add-edit-expense/add-edit-expense.page.ts +++ b/src/app/fyle/add-edit-expense/add-edit-expense.page.ts @@ -108,7 +108,7 @@ import { ProjectsService } from 'src/app/core/services/projects.service'; import { RecentLocalStorageItemsService } from 'src/app/core/services/recent-local-storage-items.service'; import { RecentlyUsedItemsService } from 'src/app/core/services/recently-used-items.service'; import { ReportService } from 'src/app/core/services/report.service'; -import { ReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; +import { SpenderReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; import { SnackbarPropertiesService } from 'src/app/core/services/snackbar-properties.service'; import { StatusService } from 'src/app/core/services/status.service'; import { StorageService } from 'src/app/core/services/storage.service'; @@ -434,7 +434,7 @@ export class AddEditExpensePage implements OnInit { private dateService: DateService, private projectsService: ProjectsService, private reportService: ReportService, - private platformReportService: ReportsService, + private platformReportService: SpenderReportsService, private customInputsService: CustomInputsService, private customFieldsService: CustomFieldsService, private transactionService: TransactionService, @@ -472,7 +472,7 @@ export class AddEditExpensePage implements OnInit { private launchDarklyService: LaunchDarklyService, private platformHandlerService: PlatformHandlerService, private expensesService: ExpensesService, - private reportsService: ReportsService + private reportsService: SpenderReportsService ) {} get isExpandedView(): boolean { diff --git a/src/app/fyle/add-edit-expense/add-edit-expense.setup.spec.ts b/src/app/fyle/add-edit-expense/add-edit-expense.setup.spec.ts index c5b8556efa..65a2edc9da 100644 --- a/src/app/fyle/add-edit-expense/add-edit-expense.setup.spec.ts +++ b/src/app/fyle/add-edit-expense/add-edit-expense.setup.spec.ts @@ -38,7 +38,7 @@ import { ProjectsService } from 'src/app/core/services/projects.service'; import { RecentLocalStorageItemsService } from 'src/app/core/services/recent-local-storage-items.service'; import { RecentlyUsedItemsService } from 'src/app/core/services/recently-used-items.service'; import { ReportService } from 'src/app/core/services/report.service'; -import { ReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; +import { SpenderReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; import { SnackbarPropertiesService } from 'src/app/core/services/snackbar-properties.service'; import { StatusService } from 'src/app/core/services/status.service'; import { StorageService } from 'src/app/core/services/storage.service'; @@ -95,7 +95,7 @@ describe('AddEditExpensePage', () => { 'addTransactions', 'removeTransaction', ]); - const reportsServiceSpy = jasmine.createSpyObj('ReportsService', ['getAllReportsByParams']); + const reportsServiceSpy = jasmine.createSpyObj('SpenderReportsService', ['getAllReportsByParams']); const customInputsServiceSpy = jasmine.createSpyObj('CustomInputsService', ['getAll', 'filterByCategory']); const customFieldsServiceSpy = jasmine.createSpyObj('CustomFieldsService', ['standardizeCustomFields']); const transactionServiceSpy = jasmine.createSpyObj('TransactionService', [ @@ -259,7 +259,7 @@ describe('AddEditExpensePage', () => { useValue: reportServiceSpy, }, { - provide: ReportsService, + provide: SpenderReportsService, useValue: reportsServiceSpy, }, { diff --git a/src/app/fyle/add-edit-mileage/add-edit-mileage-5.spec.ts b/src/app/fyle/add-edit-mileage/add-edit-mileage-5.spec.ts index e44e4c3128..e78f69365f 100644 --- a/src/app/fyle/add-edit-mileage/add-edit-mileage-5.spec.ts +++ b/src/app/fyle/add-edit-mileage/add-edit-mileage-5.spec.ts @@ -65,7 +65,7 @@ import { ProjectsService } from 'src/app/core/services/projects.service'; import { RecentLocalStorageItemsService } from 'src/app/core/services/recent-local-storage-items.service'; import { RecentlyUsedItemsService } from 'src/app/core/services/recently-used-items.service'; import { ReportService } from 'src/app/core/services/report.service'; -import { ReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; +import { SpenderReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; import { SnackbarPropertiesService } from 'src/app/core/services/snackbar-properties.service'; import { StatusService } from 'src/app/core/services/status.service'; import { StorageService } from 'src/app/core/services/storage.service'; @@ -99,7 +99,7 @@ export function TestCases5(getTestBed) { let dateService: jasmine.SpyObj; let projectsService: jasmine.SpyObj; let reportService: jasmine.SpyObj; - let platformReportService: jasmine.SpyObj; + let platformReportService: jasmine.SpyObj; let customInputsService: jasmine.SpyObj; let customFieldsService: jasmine.SpyObj; let transactionService: jasmine.SpyObj; @@ -155,7 +155,7 @@ export function TestCases5(getTestBed) { categoriesService = TestBed.inject(CategoriesService) as jasmine.SpyObj; dateService = TestBed.inject(DateService) as jasmine.SpyObj; reportService = TestBed.inject(ReportService) as jasmine.SpyObj; - platformReportService = TestBed.inject(ReportsService) as jasmine.SpyObj; + platformReportService = TestBed.inject(SpenderReportsService) as jasmine.SpyObj; projectsService = TestBed.inject(ProjectsService) as jasmine.SpyObj; customInputsService = TestBed.inject(CustomInputsService) as jasmine.SpyObj; customFieldsService = TestBed.inject(CustomFieldsService) as jasmine.SpyObj; diff --git a/src/app/fyle/add-edit-mileage/add-edit-mileage.page.setup.spec.ts b/src/app/fyle/add-edit-mileage/add-edit-mileage.page.setup.spec.ts index 9e70e1a49d..50e026b695 100644 --- a/src/app/fyle/add-edit-mileage/add-edit-mileage.page.setup.spec.ts +++ b/src/app/fyle/add-edit-mileage/add-edit-mileage.page.setup.spec.ts @@ -38,7 +38,7 @@ import { ProjectsService } from 'src/app/core/services/projects.service'; import { RecentLocalStorageItemsService } from 'src/app/core/services/recent-local-storage-items.service'; import { RecentlyUsedItemsService } from 'src/app/core/services/recently-used-items.service'; import { ReportService } from 'src/app/core/services/report.service'; -import { ReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; +import { SpenderReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; import { SnackbarPropertiesService } from 'src/app/core/services/snackbar-properties.service'; import { StatusService } from 'src/app/core/services/status.service'; import { StorageService } from 'src/app/core/services/storage.service'; @@ -100,7 +100,7 @@ describe('AddEditMileagePage', () => { 'addTransactions', 'removeTransaction', ]); - const platformReportsServiceSpy = jasmine.createSpyObj('ReportsService', ['getAllReportsByParams']); + const platformSpenderReportsServiceSpy = jasmine.createSpyObj('SpenderReportsService', ['getAllReportsByParams']); const customInputsServiceSpy = jasmine.createSpyObj('CustomInputsService', ['getAll', 'filterByCategory']); const customFieldsServiceSpy = jasmine.createSpyObj('CustomFieldsService', ['standardizeCustomFields']); const transactionServiceSpy = jasmine.createSpyObj('TransactionService', [ @@ -285,8 +285,8 @@ describe('AddEditMileagePage', () => { useValue: reportServiceSpy, }, { - provide: ReportsService, - useValue: platformReportsServiceSpy, + provide: SpenderReportsService, + useValue: platformSpenderReportsServiceSpy, }, { provide: CustomInputsService, diff --git a/src/app/fyle/add-edit-mileage/add-edit-mileage.page.ts b/src/app/fyle/add-edit-mileage/add-edit-mileage.page.ts index 98f1ec98bf..7488fc3591 100644 --- a/src/app/fyle/add-edit-mileage/add-edit-mileage.page.ts +++ b/src/app/fyle/add-edit-mileage/add-edit-mileage.page.ts @@ -85,7 +85,7 @@ import { PolicyService } from 'src/app/core/services/policy.service'; import { ProjectsService } from 'src/app/core/services/projects.service'; import { RecentlyUsedItemsService } from 'src/app/core/services/recently-used-items.service'; import { ReportService } from 'src/app/core/services/report.service'; -import { ReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; +import { SpenderReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; import { SnackbarPropertiesService } from 'src/app/core/services/snackbar-properties.service'; import { StatusService } from 'src/app/core/services/status.service'; import { StorageService } from 'src/app/core/services/storage.service'; @@ -294,7 +294,7 @@ export class AddEditMileagePage implements OnInit { private customInputsService: CustomInputsService, private customFieldsService: CustomFieldsService, private reportService: ReportService, - private platformReportService: ReportsService, + private platformReportService: SpenderReportsService, private fb: FormBuilder, private projectService: ProjectsService, private mileageService: MileageService, @@ -326,7 +326,7 @@ export class AddEditMileagePage implements OnInit { private employeesService: EmployeesService, private expensesService: ExpensesService, private changeDetectorRef: ChangeDetectorRef, - private reportsService: ReportsService + private reportsService: SpenderReportsService ) {} get showSaveAndNext(): boolean { diff --git a/src/app/fyle/add-edit-per-diem/add-edit-per-diem-2.page.spec.ts b/src/app/fyle/add-edit-per-diem/add-edit-per-diem-2.page.spec.ts index ff5489585e..043072b803 100644 --- a/src/app/fyle/add-edit-per-diem/add-edit-per-diem-2.page.spec.ts +++ b/src/app/fyle/add-edit-per-diem/add-edit-per-diem-2.page.spec.ts @@ -19,7 +19,7 @@ import { PolicyService } from 'src/app/core/services/policy.service'; import { ProjectsService } from 'src/app/core/services/projects.service'; import { RecentlyUsedItemsService } from 'src/app/core/services/recently-used-items.service'; import { ReportService } from 'src/app/core/services/report.service'; -import { ReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; +import { SpenderReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; import { SnackbarPropertiesService } from 'src/app/core/services/snackbar-properties.service'; import { StatusService } from 'src/app/core/services/status.service'; import { StorageService } from 'src/app/core/services/storage.service'; @@ -105,7 +105,7 @@ export function TestCases2(getTestBed) { let dateService: jasmine.SpyObj; let projectsService: jasmine.SpyObj; let reportService: jasmine.SpyObj; - let platformReportService: jasmine.SpyObj; + let platformReportService: jasmine.SpyObj; let customInputsService: jasmine.SpyObj; let customFieldsService: jasmine.SpyObj; let transactionService: jasmine.SpyObj; @@ -147,7 +147,7 @@ export function TestCases2(getTestBed) { dateService = TestBed.inject(DateService) as jasmine.SpyObj; projectsService = TestBed.inject(ProjectsService) as jasmine.SpyObj; reportService = TestBed.inject(ReportService) as jasmine.SpyObj; - platformReportService = TestBed.inject(ReportsService) as jasmine.SpyObj; + platformReportService = TestBed.inject(SpenderReportsService) as jasmine.SpyObj; customInputsService = TestBed.inject(CustomInputsService) as jasmine.SpyObj; customFieldsService = TestBed.inject(CustomFieldsService) as jasmine.SpyObj; transactionService = TestBed.inject(TransactionService) as jasmine.SpyObj; diff --git a/src/app/fyle/add-edit-per-diem/add-edit-per-diem.page.setup.spec.ts b/src/app/fyle/add-edit-per-diem/add-edit-per-diem.page.setup.spec.ts index c271fda5ff..968f0e544a 100644 --- a/src/app/fyle/add-edit-per-diem/add-edit-per-diem.page.setup.spec.ts +++ b/src/app/fyle/add-edit-per-diem/add-edit-per-diem.page.setup.spec.ts @@ -14,7 +14,7 @@ import { CustomInputsService } from 'src/app/core/services/custom-inputs.service import { CustomFieldsService } from 'src/app/core/services/custom-fields.service'; import { CurrencyService } from 'src/app/core/services/currency.service'; import { ReportService } from 'src/app/core/services/report.service'; -import { ReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; +import { SpenderReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; import { ProjectsService } from 'src/app/core/services/projects.service'; import { TransactionsOutboxService } from 'src/app/core/services/transactions-outbox.service'; import { TransactionService } from 'src/app/core/services/transaction.service'; @@ -65,7 +65,7 @@ describe('AddEditPerDiemPage', () => { 'addTransactions', 'removeTransaction', ]); - const platformReportsServiceSpy = jasmine.createSpyObj('ReportsService', ['getAllReportsByParams']); + const platformSpenderReportsServiceSpy = jasmine.createSpyObj('SpenderReportsService', ['getAllReportsByParams']); const projectServiceSpy = jasmine.createSpyObj('ProjectService', [ 'getAllowedOrgCategoryIds', 'getProjectCount', @@ -170,8 +170,8 @@ describe('AddEditPerDiemPage', () => { useValue: reportServiceSpy, }, { - provide: ReportsService, - useValue: platformReportsServiceSpy, + provide: SpenderReportsService, + useValue: platformSpenderReportsServiceSpy, }, { provide: ProjectsService, 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 1eeed12dae..bba79dab26 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 @@ -47,7 +47,7 @@ import { CustomFieldsService } from 'src/app/core/services/custom-fields.service import { cloneDeep, isEmpty, isEqual, isNumber } from 'lodash'; import { CurrencyService } from 'src/app/core/services/currency.service'; import { ReportService } from 'src/app/core/services/report.service'; -import { ReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; +import { SpenderReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; import { ProjectsService } from 'src/app/core/services/projects.service'; import { TransactionService } from 'src/app/core/services/transaction.service'; import { LoaderService } from 'src/app/core/services/loader.service'; @@ -258,7 +258,7 @@ export class AddEditPerDiemPage implements OnInit { private customFieldsService: CustomFieldsService, private currencyService: CurrencyService, private reportService: ReportService, - private platformReportService: ReportsService, + private platformReportService: SpenderReportsService, private projectService: ProjectsService, private transactionsOutboxService: TransactionsOutboxService, private transactionService: TransactionService, @@ -287,7 +287,7 @@ export class AddEditPerDiemPage implements OnInit { private platform: Platform, private storageService: StorageService, private expensesService: ExpensesService, - private reportsService: ReportsService + private reportsService: SpenderReportsService ) {} get minPerDiemDate(): string { diff --git a/src/app/fyle/view-expense/view-expense.page.spec.ts b/src/app/fyle/view-expense/view-expense.page.spec.ts index 6adb2f2977..0bda1db69b 100644 --- a/src/app/fyle/view-expense/view-expense.page.spec.ts +++ b/src/app/fyle/view-expense/view-expense.page.spec.ts @@ -49,6 +49,7 @@ import { ExpenseState } from 'src/app/core/models/expense-state.enum'; import { TransactionStatusInfoPopoverComponent } from 'src/app/shared/components/transaction-status-info-popover/transaction-status-info-popover.component'; import { OrgSettings } from 'src/app/core/models/org-settings.model'; import { CustomInput } from 'src/app/core/models/custom-input.model'; +import { ApproverReportsService } from 'src/app/core/services/platform/v1/approver/reports.service'; describe('ViewExpensePage', () => { let component: ViewExpensePage; @@ -73,6 +74,7 @@ describe('ViewExpensePage', () => { let approverExpensesService: jasmine.SpyObj; let spenderExpensesService: jasmine.SpyObj; let activateRouteMock: ActivatedRoute; + let approverReportsService: jasmine.SpyObj; beforeEach(waitForAsync(() => { const loaderServiceSpy = jasmine.createSpyObj('LoaderService', ['hideLoader', 'showLoader']); @@ -117,6 +119,7 @@ describe('ViewExpensePage', () => { ]); const approverExpensesServiceSpy = jasmine.createSpyObj('ApproverExpensesService', ['getExpenseById']); const spenderExpensesServiceSpy = jasmine.createSpyObj('SpenderExpensesService', ['getExpenseById']); + const approverReportsServiceSpy = jasmine.createSpyObj('ApproverReportsService', ['ejectExpenses']); TestBed.configureTestingModule({ declarations: [ViewExpensePage], @@ -198,6 +201,10 @@ describe('ViewExpensePage', () => { useValue: spenderExpensesServiceSpy, provide: SpenderExpensesService, }, + { + provide: ApproverReportsService, + useValue: approverReportsServiceSpy, + }, { provide: ActivatedRoute, useValue: { @@ -236,6 +243,7 @@ describe('ViewExpensePage', () => { loaderService = TestBed.inject(LoaderService) as jasmine.SpyObj; approverExpensesService = TestBed.inject(ApproverExpensesService) as jasmine.SpyObj; spenderExpensesService = TestBed.inject(SpenderExpensesService) as jasmine.SpyObj; + approverReportsService = TestBed.inject(ApproverReportsService) as jasmine.SpyObj; activateRouteMock = TestBed.inject(ActivatedRoute); fixture.detectChanges(); @@ -965,7 +973,7 @@ describe('ViewExpensePage', () => { it('getDeleteDialogProps(): should return the props', () => { const props = component.getDeleteDialogProps(); props.componentProps.deleteMethod(); - expect(reportService.removeTransaction).toHaveBeenCalledOnceWith(component.reportId, component.expenseId); + expect(approverReportsService.ejectExpenses).toHaveBeenCalledOnceWith(component.reportId, component.expenseId); }); describe('removeExpenseFromReport', () => { diff --git a/src/app/fyle/view-expense/view-expense.page.ts b/src/app/fyle/view-expense/view-expense.page.ts index c4784ea428..f34175b9ba 100644 --- a/src/app/fyle/view-expense/view-expense.page.ts +++ b/src/app/fyle/view-expense/view-expense.page.ts @@ -35,7 +35,7 @@ import { Expense, TransactionStatus } from 'src/app/core/models/platform/v1/expe import { AccountType } from 'src/app/core/models/platform/v1/account.model'; import { ExpenseState } from 'src/app/core/models/expense-state.enum'; import { TransactionStatusInfoPopoverComponent } from 'src/app/shared/components/transaction-status-info-popover/transaction-status-info-popover.component'; -import { ReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; +import { ApproverReportsService } from 'src/app/core/services/platform/v1/approver/reports.service'; @Component({ selector: 'app-view-expense', @@ -152,7 +152,7 @@ export class ViewExpensePage { private dependentFieldsService: DependentFieldsService, private spenderExpensesService: SpenderExpensesService, private approverExpensesService: ApproverExpensesService, - private reportsService: ReportsService + private reportsService: ApproverReportsService ) {} get ExpenseView(): typeof ExpenseView { diff --git a/src/app/fyle/view-mileage/view-mileage.page.spec.ts b/src/app/fyle/view-mileage/view-mileage.page.spec.ts index 52bfed63a6..7e727ff787 100644 --- a/src/app/fyle/view-mileage/view-mileage.page.spec.ts +++ b/src/app/fyle/view-mileage/view-mileage.page.spec.ts @@ -47,6 +47,7 @@ import { ExpensesService as SpenderExpensesService } from 'src/app/core/services import { MileageRatesService } from 'src/app/core/services/mileage-rates.service'; import { platformMileageRatesSingleData } from 'src/app/core/mock-data/platform-mileage-rate.data'; import { CustomInput } from 'src/app/core/models/custom-input.model'; +import { ApproverReportsService } from 'src/app/core/services/platform/v1/approver/reports.service'; describe('ViewMileagePage', () => { let component: ViewMileagePage; @@ -71,6 +72,7 @@ describe('ViewMileagePage', () => { let approverExpensesService: jasmine.SpyObj; let mileageRatesService: jasmine.SpyObj; let activateRouteMock: ActivatedRoute; + let approverReportsService: jasmine.SpyObj; beforeEach(waitForAsync(() => { const loaderServiceSpy = jasmine.createSpyObj('LoaderService', ['hideLoader', 'showLoader']); @@ -112,6 +114,7 @@ describe('ViewMileagePage', () => { 'getSpenderMileageRateById', 'getApproverMileageRateById', ]); + const approverReportsServiceSpy = jasmine.createSpyObj('ApproverReportsService', ['ejectExpenses']); TestBed.configureTestingModule({ declarations: [ViewMileagePage], @@ -193,6 +196,10 @@ describe('ViewMileagePage', () => { useValue: mileageRatesServiceSpy, provide: MileageRatesService, }, + { + provide: ApproverReportsService, + useValue: approverReportsServiceSpy, + }, { provide: ActivatedRoute, useValue: { @@ -229,6 +236,7 @@ describe('ViewMileagePage', () => { spenderExpensesService = TestBed.inject(SpenderExpensesService) as jasmine.SpyObj; approverExpensesService = TestBed.inject(ApproverExpensesService) as jasmine.SpyObj; mileageRatesService = TestBed.inject(MileageRatesService) as jasmine.SpyObj; + approverReportsService = TestBed.inject(ApproverReportsService) as jasmine.SpyObj; activateRouteMock = TestBed.inject(ActivatedRoute); fixture.detectChanges(); @@ -358,7 +366,7 @@ describe('ViewMileagePage', () => { it('getDeleteDialogProps(): should return the props', () => { const props = component.getDeleteDialogProps(); props.componentProps.deleteMethod(); - expect(reportService.removeTransaction).toHaveBeenCalledOnceWith(component.reportId, component.expenseId); + expect(approverReportsService.ejectExpenses).toHaveBeenCalledOnceWith(component.reportId, component.expenseId); }); describe('removeExpenseFromReport', () => { diff --git a/src/app/fyle/view-mileage/view-mileage.page.ts b/src/app/fyle/view-mileage/view-mileage.page.ts index 98ecdb1b0e..a8e8baa91a 100644 --- a/src/app/fyle/view-mileage/view-mileage.page.ts +++ b/src/app/fyle/view-mileage/view-mileage.page.ts @@ -37,7 +37,7 @@ import { AccountType } from 'src/app/core/models/platform/v1/account.model'; import { ExpenseState } from 'src/app/core/models/expense-state.enum'; import { MileageRatesService } from 'src/app/core/services/mileage-rates.service'; import { PlatformMileageRates } from 'src/app/core/models/platform/platform-mileage-rates.model'; -import { ReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; +import { ApproverReportsService } from 'src/app/core/services/platform/v1/approver/reports.service'; @Component({ selector: 'app-view-mileage', @@ -132,7 +132,7 @@ export class ViewMileagePage { private approverExpensesService: ApproverExpensesService, private spenderExpensesService: SpenderExpensesService, private mileageRatesService: MileageRatesService, - private reportsService: ReportsService + private reportsService: ApproverReportsService ) {} get ExpenseView(): typeof ExpenseView { diff --git a/src/app/fyle/view-per-diem/view-per-diem.page.spec.ts b/src/app/fyle/view-per-diem/view-per-diem.page.spec.ts index c6d40aa0b8..0a4ad4dbe6 100644 --- a/src/app/fyle/view-per-diem/view-per-diem.page.spec.ts +++ b/src/app/fyle/view-per-diem/view-per-diem.page.spec.ts @@ -44,7 +44,7 @@ import { perDiemExpense } from 'src/app/core/mock-data/platform/v1/expense.data' import { ExpenseState } from 'src/app/core/models/expense-state.enum'; import { AccountType } from 'src/app/core/models/platform/v1/account.model'; import { CustomInput } from 'src/app/core/models/custom-input.model'; -import { ReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; +import { ApproverReportsService } from 'src/app/core/services/platform/v1/approver/reports.service'; describe('ViewPerDiemPage', () => { let component: ViewPerDiemPage; @@ -55,7 +55,7 @@ describe('ViewPerDiemPage', () => { let perDiemService: jasmine.SpyObj; let policyService: jasmine.SpyObj; let reportService: jasmine.SpyObj; - let platformReportsService: jasmine.SpyObj; + let approverReportsService: jasmine.SpyObj; let router: jasmine.SpyObj; let popoverController: jasmine.SpyObj; let statusService: jasmine.SpyObj; @@ -100,7 +100,7 @@ describe('ViewPerDiemPage', () => { ]); const spenderExpensesServiceSpy = jasmine.createSpyObj('SpenderExpensesService', ['getExpenseById']); const approverExpensesServiceSpy = jasmine.createSpyObj('ApproverExpensesService', ['getExpenseById']); - const platformReportsServiceSpy = jasmine.createSpyObj('ReportsService', ['ejectExpenses']); + const approverReportsServiceSpy = jasmine.createSpyObj('ApproverReportsService', ['ejectExpenses']); TestBed.configureTestingModule({ declarations: [ViewPerDiemPage], imports: [IonicModule.forRoot()], @@ -122,7 +122,7 @@ describe('ViewPerDiemPage', () => { { provide: DependentFieldsService, useValue: dependentFieldsServiceSpy }, { provide: SpenderExpensesService, useValue: spenderExpensesServiceSpy }, { provide: ApproverExpensesService, useValue: approverExpensesServiceSpy }, - { provide: ReportsService, useValue: platformReportsServiceSpy }, + { provide: ApproverReportsService, useValue: approverReportsServiceSpy }, { provide: ActivatedRoute, useValue: { @@ -147,7 +147,7 @@ describe('ViewPerDiemPage', () => { perDiemService = TestBed.inject(PerDiemService) as jasmine.SpyObj; policyService = TestBed.inject(PolicyService) as jasmine.SpyObj; reportService = TestBed.inject(ReportService) as jasmine.SpyObj; - platformReportsService = TestBed.inject(ReportsService) as jasmine.SpyObj; + approverReportsService = TestBed.inject(ApproverReportsService) as jasmine.SpyObj; router = TestBed.inject(Router) as jasmine.SpyObj; popoverController = TestBed.inject(PopoverController) as jasmine.SpyObj; statusService = TestBed.inject(StatusService) as jasmine.SpyObj; @@ -674,7 +674,7 @@ describe('ViewPerDiemPage', () => { it('getDeleteDialogProps(): should return modal params', () => { const props = component.getDeleteDialogProps(); props.componentProps.deleteMethod(); - expect(platformReportsService.ejectExpenses).toHaveBeenCalledOnceWith(component.reportId, component.expenseId); + expect(approverReportsService.ejectExpenses).toHaveBeenCalledOnceWith(component.reportId, component.expenseId); }); it('removeExpenseFromReport(): should remove the expense from report', fakeAsync(() => { diff --git a/src/app/fyle/view-per-diem/view-per-diem.page.ts b/src/app/fyle/view-per-diem/view-per-diem.page.ts index 6bec468a30..fe527ec20a 100644 --- a/src/app/fyle/view-per-diem/view-per-diem.page.ts +++ b/src/app/fyle/view-per-diem/view-per-diem.page.ts @@ -33,7 +33,7 @@ import { ExpensesService as ApproverExpensesService } from 'src/app/core/service import { ExpensesService as SpenderExpensesService } from 'src/app/core/services/platform/v1/spender/expenses.service'; import { AccountType } from 'src/app/core/models/platform/v1/account.model'; import { ExpenseState } from 'src/app/core/models/expense-state.enum'; -import { ReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; +import { SpenderReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; @Component({ selector: 'app-view-per-diem', @@ -118,7 +118,7 @@ export class ViewPerDiemPage { private dependentFieldsService: DependentFieldsService, private spenderExpensesService: SpenderExpensesService, private approverExpensesService: ApproverExpensesService, - private reportsService: ReportsService + private reportsService: SpenderReportsService ) {} get ExpenseView(): typeof ExpenseView { diff --git a/src/app/shared/components/fy-add-to-report/fy-add-to-report.component.spec.ts b/src/app/shared/components/fy-add-to-report/fy-add-to-report.component.spec.ts index 0c7f10a182..b25c9e79f7 100644 --- a/src/app/shared/components/fy-add-to-report/fy-add-to-report.component.spec.ts +++ b/src/app/shared/components/fy-add-to-report/fy-add-to-report.component.spec.ts @@ -5,7 +5,7 @@ import { FyAddToReportComponent } from './fy-add-to-report.component'; import { Injector, NO_ERRORS_SCHEMA } from '@angular/core'; import { FormControl, NG_VALUE_ACCESSOR, NgControl } from '@angular/forms'; import { ReportService } from 'src/app/core/services/report.service'; -import { ReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; +import { SpenderReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; import { ModalPropertiesService } from 'src/app/core/services/modal-properties.service'; import { TrackingService } from 'src/app/core/services/tracking.service'; import { expectedReportsPaginated } from 'src/app/core/mock-data/platform-report.data'; @@ -23,7 +23,7 @@ describe('FyAddToReportComponent', () => { let component: FyAddToReportComponent; let fixture: ComponentFixture; let reportService: jasmine.SpyObj; - let platformReportsService: jasmine.SpyObj; + let platformSpenderReportsService: jasmine.SpyObj; let modalController: jasmine.SpyObj; let modalProperties: jasmine.SpyObj; let popoverController: jasmine.SpyObj; @@ -36,7 +36,7 @@ describe('FyAddToReportComponent', () => { 'createDraft', 'getFilteredPendingReports', ]); - const platformReportsServiceSpy = jasmine.createSpyObj('ReportsService', [ + const platformSpenderReportsServiceSpy = jasmine.createSpyObj('SpenderReportsService', [ 'getAllReportsByParams', 'getReportsCount', 'getReportsByParams', @@ -71,8 +71,8 @@ describe('FyAddToReportComponent', () => { useValue: reportServiceSpy, }, { - provide: ReportsService, - useValue: platformReportsServiceSpy, + provide: SpenderReportsService, + useValue: platformSpenderReportsServiceSpy, }, { provide: ModalController, @@ -98,7 +98,7 @@ describe('FyAddToReportComponent', () => { component = fixture.componentInstance; fixture.debugElement.injector.get(NG_VALUE_ACCESSOR); reportService = TestBed.inject(ReportService) as jasmine.SpyObj; - platformReportsService = TestBed.inject(ReportsService) as jasmine.SpyObj; + platformSpenderReportsService = TestBed.inject(SpenderReportsService) as jasmine.SpyObj; modalController = TestBed.inject(ModalController) as jasmine.SpyObj; modalProperties = TestBed.inject(ModalPropertiesService) as jasmine.SpyObj; popoverController = TestBed.inject(PopoverController) as jasmine.SpyObj; @@ -181,8 +181,8 @@ describe('FyAddToReportComponent', () => { popoverController.create.and.resolveTo(draftReportPopoverSpy); // const mockReportData = cloneDeep(expectedReportsPaginated[1]); // mockReportData.id = 'rp72SaHM7Fbz'; - platformReportsService.createDraft.and.returnValue(of(expectedReportsPaginated[0])); - platformReportsService.getAllReportsByParams.and.returnValue(of(expectedReportsPaginated)); + platformSpenderReportsService.createDraft.and.returnValue(of(expectedReportsPaginated[0])); + platformSpenderReportsService.getAllReportsByParams.and.returnValue(of(expectedReportsPaginated)); }); it('should set value equals to value returned by modalController and track addToReportFromExpense and openAddToReportModal event if createDraftReport is false', fakeAsync(() => { @@ -204,7 +204,7 @@ describe('FyAddToReportComponent', () => { expect(component.value).toEqual(expectedReportsPaginated[0]); expect(trackingService.addToReportFromExpense).toHaveBeenCalledTimes(1); expect(trackingService.openAddToReportModal).toHaveBeenCalledTimes(1); - expect(platformReportsService.createDraft).not.toHaveBeenCalled(); + expect(platformSpenderReportsService.createDraft).not.toHaveBeenCalled(); expect(trackingService.createDraftReportFromExpense).not.toHaveBeenCalled(); expect(trackingService.openCreateDraftReportPopover).not.toHaveBeenCalled(); })); @@ -227,10 +227,10 @@ describe('FyAddToReportComponent', () => { expect(modalProperties.getModalDefaultProperties).toHaveBeenCalledTimes(1); expect(popoverController.create).toHaveBeenCalledOnceWith(popoverControllerParams3); expect(reportService.getReportPurpose).toHaveBeenCalledOnceWith({ ids: null }); - expect(platformReportsService.getAllReportsByParams).toHaveBeenCalledOnceWith({ + expect(platformSpenderReportsService.getAllReportsByParams).toHaveBeenCalledOnceWith({ state: 'in.(DRAFT,APPROVER_PENDING,APPROVER_INQUIRY)', }); - expect(platformReportsService.createDraft).toHaveBeenCalledOnceWith({ + expect(platformSpenderReportsService.createDraft).toHaveBeenCalledOnceWith({ data: { purpose: 'Client Meeting', source: 'MOBILE', @@ -248,7 +248,7 @@ describe('FyAddToReportComponent', () => { it('should set value to undefined if createDraftReport is true and none of the filtered reports id matches with newly created report id', fakeAsync(() => { const mockReportData = cloneDeep(expectedReportsPaginated[1]); mockReportData.id = 'rp72SaHM7Fbz'; - platformReportsService.createDraft.and.returnValue(of(mockReportData)); + platformSpenderReportsService.createDraft.and.returnValue(of(mockReportData)); let selectionModalControllerSpy = jasmine.createSpyObj('selectionModal', ['present', 'onWillDismiss']); selectionModalControllerSpy.onWillDismiss.and.resolveTo({ data: { diff --git a/src/app/shared/components/fy-add-to-report/fy-add-to-report.component.ts b/src/app/shared/components/fy-add-to-report/fy-add-to-report.component.ts index 8b6ae8677e..08b3d42357 100644 --- a/src/app/shared/components/fy-add-to-report/fy-add-to-report.component.ts +++ b/src/app/shared/components/fy-add-to-report/fy-add-to-report.component.ts @@ -7,7 +7,7 @@ import { isEqual } from 'lodash'; import { FyAddToReportModalComponent } from './fy-add-to-report-modal/fy-add-to-report-modal.component'; import { ModalPropertiesService } from 'src/app/core/services/modal-properties.service'; import { ReportService } from 'src/app/core/services/report.service'; -import { ReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; +import { SpenderReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; import { FyInputPopoverComponent } from '../fy-input-popover/fy-input-popover.component'; import { TrackingService } from 'src/app/core/services/tracking.service'; import { Report } from 'src/app/core/models/platform/v1/report.model'; @@ -65,7 +65,7 @@ export class FyAddToReportComponent implements OnInit, OnChanges, ControlValueAc private injector: Injector, private popoverController: PopoverController, private reportService: ReportService, - private platformReportService: ReportsService, + private platformReportService: SpenderReportsService, private trackingService: TrackingService ) {} From 8b6d202a5f9fff44b7114d3282bc9d811a18ec19 Mon Sep 17 00:00:00 2001 From: aastha Date: Fri, 19 Apr 2024 11:34:08 +0530 Subject: [PATCH 05/46] Minor --- .../add-edit-expense-2.spec.ts | 7 ++++-- .../add-edit-expense-4.spec.ts | 11 +++++--- .../add-edit-expense/add-edit-expense.page.ts | 9 +++---- .../add-edit-expense.setup.spec.ts | 3 +-- .../add-edit-mileage-1.spec.ts | 7 ++++-- .../add-edit-mileage-3.spec.ts | 9 ++++--- .../add-edit-mileage.page.setup.spec.ts | 6 +++-- .../add-edit-mileage/add-edit-mileage.page.ts | 9 +++---- .../add-edit-per-diem-4.page.spec.ts | 25 +++++++++++-------- .../add-edit-per-diem-5.page.spec.ts | 9 ++++--- .../add-edit-per-diem.page.setup.spec.ts | 6 +++-- .../add-edit-per-diem.page.ts | 9 +++---- .../view-expense/view-expense.page.spec.ts | 2 +- .../view-mileage/view-mileage.page.spec.ts | 2 +- .../view-per-diem/view-per-diem.page.spec.ts | 2 +- .../fyle/view-per-diem/view-per-diem.page.ts | 4 +-- 16 files changed, 69 insertions(+), 51 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 1bca90b734..4b156191a4 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 @@ -114,6 +114,7 @@ import { transformedExpenseWithExtractedData2, } from 'src/app/core/mock-data/transformed-expense.data'; import { apiExpenses1, apiExpenses2, splitExpensesData } from 'src/app/core/mock-data/platform/v1/expense.data'; +import { SpenderReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; const properties = { cssClass: 'fy-modal', @@ -174,6 +175,7 @@ export function TestCases2(getTestBed) { let storageService: jasmine.SpyObj; let launchDarklyService: jasmine.SpyObj; let expensesService: jasmine.SpyObj; + let reportsService: jasmine.SpyObj; beforeEach(() => { const TestBed = getTestBed(); @@ -230,6 +232,7 @@ export function TestCases2(getTestBed) { storageService = TestBed.inject(StorageService) as jasmine.SpyObj; launchDarklyService = TestBed.inject(LaunchDarklyService) as jasmine.SpyObj; expensesService = TestBed.inject(ExpensesService) as jasmine.SpyObj; + reportsService = TestBed.inject(SpenderReportsService) as jasmine.SpyObj; component.fg = formBuilder.group({ currencyObj: [, component.currencyObjValidator], @@ -1215,7 +1218,7 @@ export function TestCases2(getTestBed) { describe('getDeleteReportParams():', () => { it('should return modal params and method to remove expense from report', () => { - reportService.removeTransaction.and.returnValue(of()); + reportsService.ejectExpenses.and.returnValue(of()); component .getDeleteReportParams( @@ -1224,7 +1227,7 @@ export function TestCases2(getTestBed) { 'rpId' ) .componentProps.deleteMethod(); - expect(reportService.removeTransaction).toHaveBeenCalledTimes(1); + expect(reportsService.ejectExpenses).toHaveBeenCalledTimes(1); }); it('should return modal params and method to delete expense', () => { diff --git a/src/app/fyle/add-edit-expense/add-edit-expense-4.spec.ts b/src/app/fyle/add-edit-expense/add-edit-expense-4.spec.ts index cb0db3ec22..31fdd5161c 100644 --- a/src/app/fyle/add-edit-expense/add-edit-expense-4.spec.ts +++ b/src/app/fyle/add-edit-expense/add-edit-expense-4.spec.ts @@ -99,6 +99,7 @@ import { transformedExpenseWithMatchCCCData, transformedExpenseWithMatchCCCData2, } from 'src/app/core/mock-data/transformed-expense.data'; +import { SpenderReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; export function TestCases4(getTestBed) { return describe('AddEditExpensePage-4', () => { @@ -112,6 +113,7 @@ export function TestCases4(getTestBed) { let dateService: jasmine.SpyObj; let projectsService: jasmine.SpyObj; let reportService: jasmine.SpyObj; + let spenderReportsService: jasmine.SpyObj; let customInputsService: jasmine.SpyObj; let customFieldsService: jasmine.SpyObj; let transactionService: jasmine.SpyObj; @@ -163,6 +165,7 @@ export function TestCases4(getTestBed) { categoriesService = TestBed.inject(CategoriesService) as jasmine.SpyObj; dateService = TestBed.inject(DateService) as jasmine.SpyObj; reportService = TestBed.inject(ReportService) as jasmine.SpyObj; + spenderReportsService = TestBed.inject(SpenderReportsService) as jasmine.SpyObj; projectsService = TestBed.inject(ProjectsService) as jasmine.SpyObj; customInputsService = TestBed.inject(CustomInputsService) as jasmine.SpyObj; customFieldsService = TestBed.inject(CustomFieldsService) as jasmine.SpyObj; @@ -959,7 +962,7 @@ export function TestCases4(getTestBed) { component.fg.controls.report.setValue(expectedReportsPaginated[0]); policyService.getCriticalPolicyRules.and.returnValue([]); policyService.getPolicyRules.and.returnValue([]); - reportService.removeTransaction.and.returnValue(of(undefined)); + spenderReportsService.ejectExpenses.and.returnValue(of(undefined)); reportService.addTransactions.and.returnValue(of(undefined)); authService.getEou.and.resolveTo(apiEouRes); transactionService.upsert.and.returnValue(of(transformedExpenseDataWithReportId.tx)); @@ -983,7 +986,7 @@ export function TestCases4(getTestBed) { expect(expensesService.getExpenseById).toHaveBeenCalledOnceWith('txD5hIQgLuR5'); expect(transactionService.transformExpense).toHaveBeenCalledOnceWith(platformExpenseDataWithReportId); expect(reportService.addTransactions).toHaveBeenCalledOnceWith('rprAfNrce73O', ['txD5hIQgLuR5']); - expect(reportService.removeTransaction).toHaveBeenCalledOnceWith('rpbNc3kn5baq', 'txD5hIQgLuR5'); + expect(spenderReportsService.ejectExpenses).toHaveBeenCalledOnceWith('rpbNc3kn5baq', 'txD5hIQgLuR5'); done(); }); }); @@ -998,7 +1001,7 @@ export function TestCases4(getTestBed) { component.etxn$ = of(transformedExpenseDataWithReportId2); policyService.getCriticalPolicyRules.and.returnValue([]); policyService.getPolicyRules.and.returnValue([]); - reportService.removeTransaction.and.returnValue(of(undefined)); + spenderReportsService.ejectExpenses.and.returnValue(of(undefined)); authService.getEou.and.resolveTo(apiEouRes); transactionService.upsert.and.returnValue(of(transformedExpenseDataWithReportId2.tx)); expensesService.getExpenseById.and.returnValue(of(platformExpenseDataWithReportId2)); @@ -1017,7 +1020,7 @@ export function TestCases4(getTestBed) { expect(component.trackPolicyCorrections).toHaveBeenCalledTimes(1); expect(authService.getEou).toHaveBeenCalledTimes(1); expect(component.trackEditExpense).toHaveBeenCalledOnceWith(transformedExpenseDataWithReportId2); - expect(reportService.removeTransaction).toHaveBeenCalledOnceWith('rplD17WeBlha', 'txD5hIQgLuR5'); + expect(spenderReportsService.ejectExpenses).toHaveBeenCalledOnceWith('rplD17WeBlha', 'txD5hIQgLuR5'); expect(trackingService.removeFromExistingReportEditExpense).toHaveBeenCalledTimes(1); expect(transactionService.upsert).toHaveBeenCalledOnceWith(transformedExpenseDataWithReportId2.tx); expect(expensesService.getExpenseById).toHaveBeenCalledOnceWith('txD5hIQgLuR5'); diff --git a/src/app/fyle/add-edit-expense/add-edit-expense.page.ts b/src/app/fyle/add-edit-expense/add-edit-expense.page.ts index f43f0f07ed..96ba3d2694 100644 --- a/src/app/fyle/add-edit-expense/add-edit-expense.page.ts +++ b/src/app/fyle/add-edit-expense/add-edit-expense.page.ts @@ -471,8 +471,7 @@ export class AddEditExpensePage implements OnInit { private storageService: StorageService, private launchDarklyService: LaunchDarklyService, private platformHandlerService: PlatformHandlerService, - private expensesService: ExpensesService, - private reportsService: SpenderReportsService + private expensesService: ExpensesService ) {} get isExpandedView(): boolean { @@ -3901,7 +3900,7 @@ export class AddEditExpensePage implements OnInit { } if (txnCopy.tx.report_id && selectedReportId && txnCopy.tx.report_id !== selectedReportId) { - return this.reportsService.ejectExpenses(txnCopy.tx.report_id, tx.id).pipe( + return this.platformReportService.ejectExpenses(txnCopy.tx.report_id, tx.id).pipe( switchMap(() => this.reportService.addTransactions(selectedReportId, [tx.id])), tap(() => this.trackingService.addToExistingReportAddEditExpense()), map(() => tx) @@ -3909,7 +3908,7 @@ export class AddEditExpensePage implements OnInit { } if (txnCopy.tx.report_id && !selectedReportId) { - return this.reportsService.ejectExpenses(txnCopy.tx.report_id, tx.id).pipe( + return this.platformReportService.ejectExpenses(txnCopy.tx.report_id, tx.id).pipe( tap(() => this.trackingService.removeFromExistingReportEditExpense()), map(() => tx) ); @@ -4673,7 +4672,7 @@ export class AddEditExpensePage implements OnInit { ctaLoadingText: config.ctaLoadingText, deleteMethod: (): Observable => { if (removeExpenseFromReport) { - return this.reportsService.ejectExpenses(reportId, this.activatedRoute.snapshot.params.id as string); + return this.platformReportService.ejectExpenses(reportId, this.activatedRoute.snapshot.params.id as string); } return this.transactionService.delete(this.activatedRoute.snapshot.params.id as string); }, diff --git a/src/app/fyle/add-edit-expense/add-edit-expense.setup.spec.ts b/src/app/fyle/add-edit-expense/add-edit-expense.setup.spec.ts index 65a2edc9da..3a56d228d2 100644 --- a/src/app/fyle/add-edit-expense/add-edit-expense.setup.spec.ts +++ b/src/app/fyle/add-edit-expense/add-edit-expense.setup.spec.ts @@ -93,9 +93,8 @@ describe('AddEditExpensePage', () => { 'getAutoSubmissionReportName', 'getFilteredPendingReports', 'addTransactions', - 'removeTransaction', ]); - const reportsServiceSpy = jasmine.createSpyObj('SpenderReportsService', ['getAllReportsByParams']); + const reportsServiceSpy = jasmine.createSpyObj('SpenderReportsService', ['getAllReportsByParams', 'ejectExpenses']); const customInputsServiceSpy = jasmine.createSpyObj('CustomInputsService', ['getAll', 'filterByCategory']); const customFieldsServiceSpy = jasmine.createSpyObj('CustomFieldsService', ['standardizeCustomFields']); const transactionServiceSpy = jasmine.createSpyObj('TransactionService', [ diff --git a/src/app/fyle/add-edit-mileage/add-edit-mileage-1.spec.ts b/src/app/fyle/add-edit-mileage/add-edit-mileage-1.spec.ts index f85005758c..4af092b537 100644 --- a/src/app/fyle/add-edit-mileage/add-edit-mileage-1.spec.ts +++ b/src/app/fyle/add-edit-mileage/add-edit-mileage-1.spec.ts @@ -77,6 +77,7 @@ import { AddEditMileagePage } from './add-edit-mileage.page'; import { extendedAccountData1 } from 'src/app/core/mock-data/extended-account.data'; import { platformExpenseData } from 'src/app/core/mock-data/platform/v1/expense.data'; import { transformedExpenseData } from 'src/app/core/mock-data/transformed-expense.data'; +import { SpenderReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; export function TestCases1(getTestBed) { return describe('AddEditMileage-1', () => { @@ -90,6 +91,7 @@ export function TestCases1(getTestBed) { let dateService: jasmine.SpyObj; let projectsService: jasmine.SpyObj; let reportService: jasmine.SpyObj; + let spenderReportsService: jasmine.SpyObj; let customInputsService: jasmine.SpyObj; let customFieldsService: jasmine.SpyObj; let transactionService: jasmine.SpyObj; @@ -188,6 +190,7 @@ export function TestCases1(getTestBed) { mileageService = TestBed.inject(MileageService) as jasmine.SpyObj; mileageRatesService = TestBed.inject(MileageRatesService) as jasmine.SpyObj; locationService = TestBed.inject(LocationService) as jasmine.SpyObj; + spenderReportsService = TestBed.inject(SpenderReportsService) as jasmine.SpyObj; component.fg = formBuilder.group({ mileage_rate_name: [], @@ -584,7 +587,7 @@ export function TestCases1(getTestBed) { let ctaLoadingText = 'loading'; it('should get config params for delete report modal and call method to remove txn from report', () => { - reportService.removeTransaction.and.returnValue(of()); + spenderReportsService.ejectExpenses.and.returnValue(of()); const result = component.getDeleteReportParams({ header, @@ -597,7 +600,7 @@ export function TestCases1(getTestBed) { }); result.componentProps.deleteMethod(); - expect(reportService.removeTransaction).toHaveBeenCalledOnceWith('rp123', 'txn123'); + expect(spenderReportsService.ejectExpenses).toHaveBeenCalledOnceWith('rp123', 'txn123'); }); it('should get config params for delete report modal and call method to delete expense', () => { 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 2cbf30fbf3..8170a04795 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 @@ -96,6 +96,7 @@ import { transformedExpenseDataWithReportId, transformedExpenseDataWithSubCategory, } from 'src/app/core/mock-data/transformed-expense.data'; +import { SpenderReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; export function TestCases3(getTestBed) { return describe('AddEditMileage-3', () => { @@ -148,6 +149,7 @@ export function TestCases3(getTestBed) { let mileageService: jasmine.SpyObj; let mileageRatesService: jasmine.SpyObj; let locationService: jasmine.SpyObj; + let spenderReportsService: jasmine.SpyObj; beforeEach(() => { const TestBed = getTestBed(); @@ -207,6 +209,7 @@ export function TestCases3(getTestBed) { mileageService = TestBed.inject(MileageService) as jasmine.SpyObj; mileageRatesService = TestBed.inject(MileageRatesService) as jasmine.SpyObj; locationService = TestBed.inject(LocationService) as jasmine.SpyObj; + spenderReportsService = TestBed.inject(SpenderReportsService) as jasmine.SpyObj; component.fg = formBuilder.group({ mileage_rate_name: [], @@ -596,7 +599,7 @@ export function TestCases3(getTestBed) { spyOn(component, 'trackEditExpense'); authService.getEou.and.resolveTo(apiEouRes); reportService.addTransactions.and.returnValue(of(null)); - reportService.removeTransaction.and.returnValue(of(null)); + spenderReportsService.ejectExpenses.and.returnValue(of(null)); }); it('should edit an expense', (done) => { @@ -679,7 +682,7 @@ export function TestCases3(getTestBed) { expect(expensesService.getExpenseById).toHaveBeenCalledOnceWith(transformedExpenseDataWithReportId.tx.id); expect(transactionService.transformExpense).toHaveBeenCalledOnceWith(platformExpenseDataWithReportId); expect(component.getFormValues).toHaveBeenCalledTimes(1); - expect(reportService.removeTransaction).toHaveBeenCalledOnceWith( + expect(spenderReportsService.ejectExpenses).toHaveBeenCalledOnceWith( transformedExpenseDataWithReportId.tx.report_id, transformedExpenseDataWithReportId.tx.id ); @@ -724,7 +727,7 @@ export function TestCases3(getTestBed) { expect(expensesService.getExpenseById).toHaveBeenCalledOnceWith(transformedExpenseDataWithReportId.tx.id); expect(transactionService.transformExpense).toHaveBeenCalledOnceWith(platformExpenseDataWithReportId); expect(component.getFormValues).toHaveBeenCalledTimes(1); - expect(reportService.removeTransaction).toHaveBeenCalledOnceWith( + expect(spenderReportsService.ejectExpenses).toHaveBeenCalledOnceWith( transformedExpenseDataWithReportId.tx.report_id, transformedExpenseDataWithReportId.tx.id ); diff --git a/src/app/fyle/add-edit-mileage/add-edit-mileage.page.setup.spec.ts b/src/app/fyle/add-edit-mileage/add-edit-mileage.page.setup.spec.ts index 50e026b695..3757b8fa81 100644 --- a/src/app/fyle/add-edit-mileage/add-edit-mileage.page.setup.spec.ts +++ b/src/app/fyle/add-edit-mileage/add-edit-mileage.page.setup.spec.ts @@ -98,9 +98,11 @@ describe('AddEditMileagePage', () => { 'getAutoSubmissionReportName', 'getFilteredPendingReports', 'addTransactions', - 'removeTransaction', ]); - const platformSpenderReportsServiceSpy = jasmine.createSpyObj('SpenderReportsService', ['getAllReportsByParams']); + const platformSpenderReportsServiceSpy = jasmine.createSpyObj('SpenderReportsService', [ + 'getAllReportsByParams', + 'ejectExpenses', + ]); const customInputsServiceSpy = jasmine.createSpyObj('CustomInputsService', ['getAll', 'filterByCategory']); const customFieldsServiceSpy = jasmine.createSpyObj('CustomFieldsService', ['standardizeCustomFields']); const transactionServiceSpy = jasmine.createSpyObj('TransactionService', [ diff --git a/src/app/fyle/add-edit-mileage/add-edit-mileage.page.ts b/src/app/fyle/add-edit-mileage/add-edit-mileage.page.ts index 7488fc3591..e57856998c 100644 --- a/src/app/fyle/add-edit-mileage/add-edit-mileage.page.ts +++ b/src/app/fyle/add-edit-mileage/add-edit-mileage.page.ts @@ -325,8 +325,7 @@ export class AddEditMileagePage implements OnInit { private storageService: StorageService, private employeesService: EmployeesService, private expensesService: ExpensesService, - private changeDetectorRef: ChangeDetectorRef, - private reportsService: SpenderReportsService + private changeDetectorRef: ChangeDetectorRef ) {} get showSaveAndNext(): boolean { @@ -2579,7 +2578,7 @@ export class AddEditMileagePage implements OnInit { } if (txnCopy.tx.report_id && selectedReportId && txnCopy.tx.report_id !== selectedReportId) { - return this.reportsService.ejectExpenses(txnCopy.tx.report_id, tx.id).pipe( + return this.platformReportService.ejectExpenses(txnCopy.tx.report_id, tx.id).pipe( switchMap(() => this.reportService.addTransactions(selectedReportId, [tx.id])), tap(() => this.trackingService.addToExistingReportAddEditExpense()), map(() => tx) @@ -2587,7 +2586,7 @@ export class AddEditMileagePage implements OnInit { } if (txnCopy.tx.report_id && !selectedReportId) { - return this.reportsService.ejectExpenses(txnCopy.tx.report_id, tx.id).pipe( + return this.platformReportService.ejectExpenses(txnCopy.tx.report_id, tx.id).pipe( tap(() => this.trackingService.removeFromExistingReportEditExpense()), map(() => tx) ); @@ -2877,7 +2876,7 @@ export class AddEditMileagePage implements OnInit { ctaLoadingText: config.ctaLoadingText, deleteMethod: (): Observable => { if (config.removeMileageFromReport) { - return this.reportsService.ejectExpenses(config.reportId, config.id); + return this.platformReportService.ejectExpenses(config.reportId, config.id); } return this.transactionService.delete(config.id); }, diff --git a/src/app/fyle/add-edit-per-diem/add-edit-per-diem-4.page.spec.ts b/src/app/fyle/add-edit-per-diem/add-edit-per-diem-4.page.spec.ts index 1cda69aa5a..cc62b1090a 100644 --- a/src/app/fyle/add-edit-per-diem/add-edit-per-diem-4.page.spec.ts +++ b/src/app/fyle/add-edit-per-diem/add-edit-per-diem-4.page.spec.ts @@ -56,6 +56,7 @@ import { outboxQueueData1 } from 'src/app/core/mock-data/outbox-queue.data'; import { PerDiemRedirectedFrom } from 'src/app/core/models/per-diem-redirected-from.enum'; import { platformExpenseData } from 'src/app/core/mock-data/platform/v1/expense.data'; import { transformedExpenseData } from 'src/app/core/mock-data/transformed-expense.data'; +import { SpenderReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; export function TestCases4(getTestBed) { return describe('add-edit-per-diem test cases set 4', () => { @@ -96,6 +97,7 @@ export function TestCases4(getTestBed) { let orgUserSettingsService: jasmine.SpyObj; let storageService: jasmine.SpyObj; let perDiemService: jasmine.SpyObj; + let spenderReportsService: jasmine.SpyObj; beforeEach(waitForAsync(() => { const TestBed = getTestBed(); @@ -137,6 +139,7 @@ export function TestCases4(getTestBed) { orgUserSettingsService = TestBed.inject(OrgUserSettingsService) as jasmine.SpyObj; storageService = TestBed.inject(StorageService) as jasmine.SpyObj; perDiemService = TestBed.inject(PerDiemService) as jasmine.SpyObj; + spenderReportsService = TestBed.inject(SpenderReportsService) as jasmine.SpyObj; component.fg = formBuilder.group({ currencyObj: [ { @@ -306,7 +309,7 @@ export function TestCases4(getTestBed) { expensesService.getExpenseById.and.returnValue(of(platformExpenseData)); transactionService.transformExpense.and.returnValue(transformedExpenseData); reportService.addTransactions.and.returnValue(of(undefined)); - reportService.removeTransaction.and.returnValue(of(undefined)); + spenderReportsService.ejectExpenses.and.returnValue(of(undefined)); transactionService.review.and.returnValue(of(null)); statusService.findLatestComment.and.returnValue(of('comment1')); statusService.post.and.returnValue(of(expenseStatusData)); @@ -350,7 +353,7 @@ export function TestCases4(getTestBed) { expect(expensesService.getExpenseById).toHaveBeenCalledOnceWith(platformExpenseData.id); expect(transactionService.transformExpense).toHaveBeenCalledOnceWith(platformExpenseData); expect(reportService.addTransactions).toHaveBeenCalledOnceWith('rprAfNrce73O', ['txvslh8aQMbu']); - expect(reportService.removeTransaction).not.toHaveBeenCalled(); + expect(spenderReportsService.ejectExpenses).not.toHaveBeenCalled(); expect(trackingService.addToExistingReportAddEditExpense).toHaveBeenCalledTimes(1); expect(trackingService.removeFromExistingReportEditExpense).not.toHaveBeenCalled(); expect(res).toEqual(transformedExpenseData.tx); @@ -395,7 +398,7 @@ export function TestCases4(getTestBed) { expect(expensesService.getExpenseById).toHaveBeenCalledOnceWith(platformExpenseData.id); expect(transactionService.transformExpense).toHaveBeenCalledOnceWith(platformExpenseData); expect(reportService.addTransactions).toHaveBeenCalledOnceWith('rprAfNrce73O', ['txvslh8aQMbu']); - expect(reportService.removeTransaction).toHaveBeenCalledOnceWith('rpbNc3kn5baq', 'txvslh8aQMbu'); + expect(spenderReportsService.ejectExpenses).toHaveBeenCalledOnceWith('rpbNc3kn5baq', 'txvslh8aQMbu'); expect(trackingService.addToExistingReportAddEditExpense).toHaveBeenCalledTimes(1); expect(trackingService.removeFromExistingReportEditExpense).not.toHaveBeenCalled(); expect(res).toEqual(transformedExpenseData.tx); @@ -441,7 +444,7 @@ export function TestCases4(getTestBed) { expect(expensesService.getExpenseById).toHaveBeenCalledOnceWith(platformExpenseData.id); expect(transactionService.transformExpense).toHaveBeenCalledOnceWith(platformExpenseData); expect(reportService.addTransactions).not.toHaveBeenCalled(); - expect(reportService.removeTransaction).toHaveBeenCalledOnceWith('rp8eUleN29dc', 'txvslh8aQMbu'); + expect(spenderReportsService.ejectExpenses).toHaveBeenCalledOnceWith('rp8eUleN29dc', 'txvslh8aQMbu'); expect(trackingService.addToExistingReportAddEditExpense).not.toHaveBeenCalled(); expect(trackingService.removeFromExistingReportEditExpense).toHaveBeenCalledTimes(1); expect(res).toEqual(transformedExpenseData.tx); @@ -486,7 +489,7 @@ export function TestCases4(getTestBed) { expect(expensesService.getExpenseById).toHaveBeenCalledOnceWith(platformExpenseData.id); expect(transactionService.transformExpense).toHaveBeenCalledOnceWith(platformExpenseData); expect(reportService.addTransactions).toHaveBeenCalledOnceWith('rprAfNrce73O', ['txvslh8aQMbu']); - expect(reportService.removeTransaction).not.toHaveBeenCalled(); + expect(spenderReportsService.ejectExpenses).not.toHaveBeenCalled(); expect(trackingService.addToExistingReportAddEditExpense).toHaveBeenCalledTimes(1); expect(trackingService.removeFromExistingReportEditExpense).not.toHaveBeenCalled(); expect(statusService.findLatestComment).toHaveBeenCalledOnceWith( @@ -545,7 +548,7 @@ export function TestCases4(getTestBed) { expect(expensesService.getExpenseById).toHaveBeenCalledOnceWith(platformExpenseData.id); expect(transactionService.transformExpense).toHaveBeenCalledOnceWith(platformExpenseData); expect(reportService.addTransactions).toHaveBeenCalledOnceWith('rprAfNrce73O', ['txvslh8aQMbu']); - expect(reportService.removeTransaction).not.toHaveBeenCalled(); + expect(spenderReportsService.ejectExpenses).not.toHaveBeenCalled(); expect(trackingService.addToExistingReportAddEditExpense).toHaveBeenCalledTimes(1); expect(trackingService.removeFromExistingReportEditExpense).not.toHaveBeenCalled(); expect(statusService.findLatestComment).toHaveBeenCalledOnceWith( @@ -602,7 +605,7 @@ export function TestCases4(getTestBed) { expect(expensesService.getExpenseById).toHaveBeenCalledOnceWith(platformExpenseData.id); expect(transactionService.transformExpense).toHaveBeenCalledOnceWith(platformExpenseData); expect(reportService.addTransactions).toHaveBeenCalledOnceWith('rprAfNrce73O', ['txvslh8aQMbu']); - expect(reportService.removeTransaction).not.toHaveBeenCalled(); + expect(spenderReportsService.ejectExpenses).not.toHaveBeenCalled(); expect(trackingService.addToExistingReportAddEditExpense).toHaveBeenCalledTimes(1); expect(trackingService.removeFromExistingReportEditExpense).not.toHaveBeenCalled(); expect(statusService.findLatestComment).toHaveBeenCalledOnceWith( @@ -658,7 +661,7 @@ export function TestCases4(getTestBed) { expect(expensesService.getExpenseById).toHaveBeenCalledOnceWith(platformExpenseData.id); expect(transactionService.transformExpense).toHaveBeenCalledOnceWith(platformExpenseData); expect(reportService.addTransactions).toHaveBeenCalledOnceWith('rprAfNrce73O', ['txvslh8aQMbu']); - expect(reportService.removeTransaction).not.toHaveBeenCalled(); + expect(spenderReportsService.ejectExpenses).not.toHaveBeenCalled(); expect(trackingService.addToExistingReportAddEditExpense).toHaveBeenCalledTimes(1); expect(trackingService.removeFromExistingReportEditExpense).not.toHaveBeenCalled(); expect(statusService.findLatestComment).toHaveBeenCalledOnceWith( @@ -713,7 +716,7 @@ export function TestCases4(getTestBed) { expect(expensesService.getExpenseById).toHaveBeenCalledOnceWith(platformExpenseData.id); expect(transactionService.transformExpense).toHaveBeenCalledOnceWith(platformExpenseData); expect(reportService.addTransactions).not.toHaveBeenCalled(); - expect(reportService.removeTransaction).not.toHaveBeenCalled(); + expect(spenderReportsService.ejectExpenses).not.toHaveBeenCalled(); expect(trackingService.addToExistingReportAddEditExpense).not.toHaveBeenCalled(); expect(trackingService.removeFromExistingReportEditExpense).not.toHaveBeenCalled(); expect(statusService.findLatestComment).toHaveBeenCalledOnceWith( @@ -764,7 +767,7 @@ export function TestCases4(getTestBed) { expect(expensesService.getExpenseById).toHaveBeenCalledOnceWith(platformExpenseData.id); expect(transactionService.transformExpense).toHaveBeenCalledOnceWith(platformExpenseData); expect(reportService.addTransactions).toHaveBeenCalledOnceWith('rprAfNrce73O', ['txvslh8aQMbu']); - expect(reportService.removeTransaction).not.toHaveBeenCalled(); + expect(spenderReportsService.ejectExpenses).not.toHaveBeenCalled(); expect(trackingService.addToExistingReportAddEditExpense).toHaveBeenCalledTimes(1); expect(trackingService.removeFromExistingReportEditExpense).not.toHaveBeenCalled(); expect(res).toEqual(transformedExpenseData.tx); @@ -809,7 +812,7 @@ export function TestCases4(getTestBed) { expect(expensesService.getExpenseById).toHaveBeenCalledOnceWith(platformExpenseData.id); expect(transactionService.transformExpense).toHaveBeenCalledOnceWith(platformExpenseData); expect(reportService.addTransactions).toHaveBeenCalledOnceWith('rprAfNrce73O', ['txvslh8aQMbu']); - expect(reportService.removeTransaction).not.toHaveBeenCalled(); + expect(spenderReportsService.ejectExpenses).not.toHaveBeenCalled(); expect(trackingService.addToExistingReportAddEditExpense).toHaveBeenCalledTimes(1); expect(trackingService.removeFromExistingReportEditExpense).not.toHaveBeenCalled(); expect(res).toEqual(transformedExpenseData.tx); diff --git a/src/app/fyle/add-edit-per-diem/add-edit-per-diem-5.page.spec.ts b/src/app/fyle/add-edit-per-diem/add-edit-per-diem-5.page.spec.ts index 5d7c4174d9..c6484db6d6 100644 --- a/src/app/fyle/add-edit-per-diem/add-edit-per-diem-5.page.spec.ts +++ b/src/app/fyle/add-edit-per-diem/add-edit-per-diem-5.page.spec.ts @@ -45,6 +45,7 @@ import { individualExpPolicyStateData1 } from 'src/app/core/mock-data/individual import { PerDiemRedirectedFrom } from 'src/app/core/models/per-diem-redirected-from.enum'; import { platformExpenseData } from 'src/app/core/mock-data/platform/v1/expense.data'; import { transformedExpenseData } from 'src/app/core/mock-data/transformed-expense.data'; +import { SpenderReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; export function TestCases5(getTestBed) { return describe('add-edit-per-diem test cases set 5', () => { @@ -58,6 +59,7 @@ export function TestCases5(getTestBed) { let dateService: jasmine.SpyObj; let projectsService: jasmine.SpyObj; let reportService: jasmine.SpyObj; + let spenderReportsService: jasmine.SpyObj; let customInputsService: jasmine.SpyObj; let customFieldsService: jasmine.SpyObj; let transactionService: jasmine.SpyObj; @@ -126,6 +128,7 @@ export function TestCases5(getTestBed) { orgUserSettingsService = TestBed.inject(OrgUserSettingsService) as jasmine.SpyObj; storageService = TestBed.inject(StorageService) as jasmine.SpyObj; perDiemService = TestBed.inject(PerDiemService) as jasmine.SpyObj; + spenderReportsService = TestBed.inject(SpenderReportsService) as jasmine.SpyObj; component.fg = formBuilder.group({ currencyObj: [ { @@ -348,7 +351,7 @@ export function TestCases5(getTestBed) { describe('getDeleteReportParams():', () => { it('should return modal params and method to remove expense from report if removePerDiemFromReport is true', () => { - reportService.removeTransaction.and.returnValue(of()); + spenderReportsService.ejectExpenses.and.returnValue(of()); component .getDeleteReportParams( @@ -358,7 +361,7 @@ export function TestCases5(getTestBed) { 'rpFE5X1Pqi9P' ) .componentProps.deleteMethod(); - expect(reportService.removeTransaction).toHaveBeenCalledOnceWith('rpFE5X1Pqi9P', 'tx5n59fvxk4z'); + expect(spenderReportsService.ejectExpenses).toHaveBeenCalledOnceWith('rpFE5X1Pqi9P', 'tx5n59fvxk4z'); expect(transactionService.delete).not.toHaveBeenCalled(); }); @@ -372,7 +375,7 @@ export function TestCases5(getTestBed) { ) .componentProps.deleteMethod(); expect(transactionService.delete).toHaveBeenCalledOnceWith('tx5n59fvxk4z'); - expect(reportService.removeTransaction).not.toHaveBeenCalled(); + expect(spenderReportsService.ejectExpenses).not.toHaveBeenCalled(); }); }); diff --git a/src/app/fyle/add-edit-per-diem/add-edit-per-diem.page.setup.spec.ts b/src/app/fyle/add-edit-per-diem/add-edit-per-diem.page.setup.spec.ts index 968f0e544a..47f56d983c 100644 --- a/src/app/fyle/add-edit-per-diem/add-edit-per-diem.page.setup.spec.ts +++ b/src/app/fyle/add-edit-per-diem/add-edit-per-diem.page.setup.spec.ts @@ -63,9 +63,11 @@ describe('AddEditPerDiemPage', () => { 'getReportById', 'getFilteredPendingReports', 'addTransactions', - 'removeTransaction', ]); - const platformSpenderReportsServiceSpy = jasmine.createSpyObj('SpenderReportsService', ['getAllReportsByParams']); + const platformSpenderReportsServiceSpy = jasmine.createSpyObj('SpenderReportsService', [ + 'getAllReportsByParams', + 'ejectExpenses', + ]); const projectServiceSpy = jasmine.createSpyObj('ProjectService', [ 'getAllowedOrgCategoryIds', 'getProjectCount', 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 bba79dab26..fadbc5609f 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 @@ -286,8 +286,7 @@ export class AddEditPerDiemPage implements OnInit { private orgSettingsService: OrgSettingsService, private platform: Platform, private storageService: StorageService, - private expensesService: ExpensesService, - private reportsService: SpenderReportsService + private expensesService: ExpensesService ) {} get minPerDiemDate(): string { @@ -2062,7 +2061,7 @@ export class AddEditPerDiemPage implements OnInit { } if (txnCopy.tx.report_id && selectedReportId && selectedReportId !== txnCopy.tx.report_id) { - return this.reportsService.ejectExpenses(txnCopy.tx.report_id, tx.id).pipe( + return this.platformReportService.ejectExpenses(txnCopy.tx.report_id, tx.id).pipe( switchMap(() => this.reportService.addTransactions(selectedReportId, [tx.id])), tap(() => this.trackingService.addToExistingReportAddEditExpense()), map(() => tx) @@ -2070,7 +2069,7 @@ export class AddEditPerDiemPage implements OnInit { } if (txnCopy.tx.report_id && !selectedReportId) { - return this.reportsService.ejectExpenses(txnCopy.tx.report_id, tx.id).pipe( + return this.platformReportService.ejectExpenses(txnCopy.tx.report_id, tx.id).pipe( tap(() => this.trackingService.removeFromExistingReportEditExpense()), map(() => tx) ); @@ -2279,7 +2278,7 @@ export class AddEditPerDiemPage implements OnInit { ctaLoadingText: config.ctaLoadingText, deleteMethod: (): Observable => { if (removePerDiemFromReport) { - return this.reportsService.ejectExpenses(reportId, id); + return this.platformReportService.ejectExpenses(reportId, id); } return this.transactionService.delete(id); }, diff --git a/src/app/fyle/view-expense/view-expense.page.spec.ts b/src/app/fyle/view-expense/view-expense.page.spec.ts index 0bda1db69b..798b9c12a0 100644 --- a/src/app/fyle/view-expense/view-expense.page.spec.ts +++ b/src/app/fyle/view-expense/view-expense.page.spec.ts @@ -79,7 +79,7 @@ describe('ViewExpensePage', () => { beforeEach(waitForAsync(() => { const loaderServiceSpy = jasmine.createSpyObj('LoaderService', ['hideLoader', 'showLoader']); const transactionServiceSpy = jasmine.createSpyObj('TransactionService', ['manualUnflag', 'manualFlag']); - const reportServiceSpy = jasmine.createSpyObj('ReportService', ['getTeamReport', 'removeTransaction']); + const reportServiceSpy = jasmine.createSpyObj('ReportService', ['getTeamReport']); const customInputsServiceSpy = jasmine.createSpyObj('CustomInputsService', [ 'getCustomPropertyDisplayValue', 'fillCustomProperties', diff --git a/src/app/fyle/view-mileage/view-mileage.page.spec.ts b/src/app/fyle/view-mileage/view-mileage.page.spec.ts index 7e727ff787..d568b846c7 100644 --- a/src/app/fyle/view-mileage/view-mileage.page.spec.ts +++ b/src/app/fyle/view-mileage/view-mileage.page.spec.ts @@ -77,7 +77,7 @@ describe('ViewMileagePage', () => { beforeEach(waitForAsync(() => { const loaderServiceSpy = jasmine.createSpyObj('LoaderService', ['hideLoader', 'showLoader']); const transactionServiceSpy = jasmine.createSpyObj('TransactionService', ['manualUnflag', 'manualFlag']); - const reportServiceSpy = jasmine.createSpyObj('ReportService', ['getTeamReport', 'removeTransaction']); + const reportServiceSpy = jasmine.createSpyObj('ReportService', ['getTeamReport']); const customInputsServiceSpy = jasmine.createSpyObj('CustomInputsService', [ 'getCustomPropertyDisplayValue', 'fillCustomProperties', diff --git a/src/app/fyle/view-per-diem/view-per-diem.page.spec.ts b/src/app/fyle/view-per-diem/view-per-diem.page.spec.ts index 0a4ad4dbe6..e0555e5576 100644 --- a/src/app/fyle/view-per-diem/view-per-diem.page.spec.ts +++ b/src/app/fyle/view-per-diem/view-per-diem.page.spec.ts @@ -81,7 +81,7 @@ describe('ViewPerDiemPage', () => { 'getApproverExpensePolicyViolations', 'getSpenderExpensePolicyViolations', ]); - const reportServiceSpy = jasmine.createSpyObj('ReportService', ['getTeamReport', 'removeTransaction']); + const reportServiceSpy = jasmine.createSpyObj('ReportService', ['getTeamReport']); const routerSpy = jasmine.createSpyObj('Router', ['navigate']); const popoverControllerSpy = jasmine.createSpyObj('PopoverController', ['create']); const statusServiceSpy = jasmine.createSpyObj('StatusService', ['find', 'post']); diff --git a/src/app/fyle/view-per-diem/view-per-diem.page.ts b/src/app/fyle/view-per-diem/view-per-diem.page.ts index fe527ec20a..b3b3e685fb 100644 --- a/src/app/fyle/view-per-diem/view-per-diem.page.ts +++ b/src/app/fyle/view-per-diem/view-per-diem.page.ts @@ -33,7 +33,7 @@ import { ExpensesService as ApproverExpensesService } from 'src/app/core/service import { ExpensesService as SpenderExpensesService } from 'src/app/core/services/platform/v1/spender/expenses.service'; import { AccountType } from 'src/app/core/models/platform/v1/account.model'; import { ExpenseState } from 'src/app/core/models/expense-state.enum'; -import { SpenderReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; +import { ApproverReportsService } from 'src/app/core/services/platform/v1/approver/reports.service'; @Component({ selector: 'app-view-per-diem', @@ -118,7 +118,7 @@ export class ViewPerDiemPage { private dependentFieldsService: DependentFieldsService, private spenderExpensesService: SpenderExpensesService, private approverExpensesService: ApproverExpensesService, - private reportsService: SpenderReportsService + private reportsService: ApproverReportsService ) {} get ExpenseView(): typeof ExpenseView { From a4c88ba43a2431177a32471f927089c3acc45e1b Mon Sep 17 00:00:00 2001 From: Aastha Bist Date: Fri, 19 Apr 2024 12:33:39 +0530 Subject: [PATCH 06/46] Update reports.service.spec.ts --- .../services/platform/v1/approver/reports.service.spec.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/app/core/services/platform/v1/approver/reports.service.spec.ts b/src/app/core/services/platform/v1/approver/reports.service.spec.ts index 1f0c7c4877..53fce3735e 100644 --- a/src/app/core/services/platform/v1/approver/reports.service.spec.ts +++ b/src/app/core/services/platform/v1/approver/reports.service.spec.ts @@ -3,7 +3,7 @@ import { ApproverReportsService } from './reports.service'; import { ApproverPlatformApiService } from '../../../approver-platform-api.service'; describe('ApproverReportsService', () => { - let reportsService: ApproverReportsService; + let approverReportsService: ApproverReportsService; const approverPlatformApiService = jasmine.createSpyObj('ApproverPlatformApiService', ['get']); beforeEach(() => { @@ -13,10 +13,10 @@ describe('ApproverReportsService', () => { { provide: ApproverPlatformApiService, useValue: approverPlatformApiService }, ], }); - reportsService = TestBed.inject(ApproverReportsService); + approverReportsService = TestBed.inject(ApproverReportsService); }); it('should be created', () => { - expect(reportsService).toBeTruthy(); + expect(approverReportsService).toBeTruthy(); }); }); From e1a2cfe675491467e5e06fbb7c51c854266cc5e7 Mon Sep 17 00:00:00 2001 From: Aastha Bist Date: Fri, 19 Apr 2024 12:34:42 +0530 Subject: [PATCH 07/46] Update reports.service.spec.ts --- .../v1/spender/reports.service.spec.ts | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/app/core/services/platform/v1/spender/reports.service.spec.ts b/src/app/core/services/platform/v1/spender/reports.service.spec.ts index 2db0203baa..8c080d94ef 100644 --- a/src/app/core/services/platform/v1/spender/reports.service.spec.ts +++ b/src/app/core/services/platform/v1/spender/reports.service.spec.ts @@ -14,7 +14,7 @@ import { import { ReportsQueryParams } from 'src/app/core/models/platform/v1/reports-query-params.model'; describe('SpenderReportsService', () => { - let reportsService: SpenderReportsService; + let spenderReportsService: SpenderReportsService; const spenderPlatformV1ApiServiceMock = jasmine.createSpyObj('SpenderPlatformV1ApiService', ['get']); beforeEach(() => { @@ -25,16 +25,16 @@ describe('SpenderReportsService', () => { { provide: SpenderPlatformV1ApiService, useValue: spenderPlatformV1ApiServiceMock }, ], }); - reportsService = TestBed.inject(SpenderReportsService); + spenderReportsService = TestBed.inject(SpenderReportsService); }); it('should be created', () => { - expect(reportsService).toBeTruthy(); + expect(spenderReportsService).toBeTruthy(); }); it('getReportsCount(): should get a count of reports', (done) => { // Mock the response of getReportsByParams - spyOn(reportsService, 'getReportsByParams').and.returnValue(of(platformReportCountData)); + spyOn(spenderReportsService, 'getReportsByParams').and.returnValue(of(platformReportCountData)); const expectedParams: ReportsQueryParams = { ...mockQueryParams, @@ -42,17 +42,17 @@ describe('SpenderReportsService', () => { offset: 0, }; - reportsService.getReportsCount(mockQueryParams).subscribe((res) => { + spenderReportsService.getReportsCount(mockQueryParams).subscribe((res) => { // Verify expect(res).toEqual(4); // Check if the count is as expected - expect(reportsService.getReportsByParams).toHaveBeenCalledWith(expectedParams); // Check if the method is called with the expected params + expect(spenderReportsService.getReportsByParams).toHaveBeenCalledWith(expectedParams); // Check if the method is called with the expected params done(); // Call 'done' to indicate the end of the asynchronous test }); }); it('getAllReportsByParams(): should get all reports multiple pages', (done) => { - const getReportsByParams = spyOn(reportsService, 'getReportsByParams'); - spyOn(reportsService, 'getReportsCount').and.returnValue(of(4)); + const getReportsByParams = spyOn(spenderReportsService, 'getReportsByParams'); + spyOn(spenderReportsService, 'getReportsCount').and.returnValue(of(4)); const expectedParams1: ReportsQueryParams = { ...mockQueryParams, @@ -68,9 +68,9 @@ describe('SpenderReportsService', () => { getReportsByParams.withArgs(expectedParams1).and.returnValue(of(allReportsPaginated1)); getReportsByParams.withArgs(expectedParams2).and.returnValue(of(allReportsPaginated2)); - reportsService.getAllReportsByParams(mockQueryParams).subscribe((res) => { + spenderReportsService.getAllReportsByParams(mockQueryParams).subscribe((res) => { expect(res).toEqual(expectedReportsPaginated); - expect(reportsService.getReportsCount).toHaveBeenCalledOnceWith({ + expect(spenderReportsService.getReportsCount).toHaveBeenCalledOnceWith({ state: 'in.(DRAFT,APPROVER_PENDING,APPROVER_INQUIRY)', }); expect(getReportsByParams).toHaveBeenCalledWith(expectedParams1); @@ -81,8 +81,8 @@ describe('SpenderReportsService', () => { }); it('getAllReportsByParams(): should get all reports single page', (done) => { - const getReportsByParams = spyOn(reportsService, 'getReportsByParams'); - spyOn(reportsService, 'getReportsCount').and.returnValue(of(1)); + const getReportsByParams = spyOn(spenderReportsService, 'getReportsByParams'); + spyOn(spenderReportsService, 'getReportsCount').and.returnValue(of(1)); const expectedParams: ReportsQueryParams = { ...mockQueryParams, @@ -92,9 +92,9 @@ describe('SpenderReportsService', () => { getReportsByParams.withArgs(expectedParams).and.returnValue(of(allReportsPaginated1)); - reportsService.getAllReportsByParams(mockQueryParams).subscribe((res) => { + spenderReportsService.getAllReportsByParams(mockQueryParams).subscribe((res) => { expect(res).toEqual(expectedReportsSinglePage); - expect(reportsService.getReportsCount).toHaveBeenCalledOnceWith(mockQueryParams); + expect(spenderReportsService.getReportsCount).toHaveBeenCalledOnceWith(mockQueryParams); expect(getReportsByParams).toHaveBeenCalledOnceWith(expectedParams); done(); }); @@ -112,7 +112,7 @@ describe('SpenderReportsService', () => { }, }; spenderPlatformV1ApiServiceMock.get.and.returnValue(of(allReportsPaginated1)); - reportsService.getReportsByParams(queryParams).subscribe((response) => { + spenderReportsService.getReportsByParams(queryParams).subscribe((response) => { expect(response).toEqual(allReportsPaginated1); expect(spenderPlatformV1ApiServiceMock.get).toHaveBeenCalledOnceWith('/reports', expectedConfig); done(); From 20433c7503c07851a933e48ff27c7daee42f0a2a Mon Sep 17 00:00:00 2001 From: Aastha Bist Date: Fri, 19 Apr 2024 12:49:44 +0530 Subject: [PATCH 08/46] Update view-expense.page.ts --- src/app/fyle/view-expense/view-expense.page.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/fyle/view-expense/view-expense.page.ts b/src/app/fyle/view-expense/view-expense.page.ts index f34175b9ba..70666a9a3c 100644 --- a/src/app/fyle/view-expense/view-expense.page.ts +++ b/src/app/fyle/view-expense/view-expense.page.ts @@ -152,7 +152,7 @@ export class ViewExpensePage { private dependentFieldsService: DependentFieldsService, private spenderExpensesService: SpenderExpensesService, private approverExpensesService: ApproverExpensesService, - private reportsService: ApproverReportsService + private approverReportsService: ApproverReportsService ) {} get ExpenseView(): typeof ExpenseView { @@ -467,7 +467,7 @@ export class ViewExpensePage { infoMessage: 'The report amount will be adjusted accordingly.', ctaText: 'Remove', ctaLoadingText: 'Removing', - deleteMethod: (): Observable => this.reportsService.ejectExpenses(this.reportId, this.expenseId), + deleteMethod: (): Observable => this.approverReportsService.ejectExpenses(this.reportId, this.expenseId), }, }; } From 6cd27884bfd2c328450ba3f744d19fdd4a08da0f Mon Sep 17 00:00:00 2001 From: Aastha Bist Date: Fri, 19 Apr 2024 12:50:37 +0530 Subject: [PATCH 09/46] Update view-mileage.page.ts --- src/app/fyle/view-mileage/view-mileage.page.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/fyle/view-mileage/view-mileage.page.ts b/src/app/fyle/view-mileage/view-mileage.page.ts index a8e8baa91a..320ed88b81 100644 --- a/src/app/fyle/view-mileage/view-mileage.page.ts +++ b/src/app/fyle/view-mileage/view-mileage.page.ts @@ -132,7 +132,7 @@ export class ViewMileagePage { private approverExpensesService: ApproverExpensesService, private spenderExpensesService: SpenderExpensesService, private mileageRatesService: MileageRatesService, - private reportsService: ApproverReportsService + private approverReportsService: ApproverReportsService ) {} get ExpenseView(): typeof ExpenseView { @@ -219,7 +219,7 @@ export class ViewMileagePage { infoMessage: 'The report amount will be adjusted accordingly.', ctaText: 'Remove', ctaLoadingText: 'Removing', - deleteMethod: (): Observable => this.reportsService.ejectExpenses(this.reportId, this.expenseId), + deleteMethod: (): Observable => this.approverReportsService.ejectExpenses(this.reportId, this.expenseId), }, }; } From 0f6d6465610fc228129ed0921bdd3d365de8dad8 Mon Sep 17 00:00:00 2001 From: Aastha Bist Date: Fri, 19 Apr 2024 12:51:56 +0530 Subject: [PATCH 10/46] Update view-per-diem.page.ts --- src/app/fyle/view-per-diem/view-per-diem.page.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/fyle/view-per-diem/view-per-diem.page.ts b/src/app/fyle/view-per-diem/view-per-diem.page.ts index b3b3e685fb..5014945182 100644 --- a/src/app/fyle/view-per-diem/view-per-diem.page.ts +++ b/src/app/fyle/view-per-diem/view-per-diem.page.ts @@ -118,7 +118,7 @@ export class ViewPerDiemPage { private dependentFieldsService: DependentFieldsService, private spenderExpensesService: SpenderExpensesService, private approverExpensesService: ApproverExpensesService, - private reportsService: ApproverReportsService + private approverReportsService: ApproverReportsService ) {} get ExpenseView(): typeof ExpenseView { @@ -354,7 +354,7 @@ export class ViewPerDiemPage { infoMessage: 'The report amount will be adjusted accordingly.', ctaText: 'Remove', ctaLoadingText: 'Removing', - deleteMethod: (): Observable => this.reportsService.ejectExpenses(this.reportId, this.expenseId), + deleteMethod: (): Observable => this.approverReportsService.ejectExpenses(this.reportId, this.expenseId), }, }; } From f0aa09b60804e212810d20a07ce73fc63681553a Mon Sep 17 00:00:00 2001 From: Aastha Bist Date: Thu, 25 Apr 2024 09:28:37 +0530 Subject: [PATCH 11/46] Update reports.service.ts --- src/app/core/services/platform/v1/approver/reports.service.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/core/services/platform/v1/approver/reports.service.ts b/src/app/core/services/platform/v1/approver/reports.service.ts index 108d59dd57..9003899580 100644 --- a/src/app/core/services/platform/v1/approver/reports.service.ts +++ b/src/app/core/services/platform/v1/approver/reports.service.ts @@ -8,11 +8,11 @@ import { ApproverPlatformApiService } from '../../../approver-platform-api.servi export class ApproverReportsService { constructor(private approverPlatformApiService: ApproverPlatformApiService) {} - ejectExpenses(rptId: string, txnId: string, comment?: string[]): Observable { + ejectExpenses(rptId: string, expenseId: string, comment?: string[]): Observable { const payload = { data: { id: rptId, - expense_ids: [txnId], + expense_ids: [expenseId], }, reason: comment, }; From cafd8c338f5327cf992b7fd42ef3d56b51bd710b Mon Sep 17 00:00:00 2001 From: Aastha Bist Date: Thu, 25 Apr 2024 13:29:03 +0530 Subject: [PATCH 12/46] feat: Move add expenses to platform (#2878) --- .../v1/approver/reports.service.spec.ts | 22 ++++++++- .../v1/spender/reports.service.spec.ts | 49 +++++++++++++++++-- .../platform/v1/spender/reports.service.ts | 10 ++++ src/app/core/services/report.service.spec.ts | 14 ------ src/app/core/services/report.service.ts | 15 ------ .../transactions-outbox.service.spec.ts | 10 ++-- .../services/transactions-outbox.service.ts | 8 +-- .../add-edit-expense-4.spec.ts | 8 +-- .../add-edit-expense/add-edit-expense.page.ts | 4 +- .../add-edit-expense.setup.spec.ts | 6 ++- .../add-edit-mileage-3.spec.ts | 8 +-- .../add-edit-mileage.page.setup.spec.ts | 1 + .../add-edit-mileage/add-edit-mileage.page.ts | 4 +- .../add-edit-per-diem-4.page.spec.ts | 22 ++++----- .../add-edit-per-diem.page.setup.spec.ts | 1 + .../add-edit-per-diem.page.ts | 4 +- .../dashboard/tasks/tasks-3.component.spec.ts | 10 ++-- .../tasks/tasks.component.setup.spec.ts | 3 ++ .../fyle/dashboard/tasks/tasks.component.ts | 6 ++- .../my-create-report.page.spec.ts | 12 ++++- .../my-create-report/my-create-report.page.ts | 6 ++- .../fyle/my-expenses/my-expenses.page.spec.ts | 12 ++++- src/app/fyle/my-expenses/my-expenses.page.ts | 6 ++- .../my-view-report.page.spec.ts | 15 +++++- .../my-view-report/my-view-report.page.ts | 6 ++- .../create-new-report.component.spec.ts | 9 +++- .../create-new-report.component.ts | 6 ++- .../create-new-report.component.spec.ts | 9 +++- .../create-new-report.component.ts | 6 ++- 29 files changed, 198 insertions(+), 94 deletions(-) diff --git a/src/app/core/services/platform/v1/approver/reports.service.spec.ts b/src/app/core/services/platform/v1/approver/reports.service.spec.ts index 53fce3735e..542a5ab864 100644 --- a/src/app/core/services/platform/v1/approver/reports.service.spec.ts +++ b/src/app/core/services/platform/v1/approver/reports.service.spec.ts @@ -1,10 +1,11 @@ import { TestBed } from '@angular/core/testing'; import { ApproverReportsService } from './reports.service'; import { ApproverPlatformApiService } from '../../../approver-platform-api.service'; +import { of } from 'rxjs'; describe('ApproverReportsService', () => { let approverReportsService: ApproverReportsService; - const approverPlatformApiService = jasmine.createSpyObj('ApproverPlatformApiService', ['get']); + const approverPlatformApiService = jasmine.createSpyObj('ApproverPlatformApiService', ['post']); beforeEach(() => { TestBed.configureTestingModule({ @@ -19,4 +20,23 @@ describe('ApproverReportsService', () => { it('should be created', () => { expect(approverReportsService).toBeTruthy(); }); + + it('ejectExpenses(): should remove a transaction from a report', (done) => { + approverPlatformApiService.post.and.returnValue(of(null)); + + const reportID = 'rpvcIMRMyM3A'; + const txns = ['txTQVBx7W8EO']; + + const payload = { + data: { + id: reportID, + expense_ids: txns, + }, + reason: undefined, + }; + approverReportsService.ejectExpenses(reportID, txns[0]).subscribe(() => { + expect(approverPlatformApiService.post).toHaveBeenCalledOnceWith('/reports/eject_expenses', payload); + done(); + }); + }); }); diff --git a/src/app/core/services/platform/v1/spender/reports.service.spec.ts b/src/app/core/services/platform/v1/spender/reports.service.spec.ts index 8c080d94ef..1930184541 100644 --- a/src/app/core/services/platform/v1/spender/reports.service.spec.ts +++ b/src/app/core/services/platform/v1/spender/reports.service.spec.ts @@ -15,17 +15,21 @@ import { ReportsQueryParams } from 'src/app/core/models/platform/v1/reports-quer describe('SpenderReportsService', () => { let spenderReportsService: SpenderReportsService; - const spenderPlatformV1ApiServiceMock = jasmine.createSpyObj('SpenderPlatformV1ApiService', ['get']); + let spenderPlatformV1ApiService: jasmine.SpyObj; beforeEach(() => { + const spenderPlatformV1ApiServiceSpy = jasmine.createSpyObj('SpenderPlatformV1ApiService', ['get', 'post']); TestBed.configureTestingModule({ providers: [ SpenderReportsService, { provide: PAGINATION_SIZE, useValue: 2 }, - { provide: SpenderPlatformV1ApiService, useValue: spenderPlatformV1ApiServiceMock }, + { provide: SpenderPlatformV1ApiService, useValue: spenderPlatformV1ApiServiceSpy }, ], }); spenderReportsService = TestBed.inject(SpenderReportsService); + spenderPlatformV1ApiService = TestBed.inject( + SpenderPlatformV1ApiService + ) as jasmine.SpyObj; }); it('should be created', () => { @@ -111,10 +115,47 @@ describe('SpenderReportsService', () => { ...queryParams, }, }; - spenderPlatformV1ApiServiceMock.get.and.returnValue(of(allReportsPaginated1)); + spenderPlatformV1ApiService.get.and.returnValue(of(allReportsPaginated1)); spenderReportsService.getReportsByParams(queryParams).subscribe((response) => { expect(response).toEqual(allReportsPaginated1); - expect(spenderPlatformV1ApiServiceMock.get).toHaveBeenCalledOnceWith('/reports', expectedConfig); + expect(spenderPlatformV1ApiService.get).toHaveBeenCalledOnceWith('/reports', expectedConfig); + done(); + }); + }); + + it('addExpenses(): should add an expense to a report', (done) => { + spenderPlatformV1ApiService.post.and.returnValue(of(null)); + + const reportID = 'rpvcIMRMyM3A'; + const txns = ['txTQVBx7W8EO']; + + const payload = { + data: { + id: reportID, + expense_ids: txns, + }, + }; + spenderReportsService.addExpenses(reportID, txns).subscribe(() => { + expect(spenderPlatformV1ApiService.post).toHaveBeenCalledOnceWith('/reports/add_expenses', payload); + done(); + }); + }); + + it('ejectExpenses(): should remove an expense from a report', (done) => { + spenderPlatformV1ApiService.post.and.returnValue(of(null)); + + const reportID = 'rpvcIMRMyM3A'; + const txns = ['txTQVBx7W8EO']; + + const payload = { + data: { + id: reportID, + expense_ids: txns, + }, + reason: undefined, + }; + spenderReportsService.ejectExpenses(reportID, txns[0]).subscribe(() => { + expect(spenderPlatformV1ApiService.post).toHaveBeenCalledOnceWith('/reports/eject_expenses', payload); done(); }); }); diff --git a/src/app/core/services/platform/v1/spender/reports.service.ts b/src/app/core/services/platform/v1/spender/reports.service.ts index 21225ffcf5..de6b497e06 100644 --- a/src/app/core/services/platform/v1/spender/reports.service.ts +++ b/src/app/core/services/platform/v1/spender/reports.service.ts @@ -70,4 +70,14 @@ export class SpenderReportsService { }; return this.spenderPlatformV1ApiService.post('/reports/eject_expenses', payload); } + + addExpenses(rptId: string, txnIds: string[]): Observable { + const payload = { + data: { + id: rptId, + expense_ids: txnIds, + }, + }; + return this.spenderPlatformV1ApiService.post('/reports/add_expenses', payload); + } } diff --git a/src/app/core/services/report.service.spec.ts b/src/app/core/services/report.service.spec.ts index 75a9e34256..a6960cd6fc 100644 --- a/src/app/core/services/report.service.spec.ts +++ b/src/app/core/services/report.service.spec.ts @@ -516,20 +516,6 @@ describe('ReportService', () => { }); }); - it('addTransactions(): should add a transaction to a report', (done) => { - apiService.post.and.returnValue(of(null)); - spyOn(reportService, 'clearTransactionCache').and.returnValue(of(null)); - - const reportID = 'rpvcIMRMyM3A'; - const tnxs = ['txTQVBx7W8EO']; - - reportService.addTransactions(reportID, tnxs).subscribe(() => { - expect(apiService.post).toHaveBeenCalledOnceWith(`/reports/${reportID}/txns`, { ids: tnxs }); - expect(reportService.clearTransactionCache).toHaveBeenCalledTimes(1); - done(); - }); - }); - it('actions(): should get report actions', (done) => { apiService.get.and.returnValue(of(apiReportActions)); diff --git a/src/app/core/services/report.service.ts b/src/app/core/services/report.service.ts index fb81982558..3a598c402f 100644 --- a/src/app/core/services/report.service.ts +++ b/src/app/core/services/report.service.ts @@ -128,21 +128,6 @@ export class ReportService { ); } - @CacheBuster({ - cacheBusterNotifier: reportsCacheBuster$, - }) - addTransactions(rptId: string, txnIds: string[]): Observable { - return this.apiService - .post('/reports/' + rptId + '/txns', { - ids: txnIds, - }) - .pipe( - tap(() => { - this.clearTransactionCache(); - }) - ); - } - @CacheBuster({ cacheBusterNotifier: reportsCacheBuster$, }) diff --git a/src/app/core/services/transactions-outbox.service.spec.ts b/src/app/core/services/transactions-outbox.service.spec.ts index a8d8137491..407a863168 100644 --- a/src/app/core/services/transactions-outbox.service.spec.ts +++ b/src/app/core/services/transactions-outbox.service.spec.ts @@ -6,7 +6,6 @@ import { editUnflattenedTransaction, txnData2 } from '../mock-data/transaction.d import { DateService } from './date.service'; import { FileService } from './file.service'; import { OrgUserSettingsService } from './org-user-settings.service'; -import { ReportService } from './report.service'; import { StatusService } from './status.service'; import { StorageService } from './storage.service'; import { TrackingService } from './tracking.service'; @@ -19,6 +18,7 @@ import { cloneDeep } from 'lodash'; import { of } from 'rxjs'; import { parsedReceiptData1, parsedReceiptData2 } from '../mock-data/parsed-receipt.data'; import { fileData1 } from '../mock-data/file.data'; +import { SpenderReportsService } from './platform/v1/spender/reports.service'; describe('TransactionsOutboxService', () => { const rootUrl = 'https://staging.fyle.tech'; @@ -29,7 +29,7 @@ describe('TransactionsOutboxService', () => { let expensesService: jasmine.SpyObj; let fileService: jasmine.SpyObj; let statusService: jasmine.SpyObj; - let reportService: jasmine.SpyObj; + let spenderReportsService: jasmine.SpyObj; let trackingService: jasmine.SpyObj; let orgUserSettingsService: jasmine.SpyObj; const singleCaptureCountInSession = 0; @@ -43,7 +43,7 @@ describe('TransactionsOutboxService', () => { const expensesServiceSpy = jasmine.createSpyObj('ExpensesService', ['getExpensesById']); const fileServiceSpy = jasmine.createSpyObj('FileService', ['post', 'uploadUrl', 'uploadComplete']); const statusServiceSpy = jasmine.createSpyObj('StatusService', ['post']); - const reportServiceSpy = jasmine.createSpyObj('ReportService', ['post']); + const spenderReportsServiceSpy = jasmine.createSpyObj('SpenderReportsService', ['post']); const trackingServiceSpy = jasmine.createSpyObj('TrackingService', ['post']); const orgUserSettingsServiceSpy = jasmine.createSpyObj('OrgUserSettingsService', ['post']); @@ -57,7 +57,7 @@ describe('TransactionsOutboxService', () => { { provide: ExpensesService, useValue: expensesServiceSpy }, { provide: FileService, useValue: fileServiceSpy }, { provide: StatusService, useValue: statusServiceSpy }, - { provide: ReportService, useValue: reportServiceSpy }, + { provide: SpenderReportsService, useValue: spenderReportsServiceSpy }, { provide: TrackingService, useValue: trackingServiceSpy }, { provide: OrgUserSettingsService, useValue: orgUserSettingsServiceSpy }, ], @@ -69,7 +69,7 @@ describe('TransactionsOutboxService', () => { expensesService = TestBed.inject(ExpensesService) as jasmine.SpyObj; fileService = TestBed.inject(FileService) as jasmine.SpyObj; statusService = TestBed.inject(StatusService) as jasmine.SpyObj; - reportService = TestBed.inject(ReportService) as jasmine.SpyObj; + spenderReportsService = TestBed.inject(SpenderReportsService) as jasmine.SpyObj; trackingService = TestBed.inject(TrackingService) as jasmine.SpyObj; orgUserSettingsService = TestBed.inject(OrgUserSettingsService) as jasmine.SpyObj; httpMock = TestBed.inject(HttpTestingController); diff --git a/src/app/core/services/transactions-outbox.service.ts b/src/app/core/services/transactions-outbox.service.ts index 6d3d024638..dc2a638038 100644 --- a/src/app/core/services/transactions-outbox.service.ts +++ b/src/app/core/services/transactions-outbox.service.ts @@ -9,7 +9,6 @@ import { TransactionService } from './transaction.service'; import { FileService } from './file.service'; import { StatusService } from './status.service'; import { cloneDeep, indexOf } from 'lodash'; -import { ReportService } from './report.service'; import { ParsedReceipt } from '../models/parsed_receipt.model'; import { TrackingService } from './tracking.service'; import { Expense } from '../models/expense.model'; @@ -19,6 +18,7 @@ import { Transaction } from '../models/v1/transaction.model'; import { FileObject } from '../models/file-obj.model'; import { OutboxQueue } from '../models/outbox-queue.model'; import { ExpensesService } from './platform/v1/spender/expenses.service'; +import { SpenderReportsService } from './platform/v1/spender/reports.service'; @Injectable({ providedIn: 'root', @@ -46,7 +46,7 @@ export class TransactionsOutboxService { private fileService: FileService, private statusService: StatusService, private httpClient: HttpClient, - private reportService: ReportService, + private spenderReportsService: SpenderReportsService, private trackingService: TrackingService, private currencyService: CurrencyService, private orgUserSettingsService: OrgUserSettingsService, @@ -400,8 +400,8 @@ export class TransactionsOutboxService { that.removeEntry(entry); if (reportId) { const txnIds = [resp.id]; - that.reportService - .addTransactions(reportId, txnIds) + that.spenderReportsService + .addExpenses(reportId, txnIds) .toPromise() .then(() => { this.trackingService.addToExistingReportAddEditExpense(); diff --git a/src/app/fyle/add-edit-expense/add-edit-expense-4.spec.ts b/src/app/fyle/add-edit-expense/add-edit-expense-4.spec.ts index 31fdd5161c..15f8396164 100644 --- a/src/app/fyle/add-edit-expense/add-edit-expense-4.spec.ts +++ b/src/app/fyle/add-edit-expense/add-edit-expense-4.spec.ts @@ -930,7 +930,7 @@ export function TestCases4(getTestBed) { expensesService.getExpenseById.and.returnValue(of(platformExpenseData)); transactionService.transformExpense.and.returnValue(transformedExpenseData); component.fg.controls.report.setValue(expectedReportsPaginated[0]); - reportService.addTransactions.and.returnValue(of(undefined)); + spenderReportsService.addExpenses.and.returnValue(of(undefined)); fixture.detectChanges(); component.editExpense('SAVE_AND_NEW_EXPENSE').subscribe(() => { @@ -947,7 +947,7 @@ export function TestCases4(getTestBed) { expect(transactionService.upsert).toHaveBeenCalledOnceWith(transformedExpenseData.tx); expect(expensesService.getExpenseById).toHaveBeenCalledOnceWith('txvslh8aQMbu'); expect(transactionService.transformExpense).toHaveBeenCalledOnceWith(platformExpenseData); - expect(reportService.addTransactions).toHaveBeenCalledOnceWith('rprAfNrce73O', ['txvslh8aQMbu']); + expect(spenderReportsService.addExpenses).toHaveBeenCalledOnceWith('rprAfNrce73O', ['txvslh8aQMbu']); done(); }); }); @@ -963,7 +963,7 @@ export function TestCases4(getTestBed) { policyService.getCriticalPolicyRules.and.returnValue([]); policyService.getPolicyRules.and.returnValue([]); spenderReportsService.ejectExpenses.and.returnValue(of(undefined)); - reportService.addTransactions.and.returnValue(of(undefined)); + spenderReportsService.addExpenses.and.returnValue(of(undefined)); authService.getEou.and.resolveTo(apiEouRes); transactionService.upsert.and.returnValue(of(transformedExpenseDataWithReportId.tx)); expensesService.getExpenseById.and.returnValue(of(platformExpenseDataWithReportId)); @@ -985,7 +985,7 @@ export function TestCases4(getTestBed) { expect(transactionService.upsert).toHaveBeenCalledOnceWith(transformedExpenseDataWithReportId.tx); expect(expensesService.getExpenseById).toHaveBeenCalledOnceWith('txD5hIQgLuR5'); expect(transactionService.transformExpense).toHaveBeenCalledOnceWith(platformExpenseDataWithReportId); - expect(reportService.addTransactions).toHaveBeenCalledOnceWith('rprAfNrce73O', ['txD5hIQgLuR5']); + expect(spenderReportsService.addExpenses).toHaveBeenCalledOnceWith('rprAfNrce73O', ['txD5hIQgLuR5']); expect(spenderReportsService.ejectExpenses).toHaveBeenCalledOnceWith('rpbNc3kn5baq', 'txD5hIQgLuR5'); done(); }); diff --git a/src/app/fyle/add-edit-expense/add-edit-expense.page.ts b/src/app/fyle/add-edit-expense/add-edit-expense.page.ts index 96ba3d2694..a000f64168 100644 --- a/src/app/fyle/add-edit-expense/add-edit-expense.page.ts +++ b/src/app/fyle/add-edit-expense/add-edit-expense.page.ts @@ -3893,7 +3893,7 @@ export class AddEditExpensePage implements OnInit { const criticalPolicyViolated = this.getIsPolicyExpense(etxn as unknown as Expense); if (!criticalPolicyViolated) { if (!txnCopy.tx.report_id && selectedReportId) { - return this.reportService.addTransactions(selectedReportId, [tx.id]).pipe( + return this.platformReportService.addExpenses(selectedReportId, [tx.id]).pipe( tap(() => this.trackingService.addToExistingReportAddEditExpense()), map(() => tx) ); @@ -3901,7 +3901,7 @@ export class AddEditExpensePage implements OnInit { if (txnCopy.tx.report_id && selectedReportId && txnCopy.tx.report_id !== selectedReportId) { return this.platformReportService.ejectExpenses(txnCopy.tx.report_id, tx.id).pipe( - switchMap(() => this.reportService.addTransactions(selectedReportId, [tx.id])), + switchMap(() => this.platformReportService.addExpenses(selectedReportId, [tx.id])), tap(() => this.trackingService.addToExistingReportAddEditExpense()), map(() => tx) ); diff --git a/src/app/fyle/add-edit-expense/add-edit-expense.setup.spec.ts b/src/app/fyle/add-edit-expense/add-edit-expense.setup.spec.ts index 3a56d228d2..7fb0bd38e6 100644 --- a/src/app/fyle/add-edit-expense/add-edit-expense.setup.spec.ts +++ b/src/app/fyle/add-edit-expense/add-edit-expense.setup.spec.ts @@ -94,7 +94,11 @@ describe('AddEditExpensePage', () => { 'getFilteredPendingReports', 'addTransactions', ]); - const reportsServiceSpy = jasmine.createSpyObj('SpenderReportsService', ['getAllReportsByParams', 'ejectExpenses']); + const reportsServiceSpy = jasmine.createSpyObj('SpenderReportsService', [ + 'getAllReportsByParams', + 'ejectExpenses', + 'addExpenses', + ]); const customInputsServiceSpy = jasmine.createSpyObj('CustomInputsService', ['getAll', 'filterByCategory']); const customFieldsServiceSpy = jasmine.createSpyObj('CustomFieldsService', ['standardizeCustomFields']); const transactionServiceSpy = jasmine.createSpyObj('TransactionService', [ 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 8170a04795..dc6f3634d0 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 @@ -598,7 +598,7 @@ export function TestCases3(getTestBed) { spyOn(component, 'getEditCalculatedDistance').and.returnValue(of(12)); spyOn(component, 'trackEditExpense'); authService.getEou.and.resolveTo(apiEouRes); - reportService.addTransactions.and.returnValue(of(null)); + spenderReportsService.addExpenses.and.returnValue(of(null)); spenderReportsService.ejectExpenses.and.returnValue(of(null)); }); @@ -638,7 +638,7 @@ export function TestCases3(getTestBed) { expect(transactionService.transformExpense).toHaveBeenCalledOnceWith(platformExpenseDataWithSubCategory); expect(component.getFormValues).toHaveBeenCalledTimes(1); expect(component.getIsPolicyExpense).toHaveBeenCalledTimes(1); - expect(reportService.addTransactions).toHaveBeenCalledOnceWith(expectedReportsPaginated[0].id, [ + expect(spenderReportsService.addExpenses).toHaveBeenCalledOnceWith(expectedReportsPaginated[0].id, [ transformedExpenseDataWithSubCategory.tx.id, ]); expect(trackingService.addToExistingReportAddEditExpense).toHaveBeenCalledTimes(1); @@ -686,7 +686,7 @@ export function TestCases3(getTestBed) { transformedExpenseDataWithReportId.tx.report_id, transformedExpenseDataWithReportId.tx.id ); - expect(reportService.addTransactions).toHaveBeenCalledOnceWith('rprAfNrce73O', ['txD5hIQgLuR5']); + expect(spenderReportsService.addExpenses).toHaveBeenCalledOnceWith('rprAfNrce73O', ['txD5hIQgLuR5']); expect(trackingService.addToExistingReportAddEditExpense).toHaveBeenCalledTimes(1); done(); }); @@ -960,7 +960,7 @@ export function TestCases3(getTestBed) { expect(transactionService.transformExpense).toHaveBeenCalledOnceWith(platformExpenseDataWithReportId); expect(component.getFormValues).toHaveBeenCalledTimes(1); expect(component.getIsPolicyExpense).toHaveBeenCalledTimes(1); - expect(reportService.addTransactions).toHaveBeenCalledOnceWith(expectedReportsPaginated[0].id, [ + expect(spenderReportsService.addExpenses).toHaveBeenCalledOnceWith(expectedReportsPaginated[0].id, [ 'txD5hIQgLuR5', ]); expect(trackingService.addToExistingReportAddEditExpense).toHaveBeenCalledTimes(1); diff --git a/src/app/fyle/add-edit-mileage/add-edit-mileage.page.setup.spec.ts b/src/app/fyle/add-edit-mileage/add-edit-mileage.page.setup.spec.ts index 3757b8fa81..69240adf40 100644 --- a/src/app/fyle/add-edit-mileage/add-edit-mileage.page.setup.spec.ts +++ b/src/app/fyle/add-edit-mileage/add-edit-mileage.page.setup.spec.ts @@ -102,6 +102,7 @@ describe('AddEditMileagePage', () => { const platformSpenderReportsServiceSpy = jasmine.createSpyObj('SpenderReportsService', [ 'getAllReportsByParams', 'ejectExpenses', + 'addExpenses', ]); const customInputsServiceSpy = jasmine.createSpyObj('CustomInputsService', ['getAll', 'filterByCategory']); const customFieldsServiceSpy = jasmine.createSpyObj('CustomFieldsService', ['standardizeCustomFields']); diff --git a/src/app/fyle/add-edit-mileage/add-edit-mileage.page.ts b/src/app/fyle/add-edit-mileage/add-edit-mileage.page.ts index e57856998c..831dadb3cb 100644 --- a/src/app/fyle/add-edit-mileage/add-edit-mileage.page.ts +++ b/src/app/fyle/add-edit-mileage/add-edit-mileage.page.ts @@ -2571,7 +2571,7 @@ export class AddEditMileagePage implements OnInit { const criticalPolicyViolated = this.getIsPolicyExpense(tx as unknown as Expense); if (!criticalPolicyViolated) { if (!txnCopy.tx.report_id && selectedReportId) { - return this.reportService.addTransactions(selectedReportId, [tx.id]).pipe( + return this.platformReportService.addExpenses(selectedReportId, [tx.id]).pipe( tap(() => this.trackingService.addToExistingReportAddEditExpense()), map(() => tx) ); @@ -2579,7 +2579,7 @@ export class AddEditMileagePage implements OnInit { if (txnCopy.tx.report_id && selectedReportId && txnCopy.tx.report_id !== selectedReportId) { return this.platformReportService.ejectExpenses(txnCopy.tx.report_id, tx.id).pipe( - switchMap(() => this.reportService.addTransactions(selectedReportId, [tx.id])), + switchMap(() => this.platformReportService.addExpenses(selectedReportId, [tx.id])), tap(() => this.trackingService.addToExistingReportAddEditExpense()), map(() => tx) ); diff --git a/src/app/fyle/add-edit-per-diem/add-edit-per-diem-4.page.spec.ts b/src/app/fyle/add-edit-per-diem/add-edit-per-diem-4.page.spec.ts index cc62b1090a..b879abc564 100644 --- a/src/app/fyle/add-edit-per-diem/add-edit-per-diem-4.page.spec.ts +++ b/src/app/fyle/add-edit-per-diem/add-edit-per-diem-4.page.spec.ts @@ -308,7 +308,7 @@ export function TestCases4(getTestBed) { transactionService.upsert.and.returnValue(of(transformedExpenseData.tx)); expensesService.getExpenseById.and.returnValue(of(platformExpenseData)); transactionService.transformExpense.and.returnValue(transformedExpenseData); - reportService.addTransactions.and.returnValue(of(undefined)); + spenderReportsService.addExpenses.and.returnValue(of(undefined)); spenderReportsService.ejectExpenses.and.returnValue(of(undefined)); transactionService.review.and.returnValue(of(null)); statusService.findLatestComment.and.returnValue(of('comment1')); @@ -352,7 +352,7 @@ export function TestCases4(getTestBed) { expect(transactionService.upsert).toHaveBeenCalledOnceWith(transformedExpenseData.tx); expect(expensesService.getExpenseById).toHaveBeenCalledOnceWith(platformExpenseData.id); expect(transactionService.transformExpense).toHaveBeenCalledOnceWith(platformExpenseData); - expect(reportService.addTransactions).toHaveBeenCalledOnceWith('rprAfNrce73O', ['txvslh8aQMbu']); + expect(spenderReportsService.addExpenses).toHaveBeenCalledOnceWith('rprAfNrce73O', ['txvslh8aQMbu']); expect(spenderReportsService.ejectExpenses).not.toHaveBeenCalled(); expect(trackingService.addToExistingReportAddEditExpense).toHaveBeenCalledTimes(1); expect(trackingService.removeFromExistingReportEditExpense).not.toHaveBeenCalled(); @@ -397,7 +397,7 @@ export function TestCases4(getTestBed) { expect(transactionService.upsert).toHaveBeenCalledOnceWith(transformedExpenseData.tx); expect(expensesService.getExpenseById).toHaveBeenCalledOnceWith(platformExpenseData.id); expect(transactionService.transformExpense).toHaveBeenCalledOnceWith(platformExpenseData); - expect(reportService.addTransactions).toHaveBeenCalledOnceWith('rprAfNrce73O', ['txvslh8aQMbu']); + expect(spenderReportsService.addExpenses).toHaveBeenCalledOnceWith('rprAfNrce73O', ['txvslh8aQMbu']); expect(spenderReportsService.ejectExpenses).toHaveBeenCalledOnceWith('rpbNc3kn5baq', 'txvslh8aQMbu'); expect(trackingService.addToExistingReportAddEditExpense).toHaveBeenCalledTimes(1); expect(trackingService.removeFromExistingReportEditExpense).not.toHaveBeenCalled(); @@ -443,7 +443,7 @@ export function TestCases4(getTestBed) { expect(transactionService.upsert).toHaveBeenCalledOnceWith(transformedExpenseData.tx); expect(expensesService.getExpenseById).toHaveBeenCalledOnceWith(platformExpenseData.id); expect(transactionService.transformExpense).toHaveBeenCalledOnceWith(platformExpenseData); - expect(reportService.addTransactions).not.toHaveBeenCalled(); + expect(spenderReportsService.addExpenses).not.toHaveBeenCalled(); expect(spenderReportsService.ejectExpenses).toHaveBeenCalledOnceWith('rp8eUleN29dc', 'txvslh8aQMbu'); expect(trackingService.addToExistingReportAddEditExpense).not.toHaveBeenCalled(); expect(trackingService.removeFromExistingReportEditExpense).toHaveBeenCalledTimes(1); @@ -488,7 +488,7 @@ export function TestCases4(getTestBed) { expect(transactionService.upsert).toHaveBeenCalledOnceWith(transformedExpenseData.tx); expect(expensesService.getExpenseById).toHaveBeenCalledOnceWith(platformExpenseData.id); expect(transactionService.transformExpense).toHaveBeenCalledOnceWith(platformExpenseData); - expect(reportService.addTransactions).toHaveBeenCalledOnceWith('rprAfNrce73O', ['txvslh8aQMbu']); + expect(spenderReportsService.addExpenses).toHaveBeenCalledOnceWith('rprAfNrce73O', ['txvslh8aQMbu']); expect(spenderReportsService.ejectExpenses).not.toHaveBeenCalled(); expect(trackingService.addToExistingReportAddEditExpense).toHaveBeenCalledTimes(1); expect(trackingService.removeFromExistingReportEditExpense).not.toHaveBeenCalled(); @@ -547,7 +547,7 @@ export function TestCases4(getTestBed) { expect(transactionService.upsert).toHaveBeenCalledOnceWith(transformedExpenseData.tx); expect(expensesService.getExpenseById).toHaveBeenCalledOnceWith(platformExpenseData.id); expect(transactionService.transformExpense).toHaveBeenCalledOnceWith(platformExpenseData); - expect(reportService.addTransactions).toHaveBeenCalledOnceWith('rprAfNrce73O', ['txvslh8aQMbu']); + expect(spenderReportsService.addExpenses).toHaveBeenCalledOnceWith('rprAfNrce73O', ['txvslh8aQMbu']); expect(spenderReportsService.ejectExpenses).not.toHaveBeenCalled(); expect(trackingService.addToExistingReportAddEditExpense).toHaveBeenCalledTimes(1); expect(trackingService.removeFromExistingReportEditExpense).not.toHaveBeenCalled(); @@ -604,7 +604,7 @@ export function TestCases4(getTestBed) { expect(transactionService.upsert).toHaveBeenCalledOnceWith(transformedExpenseData.tx); expect(expensesService.getExpenseById).toHaveBeenCalledOnceWith(platformExpenseData.id); expect(transactionService.transformExpense).toHaveBeenCalledOnceWith(platformExpenseData); - expect(reportService.addTransactions).toHaveBeenCalledOnceWith('rprAfNrce73O', ['txvslh8aQMbu']); + expect(spenderReportsService.addExpenses).toHaveBeenCalledOnceWith('rprAfNrce73O', ['txvslh8aQMbu']); expect(spenderReportsService.ejectExpenses).not.toHaveBeenCalled(); expect(trackingService.addToExistingReportAddEditExpense).toHaveBeenCalledTimes(1); expect(trackingService.removeFromExistingReportEditExpense).not.toHaveBeenCalled(); @@ -660,7 +660,7 @@ export function TestCases4(getTestBed) { expect(transactionService.upsert).toHaveBeenCalledOnceWith(transformedExpenseData.tx); expect(expensesService.getExpenseById).toHaveBeenCalledOnceWith(platformExpenseData.id); expect(transactionService.transformExpense).toHaveBeenCalledOnceWith(platformExpenseData); - expect(reportService.addTransactions).toHaveBeenCalledOnceWith('rprAfNrce73O', ['txvslh8aQMbu']); + expect(spenderReportsService.addExpenses).toHaveBeenCalledOnceWith('rprAfNrce73O', ['txvslh8aQMbu']); expect(spenderReportsService.ejectExpenses).not.toHaveBeenCalled(); expect(trackingService.addToExistingReportAddEditExpense).toHaveBeenCalledTimes(1); expect(trackingService.removeFromExistingReportEditExpense).not.toHaveBeenCalled(); @@ -715,7 +715,7 @@ export function TestCases4(getTestBed) { expect(transactionService.upsert).toHaveBeenCalledOnceWith(mockTxnData.tx); expect(expensesService.getExpenseById).toHaveBeenCalledOnceWith(platformExpenseData.id); expect(transactionService.transformExpense).toHaveBeenCalledOnceWith(platformExpenseData); - expect(reportService.addTransactions).not.toHaveBeenCalled(); + expect(spenderReportsService.addExpenses).not.toHaveBeenCalled(); expect(spenderReportsService.ejectExpenses).not.toHaveBeenCalled(); expect(trackingService.addToExistingReportAddEditExpense).not.toHaveBeenCalled(); expect(trackingService.removeFromExistingReportEditExpense).not.toHaveBeenCalled(); @@ -766,7 +766,7 @@ export function TestCases4(getTestBed) { expect(transactionService.upsert).toHaveBeenCalledOnceWith(transformedExpenseData.tx); expect(expensesService.getExpenseById).toHaveBeenCalledOnceWith(platformExpenseData.id); expect(transactionService.transformExpense).toHaveBeenCalledOnceWith(platformExpenseData); - expect(reportService.addTransactions).toHaveBeenCalledOnceWith('rprAfNrce73O', ['txvslh8aQMbu']); + expect(spenderReportsService.addExpenses).toHaveBeenCalledOnceWith('rprAfNrce73O', ['txvslh8aQMbu']); expect(spenderReportsService.ejectExpenses).not.toHaveBeenCalled(); expect(trackingService.addToExistingReportAddEditExpense).toHaveBeenCalledTimes(1); expect(trackingService.removeFromExistingReportEditExpense).not.toHaveBeenCalled(); @@ -811,7 +811,7 @@ export function TestCases4(getTestBed) { expect(transactionService.upsert).toHaveBeenCalledOnceWith(transformedExpenseData.tx); expect(expensesService.getExpenseById).toHaveBeenCalledOnceWith(platformExpenseData.id); expect(transactionService.transformExpense).toHaveBeenCalledOnceWith(platformExpenseData); - expect(reportService.addTransactions).toHaveBeenCalledOnceWith('rprAfNrce73O', ['txvslh8aQMbu']); + expect(spenderReportsService.addExpenses).toHaveBeenCalledOnceWith('rprAfNrce73O', ['txvslh8aQMbu']); expect(spenderReportsService.ejectExpenses).not.toHaveBeenCalled(); expect(trackingService.addToExistingReportAddEditExpense).toHaveBeenCalledTimes(1); expect(trackingService.removeFromExistingReportEditExpense).not.toHaveBeenCalled(); diff --git a/src/app/fyle/add-edit-per-diem/add-edit-per-diem.page.setup.spec.ts b/src/app/fyle/add-edit-per-diem/add-edit-per-diem.page.setup.spec.ts index 47f56d983c..f6a9112bfc 100644 --- a/src/app/fyle/add-edit-per-diem/add-edit-per-diem.page.setup.spec.ts +++ b/src/app/fyle/add-edit-per-diem/add-edit-per-diem.page.setup.spec.ts @@ -67,6 +67,7 @@ describe('AddEditPerDiemPage', () => { const platformSpenderReportsServiceSpy = jasmine.createSpyObj('SpenderReportsService', [ 'getAllReportsByParams', 'ejectExpenses', + 'addExpenses', ]); const projectServiceSpy = jasmine.createSpyObj('ProjectService', [ 'getAllowedOrgCategoryIds', 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 fadbc5609f..2285a384b4 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 @@ -2054,7 +2054,7 @@ export class AddEditPerDiemPage implements OnInit { const criticalPolicyViolated = isNumber(etxn.tx.policy_amount) && etxn.tx.policy_amount < 0.0001; if (!criticalPolicyViolated) { if (!txnCopy.tx.report_id && selectedReportId) { - return this.reportService.addTransactions(selectedReportId, [tx.id]).pipe( + return this.platformReportService.addExpenses(selectedReportId, [tx.id]).pipe( tap(() => this.trackingService.addToExistingReportAddEditExpense()), map(() => tx) ); @@ -2062,7 +2062,7 @@ export class AddEditPerDiemPage implements OnInit { if (txnCopy.tx.report_id && selectedReportId && selectedReportId !== txnCopy.tx.report_id) { return this.platformReportService.ejectExpenses(txnCopy.tx.report_id, tx.id).pipe( - switchMap(() => this.reportService.addTransactions(selectedReportId, [tx.id])), + switchMap(() => this.platformReportService.addExpenses(selectedReportId, [tx.id])), tap(() => this.trackingService.addToExistingReportAddEditExpense()), map(() => tx) ); diff --git a/src/app/fyle/dashboard/tasks/tasks-3.component.spec.ts b/src/app/fyle/dashboard/tasks/tasks-3.component.spec.ts index 8db5cfcfbd..6696f81a56 100644 --- a/src/app/fyle/dashboard/tasks/tasks-3.component.spec.ts +++ b/src/app/fyle/dashboard/tasks/tasks-3.component.spec.ts @@ -26,6 +26,7 @@ import { unreportedExpensesQueryParams } from 'src/app/core/mock-data/platform/v import { OrgSettingsService } from 'src/app/core/services/org-settings.service'; import { orgSettingsPendingRestrictions } from 'src/app/core/mock-data/org-settings.data'; import { commuteDetailsResponseData } from 'src/app/core/mock-data/commute-details-response.data'; +import { SpenderReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; export function TestCases3(getTestBed) { return describe('test case set 3', () => { @@ -46,6 +47,8 @@ export function TestCases3(getTestBed) { let networkService: jasmine.SpyObj; let expensesService: jasmine.SpyObj; let orgSettingsService: jasmine.SpyObj; + let spenderReportsService: jasmine.SpyObj; + beforeEach(waitForAsync(() => { const TestBed = getTestBed(); fixture = TestBed.createComponent(TasksComponent); @@ -66,6 +69,7 @@ export function TestCases3(getTestBed) { activatedRoute = TestBed.inject(ActivatedRoute) as jasmine.SpyObj; networkService = TestBed.inject(NetworkService) as jasmine.SpyObj; expensesService = TestBed.inject(ExpensesService) as jasmine.SpyObj; + spenderReportsService = TestBed.inject(SpenderReportsService) as jasmine.SpyObj; orgSettingsService.get.and.returnValue(of(orgSettingsPendingRestrictions)); })); @@ -75,11 +79,11 @@ export function TestCases3(getTestBed) { expect(router.navigate).toHaveBeenCalledWith(['/', 'enterprise', 'potential-duplicates']); }); - it('addTransactionsToReport(): should show loader, call reportService.addTransactions and hide the loader', (done) => { + it('addTransactionsToReport(): should show loader, call spenderReportsService.addExpenses and hide the loader', (done) => { loaderService.showLoader.and.resolveTo(); loaderService.hideLoader.and.resolveTo(true); - reportService.addTransactions.and.returnValue(of(undefined)); + spenderReportsService.addExpenses.and.returnValue(of(undefined)); component .addTransactionsToReport(apiExtendedReportRes[0], ['tx5fBcPBAxLv']) .pipe( @@ -89,7 +93,7 @@ export function TestCases3(getTestBed) { ) .subscribe((res) => { expect(loaderService.showLoader).toHaveBeenCalledTimes(1); - expect(reportService.addTransactions).toHaveBeenCalledOnceWith(apiExtendedReportRes[0].rp_id, [ + expect(spenderReportsService.addExpenses).toHaveBeenCalledOnceWith(apiExtendedReportRes[0].rp_id, [ 'tx5fBcPBAxLv', ]); expect(res).toEqual(apiExtendedReportRes[0]); diff --git a/src/app/fyle/dashboard/tasks/tasks.component.setup.spec.ts b/src/app/fyle/dashboard/tasks/tasks.component.setup.spec.ts index eb879e0100..a62f8af500 100644 --- a/src/app/fyle/dashboard/tasks/tasks.component.setup.spec.ts +++ b/src/app/fyle/dashboard/tasks/tasks.component.setup.spec.ts @@ -21,6 +21,7 @@ import { TestCases2 } from './tasks-2.component.spec'; import { TestCases3 } from './tasks-3.component.spec'; import { ExpensesService } from 'src/app/core/services/platform/v1/spender/expenses.service'; import { OrgSettingsService } from 'src/app/core/services/org-settings.service'; +import { SpenderReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; describe('TasksComponent', () => { const getTestBed = () => { @@ -62,6 +63,7 @@ describe('TasksComponent', () => { ]); const loaderServiceSpy = jasmine.createSpyObj('LoaderService', ['showLoader', 'hideLoader']); const matBottomSheetSpy = jasmine.createSpyObj('MatBottomSheet', ['open']); + const spenderReportsServiceSpy = jasmine.createSpyObj('SpenderReportsService', ['addExpenses']); const matSnackBarSpy = jasmine.createSpyObj('MatSnackBar', ['openFromComponent']); const snackbarPropertiesSpy = jasmine.createSpyObj('SnackbarPropertiesService', ['setSnackbarProperties']); const authServiceSpy = jasmine.createSpyObj('AuthService', ['getEou']); @@ -95,6 +97,7 @@ describe('TasksComponent', () => { { provide: NetworkService, useValue: networkServiceSpy }, { provide: OrgSettingsService, useValue: orgSettingsServiceSpy }, { provide: ExpensesService, useValue: expensesServiceSpy }, + { provide: SpenderReportsService, useValue: spenderReportsServiceSpy }, ], schemas: [NO_ERRORS_SCHEMA], }).compileComponents(); diff --git a/src/app/fyle/dashboard/tasks/tasks.component.ts b/src/app/fyle/dashboard/tasks/tasks.component.ts index 50db943617..a280d91753 100644 --- a/src/app/fyle/dashboard/tasks/tasks.component.ts +++ b/src/app/fyle/dashboard/tasks/tasks.component.ts @@ -31,6 +31,7 @@ import { FySelectCommuteDetailsComponent } from 'src/app/shared/components/fy-se import { OverlayResponse } from 'src/app/core/models/overlay-response.modal'; import { OrgSettingsService } from 'src/app/core/services/org-settings.service'; import { CommuteDetailsResponse } from 'src/app/core/models/platform/commute-details-response.model'; +import { SpenderReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; @Component({ selector: 'app-tasks', @@ -75,7 +76,8 @@ export class TasksComponent implements OnInit { private router: Router, private activatedRoute: ActivatedRoute, private networkService: NetworkService, - private orgSettingsService: OrgSettingsService + private orgSettingsService: OrgSettingsService, + private spenderReportsService: SpenderReportsService ) {} ngOnInit(): void { @@ -566,7 +568,7 @@ export class TasksComponent implements OnInit { addTransactionsToReport(report: ExtendedReport, selectedExpensesId: string[]): Observable { return from(this.loaderService.showLoader('Adding transaction to report')).pipe( - switchMap(() => this.reportService.addTransactions(report.rp_id, selectedExpensesId).pipe(map(() => report))), + switchMap(() => this.spenderReportsService.addExpenses(report.rp_id, selectedExpensesId).pipe(map(() => report))), finalize(() => this.loaderService.hideLoader()) ); } diff --git a/src/app/fyle/my-create-report/my-create-report.page.spec.ts b/src/app/fyle/my-create-report/my-create-report.page.spec.ts index 8ed8ba7731..90d3999c9b 100644 --- a/src/app/fyle/my-create-report/my-create-report.page.spec.ts +++ b/src/app/fyle/my-create-report/my-create-report.page.spec.ts @@ -30,6 +30,7 @@ import { MyCreateReportPage } from './my-create-report.page'; import { ExpensesService } from 'src/app/core/services/platform/v1/spender/expenses.service'; import { OrgSettingsService } from 'src/app/core/services/org-settings.service'; import { orgSettingsPendingRestrictions } from 'src/app/core/mock-data/org-settings.data'; +import { SpenderReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; describe('MyCreateReportPage', () => { let component: MyCreateReportPage; @@ -45,6 +46,7 @@ describe('MyCreateReportPage', () => { let refinerService: jasmine.SpyObj; let expensesService: jasmine.SpyObj; let orgSettingsService: jasmine.SpyObj; + let spenderReportsService: jasmine.SpyObj; beforeEach(waitForAsync(() => { const orgSettingsServiceSpy = jasmine.createSpyObj('OrgSettingsService', ['get']); @@ -63,6 +65,7 @@ describe('MyCreateReportPage', () => { const storageServiceSpy = jasmine.createSpyObj('StorageService', ['get', 'set']); const refinerServiceSpy = jasmine.createSpyObj('RefinerService', ['startSurvey']); const expensesServiceSpy = jasmine.createSpyObj('ExpensesService', ['getAllExpenses']); + const spenderReportsServiceSpy = jasmine.createSpyObj('SpenderReportsService', ['addExpenses']); TestBed.configureTestingModule({ declarations: [MyCreateReportPage, HumanizeCurrencyPipe], @@ -120,6 +123,10 @@ describe('MyCreateReportPage', () => { provide: ExpensesService, useValue: expensesServiceSpy, }, + { + provide: SpenderReportsService, + useValue: spenderReportsServiceSpy, + }, ], schemas: [CUSTOM_ELEMENTS_SCHEMA], }).compileComponents(); @@ -136,6 +143,7 @@ describe('MyCreateReportPage', () => { storageService = TestBed.inject(StorageService) as jasmine.SpyObj; refinerService = TestBed.inject(RefinerService) as jasmine.SpyObj; expensesService = TestBed.inject(ExpensesService) as jasmine.SpyObj; + spenderReportsService = TestBed.inject(SpenderReportsService) as jasmine.SpyObj; currencyService.getHomeCurrency.and.returnValue(of('USD')); orgSettingsService = TestBed.inject(OrgSettingsService) as jasmine.SpyObj; @@ -212,7 +220,7 @@ describe('MyCreateReportPage', () => { }); it('should create a draft report and add transactions to it, if there are any selected expenses', () => { - reportService.addTransactions.and.returnValue(of(null)); + spenderReportsService.addExpenses.and.returnValue(of(null)); component.readyToReportExpenses = cloneDeep(readyToReportExpensesData); component.selectedElements = cloneDeep([readyToReportExpensesData[0]]); fixture.detectChanges(); @@ -228,7 +236,7 @@ describe('MyCreateReportPage', () => { Expense_Count: 1, Report_Value: component.selectedTotalAmount, }); - expect(reportService.addTransactions).toHaveBeenCalledOnceWith(reportUnflattenedData.id, [ + expect(spenderReportsService.addExpenses).toHaveBeenCalledOnceWith(reportUnflattenedData.id, [ readyToReportExpensesData[0].id, ]); expect(router.navigate).toHaveBeenCalledOnceWith(['/', 'enterprise', 'my_reports']); diff --git a/src/app/fyle/my-create-report/my-create-report.page.ts b/src/app/fyle/my-create-report/my-create-report.page.ts index 7b462b2e4c..5da50dbd11 100644 --- a/src/app/fyle/my-create-report/my-create-report.page.ts +++ b/src/app/fyle/my-create-report/my-create-report.page.ts @@ -15,6 +15,7 @@ import { TrackingService } from '../../core/services/tracking.service'; import { Expense as PlatformExpense } from '../../core/models/platform/v1/expense.model'; import { ExpensesService } from 'src/app/core/services/platform/v1/spender/expenses.service'; import { OrgSettingsService } from 'src/app/core/services/org-settings.service'; +import { SpenderReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; @Component({ selector: 'app-my-create-report', templateUrl: './my-create-report.page.html', @@ -60,7 +61,8 @@ export class MyCreateReportPage implements OnInit { private storageService: StorageService, private refinerService: RefinerService, private expensesService: ExpensesService, - private orgSettingsService: OrgSettingsService + private orgSettingsService: OrgSettingsService, + private spenderReportsService: SpenderReportsService ) {} detectTitleChange(): void { @@ -132,7 +134,7 @@ export class MyCreateReportPage implements OnInit { ), switchMap((report: ReportV1) => { if (expenseIDs.length) { - return this.reportService.addTransactions(report.id, expenseIDs).pipe(map(() => report)); + return this.spenderReportsService.addExpenses(report.id, expenseIDs).pipe(map(() => report)); } else { return of(report); } diff --git a/src/app/fyle/my-expenses/my-expenses.page.spec.ts b/src/app/fyle/my-expenses/my-expenses.page.spec.ts index 7bd5dcf390..8fcf84b59c 100644 --- a/src/app/fyle/my-expenses/my-expenses.page.spec.ts +++ b/src/app/fyle/my-expenses/my-expenses.page.spec.ts @@ -124,6 +124,7 @@ import { AddTxnToReportDialogComponent } from './add-txn-to-report-dialog/add-tx import { MyExpensesPage } from './my-expenses.page'; import { MyExpensesService } from './my-expenses.service'; import { completeStats, incompleteStats } from 'src/app/core/mock-data/platform/v1/expenses-stats.data'; +import { SpenderReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; describe('MyExpensesV2Page', () => { let component: MyExpensesPage; @@ -159,6 +160,7 @@ describe('MyExpensesV2Page', () => { let inputElement: HTMLInputElement; let sharedExpenseService: jasmine.SpyObj; let expensesService: jasmine.SpyObj; + let spenderReportsService: jasmine.SpyObj; beforeEach(waitForAsync(() => { const tasksServiceSpy = jasmine.createSpyObj('TasksService', ['getReportsTaskCount', 'getExpensesTaskCount']); @@ -255,6 +257,7 @@ describe('MyExpensesV2Page', () => { const popupServiceSpy = jasmine.createSpyObj('PopupService', ['showPopup']); const popoverControllerSpy = jasmine.createSpyObj('PopoverController', ['create']); const snackbarPropertiesSpy = jasmine.createSpyObj('SnackbarPropertiesService', ['setSnackbarProperties']); + const spenderReportsServiceSpy = jasmine.createSpyObj('SpenderReportsService', ['addExpenses']); const expensesServiceSpy = jasmine.createSpyObj('ExpensesService', [ 'getExpensesCount', 'getExpenses', @@ -386,6 +389,10 @@ describe('MyExpensesV2Page', () => { provide: SharedExpenseService, useValue: sharedExpenseServiceSpy, }, + { + provide: SpenderReportsService, + useValue: spenderReportsServiceSpy, + }, ReportState, MaskNumber, ], @@ -430,6 +437,7 @@ describe('MyExpensesV2Page', () => { snackbarProperties = TestBed.inject(SnackbarPropertiesService) as jasmine.SpyObj; expensesService = TestBed.inject(ExpensesService) as jasmine.SpyObj; sharedExpenseService = TestBed.inject(SharedExpenseService) as jasmine.SpyObj; + spenderReportsService = TestBed.inject(SpenderReportsService) as jasmine.SpyObj; component.loadExpenses$ = new BehaviorSubject({}); })); @@ -2436,13 +2444,13 @@ describe('MyExpensesV2Page', () => { loaderService.showLoader.and.resolveTo(); loaderService.hideLoader.and.resolveTo(true); - reportService.addTransactions.and.returnValue(of()); + spenderReportsService.addExpenses.and.returnValue(of()); component .addTransactionsToReport(apiExtendedReportRes[0], ['tx5fBcPBAxLv']) .pipe( tap((updatedReport) => { expect(loaderService.showLoader).toHaveBeenCalledOnceWith('Adding transaction to report'); - expect(reportService.addTransactions).toHaveBeenCalledOnceWith('rprAfNrce73O', ['tx5fBcPBAxLv']); + expect(spenderReportsService.addExpenses).toHaveBeenCalledOnceWith('rprAfNrce73O', ['tx5fBcPBAxLv']); expect(updatedReport).toEqual(apiExtendedReportRes[0]); }), finalize(() => { diff --git a/src/app/fyle/my-expenses/my-expenses.page.ts b/src/app/fyle/my-expenses/my-expenses.page.ts index a426e94b9c..caa66bee99 100644 --- a/src/app/fyle/my-expenses/my-expenses.page.ts +++ b/src/app/fyle/my-expenses/my-expenses.page.ts @@ -77,6 +77,7 @@ import { FyFiltersComponent } from '../../shared/components/fy-filters/fy-filter import { HeaderState } from '../../shared/components/fy-header/header-state.enum'; import { AddTxnToReportDialogComponent } from './add-txn-to-report-dialog/add-txn-to-report-dialog.component'; import { MyExpensesService } from './my-expenses.service'; +import { SpenderReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; @Component({ selector: 'app-my-expenses', @@ -224,7 +225,8 @@ export class MyExpensesPage implements OnInit { private categoriesService: CategoriesService, private navController: NavController, private expenseService: ExpensesService, - private sharedExpenseService: SharedExpenseService + private sharedExpenseService: SharedExpenseService, + private spenderReportsService: SpenderReportsService ) {} get HeaderState(): typeof HeaderState { @@ -1342,7 +1344,7 @@ export class MyExpensesPage implements OnInit { addTransactionsToReport(report: ExtendedReport, selectedExpensesId: string[]): Observable { return from(this.loaderService.showLoader('Adding transaction to report')).pipe( - switchMap(() => this.reportService.addTransactions(report.rp_id, selectedExpensesId).pipe(map(() => report))), + switchMap(() => this.spenderReportsService.addExpenses(report.rp_id, selectedExpensesId).pipe(map(() => report))), finalize(() => this.loaderService.hideLoader()) ); } diff --git a/src/app/fyle/my-view-report/my-view-report.page.spec.ts b/src/app/fyle/my-view-report/my-view-report.page.spec.ts index e28bb2cade..6b1120699b 100644 --- a/src/app/fyle/my-view-report/my-view-report.page.spec.ts +++ b/src/app/fyle/my-view-report/my-view-report.page.spec.ts @@ -55,6 +55,7 @@ import { MyViewReportPage } from './my-view-report.page'; import { AddExpensesToReportComponent } from './add-expenses-to-report/add-expenses-to-report.component'; import { ShareReportComponent } from './share-report/share-report.component'; import { EditReportNamePopoverComponent } from './edit-report-name-popover/edit-report-name-popover.component'; +import { SpenderReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; describe('MyViewReportPage', () => { let component: MyViewReportPage; @@ -75,6 +76,7 @@ describe('MyViewReportPage', () => { let statusService: jasmine.SpyObj; let refinerService: jasmine.SpyObj; let orgSettingsService: jasmine.SpyObj; + let spenderReportsService: jasmine.SpyObj; beforeEach(waitForAsync(() => { const reportServiceSpy = jasmine.createSpyObj('ReportService', [ @@ -116,6 +118,7 @@ describe('MyViewReportPage', () => { const statusServiceSpy = jasmine.createSpyObj('StatusService', ['find', 'createStatusMap', 'post']); const refinerServiceSpy = jasmine.createSpyObj('RefinerService', ['startSurvey']); const orgSettingsServiceSpy = jasmine.createSpyObj('OrgSettingsService', ['get']); + const spenderReportsServiceSpy = jasmine.createSpyObj('SpenderReportsService', ['addExpenses']); TestBed.configureTestingModule({ declarations: [ @@ -202,6 +205,10 @@ describe('MyViewReportPage', () => { provide: OrgSettingsService, useValue: orgSettingsServiceSpy, }, + { + provide: SpenderReportsService, + useValue: spenderReportsServiceSpy, + }, { provide: NavController, useValue: { push: NavController.prototype.back } }, ], schemas: [CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA], @@ -224,6 +231,7 @@ describe('MyViewReportPage', () => { statusService = TestBed.inject(StatusService) as jasmine.SpyObj; refinerService = TestBed.inject(RefinerService) as jasmine.SpyObj; orgSettingsService = TestBed.inject(OrgSettingsService) as jasmine.SpyObj; + spenderReportsService = TestBed.inject(SpenderReportsService) as jasmine.SpyObj; component.erpt$ = of(newReportParam); component.canEdit$ = of(true); @@ -1017,13 +1025,16 @@ describe('MyViewReportPage', () => { component.reportId = 'rpFkJ6jUJOyg'; component.unreportedExpenses = [expense1, expense2]; fixture.detectChanges(); - reportService.addTransactions.and.returnValue(of(null)); + spenderReportsService.addExpenses.and.returnValue(of(null)); spyOn(component.loadReportDetails$, 'next'); spyOn(component.loadReportTxns$, 'next'); component.addExpensesToReport(['txcSFe6efB62', 'tx3qHxFNgRcZ']); - expect(reportService.addTransactions).toHaveBeenCalledOnceWith('rpFkJ6jUJOyg', ['txcSFe6efB62', 'tx3qHxFNgRcZ']); + expect(spenderReportsService.addExpenses).toHaveBeenCalledOnceWith('rpFkJ6jUJOyg', [ + 'txcSFe6efB62', + 'tx3qHxFNgRcZ', + ]); expect(component.loadReportDetails$.next).toHaveBeenCalledTimes(1); expect(component.loadReportTxns$.next).toHaveBeenCalledTimes(1); expect(component.unreportedExpenses).toEqual([expenseData]); diff --git a/src/app/fyle/my-view-report/my-view-report.page.ts b/src/app/fyle/my-view-report/my-view-report.page.ts index b51855154b..9de76546d2 100644 --- a/src/app/fyle/my-view-report/my-view-report.page.ts +++ b/src/app/fyle/my-view-report/my-view-report.page.ts @@ -34,6 +34,7 @@ import { EditReportNamePopoverComponent } from './edit-report-name-popover/edit- import { ShareReportComponent } from './share-report/share-report.component'; import { PlatformHandlerService } from 'src/app/core/services/platform-handler.service'; import { BackButtonActionPriority } from 'src/app/core/models/back-button-action-priority.enum'; +import { SpenderReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; @Component({ selector: 'app-my-view-report', templateUrl: './my-view-report.page.html', @@ -127,7 +128,8 @@ export class MyViewReportPage { private statusService: StatusService, private refinerService: RefinerService, private orgSettingsService: OrgSettingsService, - private platformHandlerService: PlatformHandlerService + private platformHandlerService: PlatformHandlerService, + private spenderReportsService: SpenderReportsService ) {} get Segment(): typeof ReportPageSegment { @@ -594,7 +596,7 @@ export class MyViewReportPage { addExpensesToReport(selectedExpenseIds: string[]): void { this.isExpensesLoading = true; - this.reportService.addTransactions(this.reportId, selectedExpenseIds).subscribe(() => { + this.spenderReportsService.addExpenses(this.reportId, selectedExpenseIds).subscribe(() => { this.loadReportDetails$.next(); this.loadReportTxns$.next(); this.trackingService.addToExistingReport(); diff --git a/src/app/shared/components/create-new-report-v2/create-new-report.component.spec.ts b/src/app/shared/components/create-new-report-v2/create-new-report.component.spec.ts index 3b13b44afd..eda8331b9f 100644 --- a/src/app/shared/components/create-new-report-v2/create-new-report.component.spec.ts +++ b/src/app/shared/components/create-new-report-v2/create-new-report.component.spec.ts @@ -28,6 +28,7 @@ import { CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA } from '@angular/core'; import { Expense } from 'src/app/core/models/expense.model'; import { reportUnflattenedData, reportUnflattenedData2 } from 'src/app/core/mock-data/report-v1.data'; import { apiExpenses1, nonReimbursableExpense } from 'src/app/core/mock-data/platform/v1/expense.data'; +import { SpenderReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; describe('CreateNewReportComponent', () => { let component: CreateNewReportComponent; @@ -38,6 +39,7 @@ describe('CreateNewReportComponent', () => { let refinerService: jasmine.SpyObj; let currencyService: jasmine.SpyObj; let expenseFieldsService: jasmine.SpyObj; + let spenderReportsService: jasmine.SpyObj; beforeEach(waitForAsync(() => { modalController = jasmine.createSpyObj('ModalController', ['dismiss']); @@ -51,6 +53,7 @@ describe('CreateNewReportComponent', () => { refinerService = jasmine.createSpyObj('RefinerService', ['startSurvey']); currencyService = jasmine.createSpyObj('CurrencyService', ['getHomeCurrency']); expenseFieldsService = jasmine.createSpyObj('ExpenseFieldsService', ['getAllMap']); + spenderReportsService = jasmine.createSpyObj('SpenderReportsService', ['addExpenses']); const humanizeCurrencyPipeSpy = jasmine.createSpyObj('HumanizeCurrency', ['transform']); const fyCurrencyPipeSpy = jasmine.createSpyObj('FyCurrencyPipe', ['transform']); @@ -73,6 +76,7 @@ describe('CreateNewReportComponent', () => { { provide: ExpenseFieldsService, useValue: expenseFieldsService }, { provide: HumanizeCurrencyPipe, useValue: humanizeCurrencyPipeSpy }, { provide: FyCurrencyPipe, useValue: fyCurrencyPipeSpy }, + { provide: SpenderReportsService, useValue: spenderReportsService }, ], schemas: [CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA], }).compileComponents(); @@ -82,6 +86,7 @@ describe('CreateNewReportComponent', () => { refinerService = TestBed.inject(RefinerService) as jasmine.SpyObj; currencyService = TestBed.inject(CurrencyService) as jasmine.SpyObj; expenseFieldsService = TestBed.inject(ExpenseFieldsService) as jasmine.SpyObj; + spenderReportsService = TestBed.inject(SpenderReportsService) as jasmine.SpyObj; modalController = TestBed.inject(ModalController) as jasmine.SpyObj; currencyService.getHomeCurrency.and.returnValue(of(orgData1[0].currency)); @@ -207,7 +212,7 @@ describe('CreateNewReportComponent', () => { const Report_Value = 0; const report = reportUnflattenedData2; reportService.createDraft.and.returnValue(of(reportUnflattenedData2)); - reportService.addTransactions.and.returnValue(of(undefined)); + spenderReportsService.addExpenses.and.returnValue(of(undefined)); component.ctaClickedEvent('create_draft_report'); fixture.detectChanges(); tick(500); @@ -215,7 +220,7 @@ describe('CreateNewReportComponent', () => { expect(component.showReportNameError).toBeFalse(); expect(trackingService.createReport).toHaveBeenCalledOnceWith({ Expense_Count, Report_Value }); expect(reportService.createDraft).toHaveBeenCalledOnceWith(reportParam); - expect(reportService.addTransactions).toHaveBeenCalledOnceWith(reportID, txns); + expect(spenderReportsService.addExpenses).toHaveBeenCalledOnceWith(reportID, txns); expect(component.saveDraftReportLoader).toBeFalse(); expect(modalController.dismiss).toHaveBeenCalledOnceWith({ report, diff --git a/src/app/shared/components/create-new-report-v2/create-new-report.component.ts b/src/app/shared/components/create-new-report-v2/create-new-report.component.ts index d0b40225e4..1442fee016 100644 --- a/src/app/shared/components/create-new-report-v2/create-new-report.component.ts +++ b/src/app/shared/components/create-new-report-v2/create-new-report.component.ts @@ -11,6 +11,7 @@ import { RefinerService } from 'src/app/core/services/refiner.service'; import { CurrencyService } from 'src/app/core/services/currency.service'; import { ExpenseFieldsService } from 'src/app/core/services/expense-fields.service'; import { ReportV1 } from 'src/app/core/models/report-v1.model'; +import { SpenderReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; @Component({ selector: 'app-create-new-report', @@ -46,7 +47,8 @@ export class CreateNewReportComponent implements OnInit { private trackingService: TrackingService, private refinerService: RefinerService, private currencyService: CurrencyService, - private expenseFieldsService: ExpenseFieldsService + private expenseFieldsService: ExpenseFieldsService, + private spenderReportsService: SpenderReportsService ) {} getReportTitle(): Subscription { @@ -129,7 +131,7 @@ export class CreateNewReportComponent implements OnInit { ), switchMap((report: ReportV1) => { if (txnIds.length > 0) { - return this.reportService.addTransactions(report.id, txnIds).pipe(map(() => report)); + return this.spenderReportsService.addExpenses(report.id, txnIds).pipe(map(() => report)); } else { return of(report); } diff --git a/src/app/shared/components/create-new-report/create-new-report.component.spec.ts b/src/app/shared/components/create-new-report/create-new-report.component.spec.ts index 1b297c8bd3..8cc47f25f2 100644 --- a/src/app/shared/components/create-new-report/create-new-report.component.spec.ts +++ b/src/app/shared/components/create-new-report/create-new-report.component.spec.ts @@ -27,6 +27,7 @@ import { import { CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA } from '@angular/core'; import { Expense } from 'src/app/core/models/expense.model'; import { reportUnflattenedData, reportUnflattenedData2 } from 'src/app/core/mock-data/report-v1.data'; +import { SpenderReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; describe('CreateNewReportComponent', () => { let component: CreateNewReportComponent; @@ -37,6 +38,7 @@ describe('CreateNewReportComponent', () => { let refinerService: jasmine.SpyObj; let currencyService: jasmine.SpyObj; let expenseFieldsService: jasmine.SpyObj; + let spenderReportsService: jasmine.SpyObj; beforeEach(waitForAsync(() => { modalController = jasmine.createSpyObj('ModalController', ['dismiss']); @@ -50,6 +52,7 @@ describe('CreateNewReportComponent', () => { refinerService = jasmine.createSpyObj('RefinerService', ['startSurvey']); currencyService = jasmine.createSpyObj('CurrencyService', ['getHomeCurrency']); expenseFieldsService = jasmine.createSpyObj('ExpenseFieldsService', ['getAllMap']); + const spenderReportsServiceSpy = jasmine.createSpyObj('SpenderReportsService', ['addExpenses']); const humanizeCurrencyPipeSpy = jasmine.createSpyObj('HumanizeCurrency', ['transform']); const fyCurrencyPipeSpy = jasmine.createSpyObj('FyCurrencyPipe', ['transform']); @@ -72,6 +75,7 @@ describe('CreateNewReportComponent', () => { { provide: ExpenseFieldsService, useValue: expenseFieldsService }, { provide: HumanizeCurrencyPipe, useValue: humanizeCurrencyPipeSpy }, { provide: FyCurrencyPipe, useValue: fyCurrencyPipeSpy }, + { provide: SpenderReportsService, useValue: spenderReportsServiceSpy }, ], schemas: [CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA], }).compileComponents(); @@ -81,6 +85,7 @@ describe('CreateNewReportComponent', () => { refinerService = TestBed.inject(RefinerService) as jasmine.SpyObj; currencyService = TestBed.inject(CurrencyService) as jasmine.SpyObj; expenseFieldsService = TestBed.inject(ExpenseFieldsService) as jasmine.SpyObj; + spenderReportsService = TestBed.inject(SpenderReportsService) as jasmine.SpyObj; modalController = TestBed.inject(ModalController) as jasmine.SpyObj; currencyService.getHomeCurrency.and.returnValue(of(orgData1[0].currency)); @@ -196,7 +201,7 @@ describe('CreateNewReportComponent', () => { const Report_Value = 0; const report = reportUnflattenedData2; reportService.createDraft.and.returnValue(of(reportUnflattenedData2)); - reportService.addTransactions.and.returnValue(of(undefined)); + spenderReportsService.addExpenses.and.returnValue(of(undefined)); component.ctaClickedEvent('create_draft_report'); fixture.detectChanges(); tick(500); @@ -204,7 +209,7 @@ describe('CreateNewReportComponent', () => { expect(component.showReportNameError).toBeFalse(); expect(trackingService.createReport).toHaveBeenCalledOnceWith({ Expense_Count, Report_Value }); expect(reportService.createDraft).toHaveBeenCalledOnceWith(reportParam); - expect(reportService.addTransactions).toHaveBeenCalledOnceWith(reportID, tnxs); + expect(spenderReportsService.addExpenses).toHaveBeenCalledOnceWith(reportID, tnxs); expect(component.saveDraftReportLoader).toBeFalse(); expect(modalController.dismiss).toHaveBeenCalledOnceWith({ report, diff --git a/src/app/shared/components/create-new-report/create-new-report.component.ts b/src/app/shared/components/create-new-report/create-new-report.component.ts index abbd1107e7..28f03925aa 100644 --- a/src/app/shared/components/create-new-report/create-new-report.component.ts +++ b/src/app/shared/components/create-new-report/create-new-report.component.ts @@ -11,6 +11,7 @@ import { RefinerService } from 'src/app/core/services/refiner.service'; import { CurrencyService } from 'src/app/core/services/currency.service'; import { ExpenseFieldsService } from 'src/app/core/services/expense-fields.service'; import { ReportV1 } from 'src/app/core/models/report-v1.model'; +import { SpenderReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; @Component({ selector: 'app-create-new-report', @@ -46,7 +47,8 @@ export class CreateNewReportComponent implements OnInit { private trackingService: TrackingService, private refinerService: RefinerService, private currencyService: CurrencyService, - private expenseFieldsService: ExpenseFieldsService + private expenseFieldsService: ExpenseFieldsService, + private spenderReportsService: SpenderReportsService ) {} getReportTitle(): Subscription { @@ -129,7 +131,7 @@ export class CreateNewReportComponent implements OnInit { ), switchMap((report: ReportV1) => { if (txnIds.length > 0) { - return this.reportService.addTransactions(report.id, txnIds).pipe(map(() => report)); + return this.spenderReportsService.addExpenses(report.id, txnIds).pipe(map(() => report)); } else { return of(report); } From c2a8e743ac3577ba15f394290e56034140e52593 Mon Sep 17 00:00:00 2001 From: aastha Date: Thu, 25 Apr 2024 18:05:42 +0530 Subject: [PATCH 13/46] Minor --- .../platform/v1/reports-query-params.model.ts | 1 + .../platform/v1/approver/reports.service.ts | 49 +++++++++++++++++-- .../v1/spender/reports.service.spec.ts | 12 +++++ .../platform/v1/spender/reports.service.ts | 16 +++++- 4 files changed, 73 insertions(+), 5 deletions(-) diff --git a/src/app/core/models/platform/v1/reports-query-params.model.ts b/src/app/core/models/platform/v1/reports-query-params.model.ts index d1e53cbd71..5cac67b9f0 100644 --- a/src/app/core/models/platform/v1/reports-query-params.model.ts +++ b/src/app/core/models/platform/v1/reports-query-params.model.ts @@ -3,4 +3,5 @@ export interface ReportsQueryParams { offset?: number; limit?: number; order?: string; + id?: string; } diff --git a/src/app/core/services/platform/v1/approver/reports.service.ts b/src/app/core/services/platform/v1/approver/reports.service.ts index 9003899580..c2069bd716 100644 --- a/src/app/core/services/platform/v1/approver/reports.service.ts +++ b/src/app/core/services/platform/v1/approver/reports.service.ts @@ -1,12 +1,55 @@ -import { Injectable } from '@angular/core'; -import { Observable } from 'rxjs'; +import { Inject, Injectable } from '@angular/core'; +import { Observable, concatMap, map, range, reduce, switchMap } from 'rxjs'; import { ApproverPlatformApiService } from '../../../approver-platform-api.service'; +import { PlatformApiResponse } from 'src/app/core/models/platform/platform-api-response.model'; +import { ReportsQueryParams } from 'src/app/core/models/platform/v1/reports-query-params.model'; +import { PAGINATION_SIZE } from 'src/app/constants'; +import { Report } from 'src/app/core/models/platform/v1/report.model'; @Injectable({ providedIn: 'root', }) export class ApproverReportsService { - constructor(private approverPlatformApiService: ApproverPlatformApiService) {} + constructor( + @Inject(PAGINATION_SIZE) private paginationSize: number, + private approverPlatformApiService: ApproverPlatformApiService + ) {} + + getAllReportsByParams(queryParams: ReportsQueryParams): Observable { + return this.getReportsCount(queryParams).pipe( + switchMap((count) => { + count = count > this.paginationSize ? count / this.paginationSize : 1; + return range(0, count); + }), + concatMap((page) => { + let params = { + ...queryParams, + offset: this.paginationSize * page, + limit: this.paginationSize, + }; + return this.getReportsByParams(params); + }), + reduce((acc, curr) => acc.concat(curr.data), [] as Report[]) + ); + } + + getReportsCount(queryParams: ReportsQueryParams): Observable { + let params = { + state: queryParams.state, + limit: 1, + offset: 0, + }; + return this.getReportsByParams(params).pipe(map((res) => res.count)); + } + + getReportsByParams(queryParams: ReportsQueryParams = {}): Observable> { + const config = { + params: { + ...queryParams, + }, + }; + return this.approverPlatformApiService.get>('/reports', config); + } ejectExpenses(rptId: string, expenseId: string, comment?: string[]): Observable { const payload = { diff --git a/src/app/core/services/platform/v1/spender/reports.service.spec.ts b/src/app/core/services/platform/v1/spender/reports.service.spec.ts index 1930184541..f73cb6e284 100644 --- a/src/app/core/services/platform/v1/spender/reports.service.spec.ts +++ b/src/app/core/services/platform/v1/spender/reports.service.spec.ts @@ -12,6 +12,7 @@ import { mockQueryParams, } from 'src/app/core/mock-data/platform-report.data'; import { ReportsQueryParams } from 'src/app/core/models/platform/v1/reports-query-params.model'; +import { query } from '@angular/animations'; describe('SpenderReportsService', () => { let spenderReportsService: SpenderReportsService; @@ -141,6 +142,17 @@ describe('SpenderReportsService', () => { }); }); + it('getReport(): should get a report by id', () => { + const getReportsByParams = spyOn(spenderReportsService, 'getReportsByParams'); + const queryParams = { + id: 'rpvcIMRMyM3A', + }; + getReportsByParams.withArgs(queryParams).and.returnValue(of(allReportsPaginated1)); + spenderReportsService.getReport('rpvcIMRMyM3A').subscribe((res) => { + expect(getReportsByParams).toHaveBeenCalledOnceWith(queryParams); + }); + }); + it('ejectExpenses(): should remove an expense from a report', (done) => { spenderPlatformV1ApiService.post.and.returnValue(of(null)); diff --git a/src/app/core/services/platform/v1/spender/reports.service.ts b/src/app/core/services/platform/v1/spender/reports.service.ts index de6b497e06..f86602e3c8 100644 --- a/src/app/core/services/platform/v1/spender/reports.service.ts +++ b/src/app/core/services/platform/v1/spender/reports.service.ts @@ -18,7 +18,7 @@ export class SpenderReportsService { private spenderPlatformV1ApiService: SpenderPlatformV1ApiService ) {} - getAllReportsByParams(queryParams: ReportsQueryParams): Observable { + getAllReportsByParams(queryParams: ReportsQueryParams, order?: string): Observable { return this.getReportsCount(queryParams).pipe( switchMap((count) => { count = count > this.paginationSize ? count / this.paginationSize : 1; @@ -26,10 +26,18 @@ export class SpenderReportsService { }), concatMap((page) => { let params = { - state: queryParams.state, + ...queryParams, offset: this.paginationSize * page, limit: this.paginationSize, }; + + if (order) { + params = { + ...params, + order, + }; + } + return this.getReportsByParams(params); }), reduce((acc, curr) => acc.concat(curr.data), [] as Report[]) @@ -54,6 +62,10 @@ export class SpenderReportsService { return this.spenderPlatformV1ApiService.get>('/reports', config); } + getReport(id: string): Observable { + return this.getReportsByParams({ id: `eq.${id}` }).pipe(map((res) => res.data[0])); + } + createDraft(data: CreateDraftParams): Observable { return this.spenderPlatformV1ApiService .post>('/reports', data) From 94a919d2d80cfe11e511a4547d0615417c391faa Mon Sep 17 00:00:00 2001 From: aastha Date: Fri, 26 Apr 2024 06:30:00 +0530 Subject: [PATCH 14/46] Minor --- .../v1/platform-stats-requesst-param.model.ts | 3 +++ .../services/platform/v1/spender/reports.service.ts | 12 ++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 src/app/core/models/platform/v1/platform-stats-requesst-param.model.ts diff --git a/src/app/core/models/platform/v1/platform-stats-requesst-param.model.ts b/src/app/core/models/platform/v1/platform-stats-requesst-param.model.ts new file mode 100644 index 0000000000..484eb2c083 --- /dev/null +++ b/src/app/core/models/platform/v1/platform-stats-requesst-param.model.ts @@ -0,0 +1,3 @@ +export interface PlatformStatsRequestParams { + state: string; +} diff --git a/src/app/core/services/platform/v1/spender/reports.service.ts b/src/app/core/services/platform/v1/spender/reports.service.ts index f86602e3c8..d9b858b40e 100644 --- a/src/app/core/services/platform/v1/spender/reports.service.ts +++ b/src/app/core/services/platform/v1/spender/reports.service.ts @@ -8,6 +8,8 @@ import { ReportsQueryParams } from 'src/app/core/models/platform/v1/reports-quer import { PAGINATION_SIZE } from 'src/app/constants'; import { CreateDraftParams } from 'src/app/core/models/platform/v1/create-draft-params.model'; import { PlatformApiPayload } from 'src/app/core/models/platform/platform-api-payload.model'; +import { StatsResponse } from 'src/app/core/models/v2/stats-response.model'; +import { PlatformStatsRequestParams } from 'src/app/core/models/platform/v1/platform-stats-requesst-param.model'; @Injectable({ providedIn: 'root', @@ -83,6 +85,16 @@ export class SpenderReportsService { return this.spenderPlatformV1ApiService.post('/reports/eject_expenses', payload); } + getReportsStats(params: PlatformStatsRequestParams): Observable { + return this.spenderPlatformV1ApiService + .post<{ data: StatsResponse }>('/reports/stats', { + data: { + query_params: `state=${params.state}`, + }, + }) + .pipe(map((res) => res.data)); + } + addExpenses(rptId: string, txnIds: string[]): Observable { const payload = { data: { From 5eaefdf4ec3f351d1e82b9c0c127f80b23103aad Mon Sep 17 00:00:00 2001 From: aastha Date: Fri, 26 Apr 2024 07:23:17 +0530 Subject: [PATCH 15/46] Minor --- .../services/platform/v1/approver/reports.service.spec.ts | 2 ++ .../services/platform/v1/spender/reports.service.spec.ts | 8 ++++---- .../core/services/platform/v1/spender/reports.service.ts | 2 ++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/app/core/services/platform/v1/approver/reports.service.spec.ts b/src/app/core/services/platform/v1/approver/reports.service.spec.ts index 542a5ab864..ffa1470789 100644 --- a/src/app/core/services/platform/v1/approver/reports.service.spec.ts +++ b/src/app/core/services/platform/v1/approver/reports.service.spec.ts @@ -2,6 +2,7 @@ import { TestBed } from '@angular/core/testing'; import { ApproverReportsService } from './reports.service'; import { ApproverPlatformApiService } from '../../../approver-platform-api.service'; import { of } from 'rxjs'; +import { PAGINATION_SIZE } from 'src/app/constants'; describe('ApproverReportsService', () => { let approverReportsService: ApproverReportsService; @@ -11,6 +12,7 @@ describe('ApproverReportsService', () => { TestBed.configureTestingModule({ providers: [ ApproverReportsService, + { provide: PAGINATION_SIZE, useValue: 2 }, { provide: ApproverPlatformApiService, useValue: approverPlatformApiService }, ], }); diff --git a/src/app/core/services/platform/v1/spender/reports.service.spec.ts b/src/app/core/services/platform/v1/spender/reports.service.spec.ts index f73cb6e284..7527a9b011 100644 --- a/src/app/core/services/platform/v1/spender/reports.service.spec.ts +++ b/src/app/core/services/platform/v1/spender/reports.service.spec.ts @@ -143,13 +143,13 @@ describe('SpenderReportsService', () => { }); it('getReport(): should get a report by id', () => { - const getReportsByParams = spyOn(spenderReportsService, 'getReportsByParams'); + spyOn(spenderReportsService, 'getReportsByParams').and.returnValue(of(allReportsPaginated1)); const queryParams = { - id: 'rpvcIMRMyM3A', + id: 'eq.rpvcIMRMyM3A', }; - getReportsByParams.withArgs(queryParams).and.returnValue(of(allReportsPaginated1)); spenderReportsService.getReport('rpvcIMRMyM3A').subscribe((res) => { - expect(getReportsByParams).toHaveBeenCalledOnceWith(queryParams); + console.log(res); + expect(spenderReportsService.getReportsByParams).toHaveBeenCalledOnceWith(queryParams); }); }); diff --git a/src/app/core/services/platform/v1/spender/reports.service.ts b/src/app/core/services/platform/v1/spender/reports.service.ts index d9b858b40e..5f5aa6f9a1 100644 --- a/src/app/core/services/platform/v1/spender/reports.service.ts +++ b/src/app/core/services/platform/v1/spender/reports.service.ts @@ -56,6 +56,7 @@ export class SpenderReportsService { } getReportsByParams(queryParams: ReportsQueryParams = {}): Observable> { + console.log(queryParams); const config = { params: { ...queryParams, @@ -65,6 +66,7 @@ export class SpenderReportsService { } getReport(id: string): Observable { + console.log({ id: `eq.${id}` }); return this.getReportsByParams({ id: `eq.${id}` }).pipe(map((res) => res.data[0])); } From 436ac68661de260474b71e1dde733e860a963ad2 Mon Sep 17 00:00:00 2001 From: aastha Date: Fri, 26 Apr 2024 07:44:51 +0530 Subject: [PATCH 16/46] Minor --- .../v1/spender/reports.service.spec.ts | 22 +++++++++++++++++++ .../platform/v1/spender/reports.service.ts | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/app/core/services/platform/v1/spender/reports.service.spec.ts b/src/app/core/services/platform/v1/spender/reports.service.spec.ts index 7527a9b011..fe35b6979f 100644 --- a/src/app/core/services/platform/v1/spender/reports.service.spec.ts +++ b/src/app/core/services/platform/v1/spender/reports.service.spec.ts @@ -153,6 +153,28 @@ describe('SpenderReportsService', () => { }); }); + it('getAdvanceRequestStats(): should get advance request stats', (done) => { + const statsResponse = { + count: 2, + total_amount: 1200, + }; + spenderPlatformV1ApiService.post.and.returnValue(of({ data: statsResponse })); + + const params = { + state: 'eq.SENT_BACK', + }; + + spenderReportsService.getReportsStats(params).subscribe((res) => { + expect(res).toEqual(statsResponse); + expect(spenderPlatformV1ApiService.post).toHaveBeenCalledOnceWith('/reports/stats', { + data: { + query_params: `state=${params.state}`, + }, + }); + done(); + }); + }); + it('ejectExpenses(): should remove an expense from a report', (done) => { spenderPlatformV1ApiService.post.and.returnValue(of(null)); diff --git a/src/app/core/services/platform/v1/spender/reports.service.ts b/src/app/core/services/platform/v1/spender/reports.service.ts index 5f5aa6f9a1..04fc659343 100644 --- a/src/app/core/services/platform/v1/spender/reports.service.ts +++ b/src/app/core/services/platform/v1/spender/reports.service.ts @@ -8,7 +8,7 @@ import { ReportsQueryParams } from 'src/app/core/models/platform/v1/reports-quer import { PAGINATION_SIZE } from 'src/app/constants'; import { CreateDraftParams } from 'src/app/core/models/platform/v1/create-draft-params.model'; import { PlatformApiPayload } from 'src/app/core/models/platform/platform-api-payload.model'; -import { StatsResponse } from 'src/app/core/models/v2/stats-response.model'; +import { StatsResponse } from 'src/app/core/models/platform/v1/stats-response.model'; import { PlatformStatsRequestParams } from 'src/app/core/models/platform/v1/platform-stats-requesst-param.model'; @Injectable({ From 1943364c050cd7d6194adb03ad656c1e4a7cd517 Mon Sep 17 00:00:00 2001 From: Aastha Bist Date: Fri, 26 Apr 2024 07:46:17 +0530 Subject: [PATCH 17/46] Update reports.service.spec.ts --- .../core/services/platform/v1/spender/reports.service.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/core/services/platform/v1/spender/reports.service.spec.ts b/src/app/core/services/platform/v1/spender/reports.service.spec.ts index fe35b6979f..792e04fc77 100644 --- a/src/app/core/services/platform/v1/spender/reports.service.spec.ts +++ b/src/app/core/services/platform/v1/spender/reports.service.spec.ts @@ -153,7 +153,7 @@ describe('SpenderReportsService', () => { }); }); - it('getAdvanceRequestStats(): should get advance request stats', (done) => { + it('getReportsStats(): should get advance request stats', (done) => { const statsResponse = { count: 2, total_amount: 1200, @@ -161,7 +161,7 @@ describe('SpenderReportsService', () => { spenderPlatformV1ApiService.post.and.returnValue(of({ data: statsResponse })); const params = { - state: 'eq.SENT_BACK', + state: 'eq.DRAFT', }; spenderReportsService.getReportsStats(params).subscribe((res) => { From c6e9fcc8522c9d933c6f76347fec141ba4eb8c2e Mon Sep 17 00:00:00 2001 From: Aastha Bist Date: Fri, 26 Apr 2024 08:18:38 +0530 Subject: [PATCH 18/46] Update reports.service.ts --- src/app/core/services/platform/v1/spender/reports.service.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/app/core/services/platform/v1/spender/reports.service.ts b/src/app/core/services/platform/v1/spender/reports.service.ts index 04fc659343..630ff980a6 100644 --- a/src/app/core/services/platform/v1/spender/reports.service.ts +++ b/src/app/core/services/platform/v1/spender/reports.service.ts @@ -56,7 +56,6 @@ export class SpenderReportsService { } getReportsByParams(queryParams: ReportsQueryParams = {}): Observable> { - console.log(queryParams); const config = { params: { ...queryParams, @@ -66,7 +65,6 @@ export class SpenderReportsService { } getReport(id: string): Observable { - console.log({ id: `eq.${id}` }); return this.getReportsByParams({ id: `eq.${id}` }).pipe(map((res) => res.data[0])); } From 597b6f4bd3000bf9d8835037149f190ef3661c33 Mon Sep 17 00:00:00 2001 From: aastha Date: Fri, 26 Apr 2024 12:29:20 +0530 Subject: [PATCH 19/46] Minor --- .../platform/v1/approver/reports.service.ts | 42 +------------------ 1 file changed, 1 insertion(+), 41 deletions(-) diff --git a/src/app/core/services/platform/v1/approver/reports.service.ts b/src/app/core/services/platform/v1/approver/reports.service.ts index c2069bd716..1b85683d6e 100644 --- a/src/app/core/services/platform/v1/approver/reports.service.ts +++ b/src/app/core/services/platform/v1/approver/reports.service.ts @@ -1,10 +1,6 @@ import { Inject, Injectable } from '@angular/core'; -import { Observable, concatMap, map, range, reduce, switchMap } from 'rxjs'; +import { Observable } from 'rxjs'; import { ApproverPlatformApiService } from '../../../approver-platform-api.service'; -import { PlatformApiResponse } from 'src/app/core/models/platform/platform-api-response.model'; -import { ReportsQueryParams } from 'src/app/core/models/platform/v1/reports-query-params.model'; -import { PAGINATION_SIZE } from 'src/app/constants'; -import { Report } from 'src/app/core/models/platform/v1/report.model'; @Injectable({ providedIn: 'root', @@ -15,42 +11,6 @@ export class ApproverReportsService { private approverPlatformApiService: ApproverPlatformApiService ) {} - getAllReportsByParams(queryParams: ReportsQueryParams): Observable { - return this.getReportsCount(queryParams).pipe( - switchMap((count) => { - count = count > this.paginationSize ? count / this.paginationSize : 1; - return range(0, count); - }), - concatMap((page) => { - let params = { - ...queryParams, - offset: this.paginationSize * page, - limit: this.paginationSize, - }; - return this.getReportsByParams(params); - }), - reduce((acc, curr) => acc.concat(curr.data), [] as Report[]) - ); - } - - getReportsCount(queryParams: ReportsQueryParams): Observable { - let params = { - state: queryParams.state, - limit: 1, - offset: 0, - }; - return this.getReportsByParams(params).pipe(map((res) => res.count)); - } - - getReportsByParams(queryParams: ReportsQueryParams = {}): Observable> { - const config = { - params: { - ...queryParams, - }, - }; - return this.approverPlatformApiService.get>('/reports', config); - } - ejectExpenses(rptId: string, expenseId: string, comment?: string[]): Observable { const payload = { data: { From 127299916c5a08a75206d5ba34367d440c5e4292 Mon Sep 17 00:00:00 2001 From: Aastha Bist Date: Fri, 26 Apr 2024 12:31:19 +0530 Subject: [PATCH 20/46] Update reports.service.spec.ts --- .../core/services/platform/v1/spender/reports.service.spec.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/app/core/services/platform/v1/spender/reports.service.spec.ts b/src/app/core/services/platform/v1/spender/reports.service.spec.ts index 792e04fc77..2a41ed0354 100644 --- a/src/app/core/services/platform/v1/spender/reports.service.spec.ts +++ b/src/app/core/services/platform/v1/spender/reports.service.spec.ts @@ -12,7 +12,6 @@ import { mockQueryParams, } from 'src/app/core/mock-data/platform-report.data'; import { ReportsQueryParams } from 'src/app/core/models/platform/v1/reports-query-params.model'; -import { query } from '@angular/animations'; describe('SpenderReportsService', () => { let spenderReportsService: SpenderReportsService; From d51f7adff5ded586c79e348ab1c5e1032a90d5f3 Mon Sep 17 00:00:00 2001 From: aastha Date: Fri, 26 Apr 2024 12:31:56 +0530 Subject: [PATCH 21/46] Revert "Minor" This reverts commit 597b6f4bd3000bf9d8835037149f190ef3661c33. --- .../platform/v1/approver/reports.service.ts | 42 ++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/src/app/core/services/platform/v1/approver/reports.service.ts b/src/app/core/services/platform/v1/approver/reports.service.ts index 1b85683d6e..c2069bd716 100644 --- a/src/app/core/services/platform/v1/approver/reports.service.ts +++ b/src/app/core/services/platform/v1/approver/reports.service.ts @@ -1,6 +1,10 @@ import { Inject, Injectable } from '@angular/core'; -import { Observable } from 'rxjs'; +import { Observable, concatMap, map, range, reduce, switchMap } from 'rxjs'; import { ApproverPlatformApiService } from '../../../approver-platform-api.service'; +import { PlatformApiResponse } from 'src/app/core/models/platform/platform-api-response.model'; +import { ReportsQueryParams } from 'src/app/core/models/platform/v1/reports-query-params.model'; +import { PAGINATION_SIZE } from 'src/app/constants'; +import { Report } from 'src/app/core/models/platform/v1/report.model'; @Injectable({ providedIn: 'root', @@ -11,6 +15,42 @@ export class ApproverReportsService { private approverPlatformApiService: ApproverPlatformApiService ) {} + getAllReportsByParams(queryParams: ReportsQueryParams): Observable { + return this.getReportsCount(queryParams).pipe( + switchMap((count) => { + count = count > this.paginationSize ? count / this.paginationSize : 1; + return range(0, count); + }), + concatMap((page) => { + let params = { + ...queryParams, + offset: this.paginationSize * page, + limit: this.paginationSize, + }; + return this.getReportsByParams(params); + }), + reduce((acc, curr) => acc.concat(curr.data), [] as Report[]) + ); + } + + getReportsCount(queryParams: ReportsQueryParams): Observable { + let params = { + state: queryParams.state, + limit: 1, + offset: 0, + }; + return this.getReportsByParams(params).pipe(map((res) => res.count)); + } + + getReportsByParams(queryParams: ReportsQueryParams = {}): Observable> { + const config = { + params: { + ...queryParams, + }, + }; + return this.approverPlatformApiService.get>('/reports', config); + } + ejectExpenses(rptId: string, expenseId: string, comment?: string[]): Observable { const payload = { data: { From c1fe7b0ad2111a9874308360b8646efa7807ce87 Mon Sep 17 00:00:00 2001 From: Aastha Bist Date: Fri, 26 Apr 2024 12:42:59 +0530 Subject: [PATCH 22/46] Update reports.service.ts --- src/app/core/services/platform/v1/spender/reports.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/core/services/platform/v1/spender/reports.service.ts b/src/app/core/services/platform/v1/spender/reports.service.ts index f96e17d1c2..43c7e74eb0 100644 --- a/src/app/core/services/platform/v1/spender/reports.service.ts +++ b/src/app/core/services/platform/v1/spender/reports.service.ts @@ -95,7 +95,7 @@ export class SpenderReportsService { .pipe(map((res) => res.data)); } - addExpenses(rptId: string, txnIds: string[]): Observable { + addExpenses(rptId: string, expenseIds: string[]): Observable { const payload = { data: { id: rptId, From 109fa150c5658fd8df0af56d066f95018c4ec545 Mon Sep 17 00:00:00 2001 From: Aastha Bist Date: Fri, 26 Apr 2024 12:43:22 +0530 Subject: [PATCH 23/46] Rename platform-stats-requesst-param.model.ts to platform-stats-request-param.model.ts --- ...uesst-param.model.ts => platform-stats-request-param.model.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/app/core/models/platform/v1/{platform-stats-requesst-param.model.ts => platform-stats-request-param.model.ts} (100%) diff --git a/src/app/core/models/platform/v1/platform-stats-requesst-param.model.ts b/src/app/core/models/platform/v1/platform-stats-request-param.model.ts similarity index 100% rename from src/app/core/models/platform/v1/platform-stats-requesst-param.model.ts rename to src/app/core/models/platform/v1/platform-stats-request-param.model.ts From 74be123800e8eba30aa83da8dd1b1b5939376c4a Mon Sep 17 00:00:00 2001 From: Aastha Bist Date: Fri, 26 Apr 2024 12:43:39 +0530 Subject: [PATCH 24/46] Update reports.service.ts --- src/app/core/services/platform/v1/spender/reports.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/core/services/platform/v1/spender/reports.service.ts b/src/app/core/services/platform/v1/spender/reports.service.ts index 43c7e74eb0..e4f1b2d58d 100644 --- a/src/app/core/services/platform/v1/spender/reports.service.ts +++ b/src/app/core/services/platform/v1/spender/reports.service.ts @@ -9,7 +9,7 @@ import { PAGINATION_SIZE } from 'src/app/constants'; import { CreateDraftParams } from 'src/app/core/models/platform/v1/create-draft-params.model'; import { PlatformApiPayload } from 'src/app/core/models/platform/platform-api-payload.model'; import { StatsResponse } from 'src/app/core/models/platform/v1/stats-response.model'; -import { PlatformStatsRequestParams } from 'src/app/core/models/platform/v1/platform-stats-requesst-param.model'; +import { PlatformStatsRequestParams } from 'src/app/core/models/platform/v1/platform-stats-request-param.model'; @Injectable({ providedIn: 'root', From bdb940a971b2368165f9c5693f75168403c93f9e Mon Sep 17 00:00:00 2001 From: Aastha Bist Date: Fri, 26 Apr 2024 13:00:11 +0530 Subject: [PATCH 25/46] Update reports.service.ts --- src/app/core/services/platform/v1/approver/reports.service.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/app/core/services/platform/v1/approver/reports.service.ts b/src/app/core/services/platform/v1/approver/reports.service.ts index 1b85683d6e..6dfb306353 100644 --- a/src/app/core/services/platform/v1/approver/reports.service.ts +++ b/src/app/core/services/platform/v1/approver/reports.service.ts @@ -1,6 +1,7 @@ import { Inject, Injectable } from '@angular/core'; import { Observable } from 'rxjs'; import { ApproverPlatformApiService } from '../../../approver-platform-api.service'; +import { PAGINATION_SIZE } from 'src/app/constants'; @Injectable({ providedIn: 'root', From 12fa61d224e8380b270eb5a1165d82c92a86dcdf Mon Sep 17 00:00:00 2001 From: Aastha Bist Date: Fri, 26 Apr 2024 15:19:36 +0530 Subject: [PATCH 26/46] Update reports.service.ts --- .../platform/v1/approver/reports.service.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/app/core/services/platform/v1/approver/reports.service.ts b/src/app/core/services/platform/v1/approver/reports.service.ts index c2069bd716..eb36781bdf 100644 --- a/src/app/core/services/platform/v1/approver/reports.service.ts +++ b/src/app/core/services/platform/v1/approver/reports.service.ts @@ -51,6 +51,20 @@ export class ApproverReportsService { return this.approverPlatformApiService.get>('/reports', config); } + getReportsStats(params: PlatformStatsRequestParams): Observable { + return this.approverPlatformApiService + .post<{ data: StatsResponse }>('/reports/stats', { + data: { + query_params: `state=${params.state}`, + }, + }) + .pipe(map((res) => res.data)); + } + + getReport(id: string): Observable { + return this.getReportsByParams({ id: `eq.${id}` }).pipe(map((res) => res.data[0])); + } + ejectExpenses(rptId: string, expenseId: string, comment?: string[]): Observable { const payload = { data: { From 4a812b6a2145675f91c595cbaa7ea7f02ed0b980 Mon Sep 17 00:00:00 2001 From: aastha Date: Fri, 26 Apr 2024 17:35:04 +0530 Subject: [PATCH 27/46] Minor --- .../v1/approver/reports.service.spec.ts | 128 ++++++++++++++++++ .../platform/v1/approver/reports.service.ts | 16 +++ 2 files changed, 144 insertions(+) diff --git a/src/app/core/services/platform/v1/approver/reports.service.spec.ts b/src/app/core/services/platform/v1/approver/reports.service.spec.ts index ffa1470789..e1cf142cbb 100644 --- a/src/app/core/services/platform/v1/approver/reports.service.spec.ts +++ b/src/app/core/services/platform/v1/approver/reports.service.spec.ts @@ -3,6 +3,14 @@ import { ApproverReportsService } from './reports.service'; import { ApproverPlatformApiService } from '../../../approver-platform-api.service'; import { of } from 'rxjs'; import { PAGINATION_SIZE } from 'src/app/constants'; +import { + allReportsPaginated1, + allReportsPaginated2, + expectedReportsPaginated, + expectedReportsSinglePage, + mockQueryParams, +} from 'src/app/core/mock-data/platform-report.data'; +import { ReportsQueryParams } from 'src/app/core/models/platform/v1/reports-query-params.model'; describe('ApproverReportsService', () => { let approverReportsService: ApproverReportsService; @@ -41,4 +49,124 @@ describe('ApproverReportsService', () => { done(); }); }); + + it('getReportsCount(): should get a count of reports', (done) => { + // Mock the response of getReportsByParams + spyOn(approverReportsService, 'getReportsByParams').and.returnValue(of(platformReportCountData)); + + const expectedParams: ReportsQueryParams = { + ...mockQueryParams, + limit: 1, + offset: 0, + }; + + approverReportsService.getReportsCount(mockQueryParams).subscribe((res) => { + // Verify + expect(res).toEqual(4); // Check if the count is as expected + expect(approverReportsService.getReportsByParams).toHaveBeenCalledWith(expectedParams); // Check if the method is called with the expected params + done(); // Call 'done' to indicate the end of the asynchronous test + }); + }); + + it('getAllReportsByParams(): should get all reports multiple pages', (done) => { + const getReportsByParams = spyOn(approverReportsService, 'getReportsByParams'); + spyOn(approverReportsService, 'getReportsCount').and.returnValue(of(4)); + + const expectedParams1: ReportsQueryParams = { + ...mockQueryParams, + limit: 2, + offset: 0, + }; + const expectedParams2: ReportsQueryParams = { + ...mockQueryParams, + limit: 2, + offset: 2, + }; + + getReportsByParams.withArgs(expectedParams1).and.returnValue(of(allReportsPaginated1)); + getReportsByParams.withArgs(expectedParams2).and.returnValue(of(allReportsPaginated2)); + + approverReportsService.getAllReportsByParams(mockQueryParams).subscribe((res) => { + expect(res).toEqual(expectedReportsPaginated); + expect(approverReportsService.getReportsCount).toHaveBeenCalledOnceWith({ + state: 'in.(DRAFT,APPROVER_PENDING,APPROVER_INQUIRY)', + }); + expect(getReportsByParams).toHaveBeenCalledWith(expectedParams1); + expect(getReportsByParams).toHaveBeenCalledWith(expectedParams2); + expect(getReportsByParams).toHaveBeenCalledTimes(2); + done(); + }); + }); + + it('getAllReportsByParams(): should get all reports single page', (done) => { + const getReportsByParams = spyOn(approverReportsService, 'getReportsByParams'); + spyOn(approverReportsService, 'getReportsCount').and.returnValue(of(1)); + + const expectedParams: ReportsQueryParams = { + ...mockQueryParams, + offset: 0, + limit: 2, + }; + + getReportsByParams.withArgs(expectedParams).and.returnValue(of(allReportsPaginated1)); + + approverReportsService.getAllReportsByParams(mockQueryParams).subscribe((res) => { + expect(res).toEqual(expectedReportsSinglePage); + expect(approverReportsService.getReportsCount).toHaveBeenCalledOnceWith(mockQueryParams); + expect(getReportsByParams).toHaveBeenCalledOnceWith(expectedParams); + done(); + }); + }); + + it('should get reports with specified parameters', (done) => { + const queryParams = { + state: 'DRAFT', + offset: 0, + limit: 2, + }; + const expectedConfig = { + params: { + ...queryParams, + }, + }; + approverPlatformApiService.get.and.returnValue(of(allReportsPaginated1)); + approverReportsService.getReportsByParams(queryParams).subscribe((response) => { + expect(response).toEqual(allReportsPaginated1); + expect(approverPlatformApiService.get).toHaveBeenCalledOnceWith('/reports', expectedConfig); + done(); + }); + }); + + it('getReport(): should get a report by id', () => { + spyOn(approverReportsService, 'getReportsByParams').and.returnValue(of(allReportsPaginated1)); + const queryParams = { + id: 'eq.rpvcIMRMyM3A', + }; + approverReportsService.getReport('rpvcIMRMyM3A').subscribe((res) => { + console.log(res); + expect(approverReportsService.getReportsByParams).toHaveBeenCalledOnceWith(queryParams); + }); + }); + + it('getReportsStats(): should get advance request stats', (done) => { + const statsResponse = { + count: 2, + total_amount: 1200, + }; + approverPlatformApiService.post.and.returnValue(of({ data: statsResponse })); + + const params = { + state: 'eq.DRAFT', + }; + + approverReportsService.getReportsStats(params).subscribe((res) => { + expect(res).toEqual(statsResponse); + expect(approverPlatformApiService.post).toHaveBeenCalledOnceWith('/reports/stats', { + data: { + query_params: `state=${params.state}`, + }, + }); + done(); + }); + }); }); diff --git a/src/app/core/services/platform/v1/approver/reports.service.ts b/src/app/core/services/platform/v1/approver/reports.service.ts index c2069bd716..1f5aecc30d 100644 --- a/src/app/core/services/platform/v1/approver/reports.service.ts +++ b/src/app/core/services/platform/v1/approver/reports.service.ts @@ -5,6 +5,8 @@ import { PlatformApiResponse } from 'src/app/core/models/platform/platform-api-r import { ReportsQueryParams } from 'src/app/core/models/platform/v1/reports-query-params.model'; import { PAGINATION_SIZE } from 'src/app/constants'; import { Report } from 'src/app/core/models/platform/v1/report.model'; +import { PlatformStatsRequestParams } from 'src/app/core/models/platform/v1/platform-stats-requesst-param.model'; +import { StatsResponse } from 'src/app/core/models/v2/stats-response.model'; @Injectable({ providedIn: 'root', @@ -61,4 +63,18 @@ export class ApproverReportsService { }; return this.approverPlatformApiService.post('/reports/eject_expenses', payload); } + + getReport(id: string): Observable { + return this.getReportsByParams({ id: `eq.${id}` }).pipe(map((res) => res.data[0])); + } + + getReportsStats(params: PlatformStatsRequestParams): Observable { + return this.approverPlatformApiService + .post<{ data: StatsResponse }>('/reports/stats', { + data: { + query_params: `state=${params.state}`, + }, + }) + .pipe(map((res) => res.data)); + } } From 1705f10c8f53ff0c610304e9957971d4454125f6 Mon Sep 17 00:00:00 2001 From: aastha Date: Fri, 26 Apr 2024 17:36:01 +0530 Subject: [PATCH 28/46] Minor --- .../platform/v1/approver/reports.service.ts | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/app/core/services/platform/v1/approver/reports.service.ts b/src/app/core/services/platform/v1/approver/reports.service.ts index 515e110dc1..f6707cdbfe 100644 --- a/src/app/core/services/platform/v1/approver/reports.service.ts +++ b/src/app/core/services/platform/v1/approver/reports.service.ts @@ -77,18 +77,4 @@ export class ApproverReportsService { }; return this.approverPlatformApiService.post('/reports/eject_expenses', payload); } - - getReport(id: string): Observable { - return this.getReportsByParams({ id: `eq.${id}` }).pipe(map((res) => res.data[0])); - } - - getReportsStats(params: PlatformStatsRequestParams): Observable { - return this.approverPlatformApiService - .post<{ data: StatsResponse }>('/reports/stats', { - data: { - query_params: `state=${params.state}`, - }, - }) - .pipe(map((res) => res.data)); - } } From d6614f4118f0c20b225891e93ff11b23cb8ce157 Mon Sep 17 00:00:00 2001 From: aastha Date: Fri, 26 Apr 2024 18:16:21 +0530 Subject: [PATCH 29/46] Minor --- .../core/services/platform/v1/approver/reports.service.spec.ts | 1 + src/app/core/services/platform/v1/approver/reports.service.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/app/core/services/platform/v1/approver/reports.service.spec.ts b/src/app/core/services/platform/v1/approver/reports.service.spec.ts index e1cf142cbb..1e03b4b6da 100644 --- a/src/app/core/services/platform/v1/approver/reports.service.spec.ts +++ b/src/app/core/services/platform/v1/approver/reports.service.spec.ts @@ -9,6 +9,7 @@ import { expectedReportsPaginated, expectedReportsSinglePage, mockQueryParams, + platformReportCountData, } from 'src/app/core/mock-data/platform-report.data'; import { ReportsQueryParams } from 'src/app/core/models/platform/v1/reports-query-params.model'; diff --git a/src/app/core/services/platform/v1/approver/reports.service.ts b/src/app/core/services/platform/v1/approver/reports.service.ts index f6707cdbfe..e8b49f90ce 100644 --- a/src/app/core/services/platform/v1/approver/reports.service.ts +++ b/src/app/core/services/platform/v1/approver/reports.service.ts @@ -5,7 +5,7 @@ import { PlatformApiResponse } from 'src/app/core/models/platform/platform-api-r import { ReportsQueryParams } from 'src/app/core/models/platform/v1/reports-query-params.model'; import { PAGINATION_SIZE } from 'src/app/constants'; import { Report } from 'src/app/core/models/platform/v1/report.model'; -import { PlatformStatsRequestParams } from 'src/app/core/models/platform/v1/platform-stats-requesst-param.model'; +import { PlatformStatsRequestParams } from 'src/app/core/models/platform/v1/platform-stats-request-param.model'; import { StatsResponse } from 'src/app/core/models/v2/stats-response.model'; @Injectable({ From 70482e58012dde64492bf15794904a8b82e76515 Mon Sep 17 00:00:00 2001 From: aastha Date: Mon, 29 Apr 2024 09:40:36 +0530 Subject: [PATCH 30/46] Minor --- .../platform/v1/approver/reports.service.spec.ts | 11 ++++++++--- .../services/platform/v1/approver/reports.service.ts | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/app/core/services/platform/v1/approver/reports.service.spec.ts b/src/app/core/services/platform/v1/approver/reports.service.spec.ts index 1e03b4b6da..fb47e70c57 100644 --- a/src/app/core/services/platform/v1/approver/reports.service.spec.ts +++ b/src/app/core/services/platform/v1/approver/reports.service.spec.ts @@ -12,20 +12,25 @@ import { platformReportCountData, } from 'src/app/core/mock-data/platform-report.data'; import { ReportsQueryParams } from 'src/app/core/models/platform/v1/reports-query-params.model'; +import { StatsResponse } from 'src/app/core/models/platform/v1/stats-response.model'; describe('ApproverReportsService', () => { let approverReportsService: ApproverReportsService; - const approverPlatformApiService = jasmine.createSpyObj('ApproverPlatformApiService', ['post']); + let approverPlatformApiService: jasmine.SpyObj; beforeEach(() => { + const approverPlatformApiServiceSpy = jasmine.createSpyObj('ApproverPlatformApiService', ['post', 'get']); TestBed.configureTestingModule({ providers: [ ApproverReportsService, { provide: PAGINATION_SIZE, useValue: 2 }, - { provide: ApproverPlatformApiService, useValue: approverPlatformApiService }, + { provide: ApproverPlatformApiService, useValue: approverPlatformApiServiceSpy }, ], }); approverReportsService = TestBed.inject(ApproverReportsService); + approverPlatformApiService = TestBed.inject( + ApproverPlatformApiService + ) as jasmine.SpyObj; }); it('should be created', () => { @@ -150,7 +155,7 @@ describe('ApproverReportsService', () => { }); it('getReportsStats(): should get advance request stats', (done) => { - const statsResponse = { + const statsResponse: StatsResponse = { count: 2, total_amount: 1200, }; diff --git a/src/app/core/services/platform/v1/approver/reports.service.ts b/src/app/core/services/platform/v1/approver/reports.service.ts index e8b49f90ce..0905bd1171 100644 --- a/src/app/core/services/platform/v1/approver/reports.service.ts +++ b/src/app/core/services/platform/v1/approver/reports.service.ts @@ -6,7 +6,7 @@ import { ReportsQueryParams } from 'src/app/core/models/platform/v1/reports-quer import { PAGINATION_SIZE } from 'src/app/constants'; import { Report } from 'src/app/core/models/platform/v1/report.model'; import { PlatformStatsRequestParams } from 'src/app/core/models/platform/v1/platform-stats-request-param.model'; -import { StatsResponse } from 'src/app/core/models/v2/stats-response.model'; +import { StatsResponse } from 'src/app/core/models/platform/v1/stats-response.model'; @Injectable({ providedIn: 'root', From c7a604f2ba6bbe8aa150ff5a01c27ed6bce7d521 Mon Sep 17 00:00:00 2001 From: aastha Date: Mon, 29 Apr 2024 10:02:20 +0530 Subject: [PATCH 31/46] Minor --- src/app/core/models/report-stats.model.ts | 12 +++---- src/app/fyle/dashboard/dashboard.service.ts | 37 ++++++++++++++++----- 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/src/app/core/models/report-stats.model.ts b/src/app/core/models/report-stats.model.ts index 1c07bb4a7f..81c0285fb6 100644 --- a/src/app/core/models/report-stats.model.ts +++ b/src/app/core/models/report-stats.model.ts @@ -1,9 +1,9 @@ -import { Stats } from './stats.model'; +import { StatsResponse } from './platform/v1/stats-response.model'; export interface ReportStats { - draft: Stats; - report: Stats; - approved: Stats; - paymentPending: Stats; - processing: Stats; + draft: StatsResponse; + report: StatsResponse; + approved: StatsResponse; + paymentPending: StatsResponse; + processing: StatsResponse; } diff --git a/src/app/fyle/dashboard/dashboard.service.ts b/src/app/fyle/dashboard/dashboard.service.ts index e36e9cdc5c..d7e0bfa9c6 100644 --- a/src/app/fyle/dashboard/dashboard.service.ts +++ b/src/app/fyle/dashboard/dashboard.service.ts @@ -1,5 +1,5 @@ import { Injectable } from '@angular/core'; -import { Observable } from 'rxjs'; +import { Observable, forkJoin } from 'rxjs'; import { map } from 'rxjs/operators'; import { CCCDetails } from 'src/app/core/models/ccc-expense-details.model'; import { ReportStats } from 'src/app/core/models/report-stats.model'; @@ -8,13 +8,17 @@ import { ExpensesService } from 'src/app/core/services/platform/v1/spender/expen import { Stats } from '../../core/models/stats.model'; import { StatsResponse } from '../../core/models/v2/stats-response.model'; import { ReportService } from '../../core/services/report.service'; +import { SpenderReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; +import { report } from 'process'; +import { approversData1 } from 'src/app/core/mock-data/approver.data'; @Injectable() export class DashboardService { constructor( private reportService: ReportService, private corporateCreditCardExpenseService: CorporateCreditCardExpenseService, - private expensesService: ExpensesService + private expensesService: ExpensesService, + private spenderReportsService: SpenderReportsService ) {} getUnreportedExpensesStats(): Observable { @@ -47,13 +51,28 @@ export class DashboardService { } getReportsStats(): Observable { - return this.reportService - .getReportStats({ - scalar: false, - dimension_1_1: 'rp_state', - aggregates: 'sum(rp_amount),count(rp_id)', - }) - .pipe(map((statsResponse) => this.getReportAggregates(statsResponse))); + const draftStats = this.spenderReportsService.getReportsStats({ + state: 'eq.DRAFT', + }); + const reportedStats = this.spenderReportsService.getReportsStats({ + state: 'eq.APPROVER_PENDING', + }); + const approvedStats = this.spenderReportsService.getReportsStats({ + state: 'eq.APPROVED', + }); + const paymentPendingStats = this.spenderReportsService.getReportsStats({ + state: 'eq.DRAFT', + }); + const draftStats = this.spenderReportsService.getReportsStats({ + state: 'eq.DRAFT', + }); + const reportStatsObservable$ = forkJoin([]); + draft; + report; + approvers; + paymentPending; + paymentProcessing; + return reportStatsObservable$; } getReportAggregates(reportsStatsResponse: StatsResponse): ReportStats { From c11842b463c8412a46ddc8752e08c1079c3de87f Mon Sep 17 00:00:00 2001 From: aastha Date: Mon, 29 Apr 2024 10:27:01 +0530 Subject: [PATCH 32/46] Minor --- src/app/core/mock-data/report-stats.data.ts | 70 ++++++++++++++++--- .../v1/report-stats-response.model.ts | 9 +++ src/app/core/models/report-stats.model.ts | 11 +-- .../platform/v1/approver/reports.service.ts | 5 +- .../platform/v1/spender/reports.service.ts | 5 +- src/app/fyle/dashboard/dashboard.service.ts | 62 +++------------- .../fyle/dashboard/stats/stats.component.html | 10 +-- .../fyle/dashboard/stats/stats.component.ts | 10 +-- 8 files changed, 102 insertions(+), 80 deletions(-) create mode 100644 src/app/core/models/platform/v1/report-stats-response.model.ts diff --git a/src/app/core/mock-data/report-stats.data.ts b/src/app/core/mock-data/report-stats.data.ts index fccb6d9720..89d6ade35a 100644 --- a/src/app/core/mock-data/report-stats.data.ts +++ b/src/app/core/mock-data/report-stats.data.ts @@ -3,45 +3,95 @@ import { ReportStats } from '../models/report-stats.model'; export const expectedReportStats: ReportStats = { draft: { count: 6, - sum: 93165.91, + failed_amount: null, + failed_count: null, + processing_amount: null, + processing_count: null, + reimbursable_amount: null, + total_amount: 93165.91, }, report: { count: 45, - sum: 5177243929.65219, + total_amount: 5177243929.65219, + failed_amount: null, + failed_count: null, + processing_amount: null, + processing_count: null, + reimbursable_amount: null, }, approved: { count: 56, - sum: 28758273650702.816, + total_amount: 28758273650702.816, + failed_amount: null, + failed_count: null, + processing_amount: null, + processing_count: null, + reimbursable_amount: null, }, paymentPending: { count: 4, - sum: 501602.12, + total_amount: 501602.12, + failed_amount: null, + failed_count: null, + processing_amount: null, + processing_count: null, + reimbursable_amount: null, }, processing: { count: 7, - sum: 5012.12, + total_amount: 5012.12, + failed_amount: null, + failed_count: null, + processing_amount: null, + processing_count: null, + reimbursable_amount: null, }, }; export const expectedEmptyReportStats: ReportStats = { draft: { - sum: 0, + total_amount: 0, count: 0, + failed_amount: null, + failed_count: null, + processing_amount: null, + processing_count: null, + reimbursable_amount: null, }, report: { - sum: 0, + total_amount: 0, count: 0, + failed_amount: null, + failed_count: null, + processing_amount: null, + processing_count: null, + reimbursable_amount: null, }, approved: { - sum: 0, + total_amount: 0, count: 0, + failed_amount: null, + failed_count: null, + processing_amount: null, + processing_count: null, + reimbursable_amount: null, }, paymentPending: { - sum: 0, + total_amount: 0, count: 0, + failed_amount: null, + failed_count: null, + processing_amount: null, + processing_count: null, + reimbursable_amount: null, }, processing: { - sum: 0, + total_amount: 0, count: 0, + failed_amount: null, + failed_count: null, + processing_amount: null, + processing_count: null, + reimbursable_amount: null, }, }; diff --git a/src/app/core/models/platform/v1/report-stats-response.model.ts b/src/app/core/models/platform/v1/report-stats-response.model.ts new file mode 100644 index 0000000000..2648c910cd --- /dev/null +++ b/src/app/core/models/platform/v1/report-stats-response.model.ts @@ -0,0 +1,9 @@ +export interface ReportsStatsResponsePlatform { + count: number; + failed_amount: number; + failed_count: number; + processing_amount: number; + processing_count: number; + reimbursable_amount: number; + total_amount: number; +} diff --git a/src/app/core/models/report-stats.model.ts b/src/app/core/models/report-stats.model.ts index 81c0285fb6..5aac064b5e 100644 --- a/src/app/core/models/report-stats.model.ts +++ b/src/app/core/models/report-stats.model.ts @@ -1,9 +1,10 @@ +import { ReportsStatsResponsePlatform } from './platform/v1/report-stats-response.model'; import { StatsResponse } from './platform/v1/stats-response.model'; export interface ReportStats { - draft: StatsResponse; - report: StatsResponse; - approved: StatsResponse; - paymentPending: StatsResponse; - processing: StatsResponse; + draft: ReportsStatsResponsePlatform; + report: ReportsStatsResponsePlatform; + approved: ReportsStatsResponsePlatform; + paymentPending: ReportsStatsResponsePlatform; + processing: ReportsStatsResponsePlatform; } diff --git a/src/app/core/services/platform/v1/approver/reports.service.ts b/src/app/core/services/platform/v1/approver/reports.service.ts index 0905bd1171..b7c5e74fa4 100644 --- a/src/app/core/services/platform/v1/approver/reports.service.ts +++ b/src/app/core/services/platform/v1/approver/reports.service.ts @@ -7,6 +7,7 @@ import { PAGINATION_SIZE } from 'src/app/constants'; import { Report } from 'src/app/core/models/platform/v1/report.model'; import { PlatformStatsRequestParams } from 'src/app/core/models/platform/v1/platform-stats-request-param.model'; import { StatsResponse } from 'src/app/core/models/platform/v1/stats-response.model'; +import { ReportsStatsResponsePlatform } from 'src/app/core/models/platform/v1/report-stats-response.model'; @Injectable({ providedIn: 'root', @@ -53,9 +54,9 @@ export class ApproverReportsService { return this.approverPlatformApiService.get>('/reports', config); } - getReportsStats(params: PlatformStatsRequestParams): Observable { + getReportsStats(params: PlatformStatsRequestParams): Observable { return this.approverPlatformApiService - .post<{ data: StatsResponse }>('/reports/stats', { + .post<{ data: ReportsStatsResponsePlatform }>('/reports/stats', { data: { query_params: `state=${params.state}`, }, diff --git a/src/app/core/services/platform/v1/spender/reports.service.ts b/src/app/core/services/platform/v1/spender/reports.service.ts index e4f1b2d58d..b97969cf83 100644 --- a/src/app/core/services/platform/v1/spender/reports.service.ts +++ b/src/app/core/services/platform/v1/spender/reports.service.ts @@ -10,6 +10,7 @@ import { CreateDraftParams } from 'src/app/core/models/platform/v1/create-draft- import { PlatformApiPayload } from 'src/app/core/models/platform/platform-api-payload.model'; import { StatsResponse } from 'src/app/core/models/platform/v1/stats-response.model'; import { PlatformStatsRequestParams } from 'src/app/core/models/platform/v1/platform-stats-request-param.model'; +import { ReportsStatsResponsePlatform } from 'src/app/core/models/platform/v1/report-stats-response.model'; @Injectable({ providedIn: 'root', @@ -85,9 +86,9 @@ export class SpenderReportsService { return this.spenderPlatformV1ApiService.post('/reports/eject_expenses', payload); } - getReportsStats(params: PlatformStatsRequestParams): Observable { + getReportsStats(params: PlatformStatsRequestParams): Observable { return this.spenderPlatformV1ApiService - .post<{ data: StatsResponse }>('/reports/stats', { + .post<{ data: ReportsStatsResponsePlatform }>('/reports/stats', { data: { query_params: `state=${params.state}`, }, diff --git a/src/app/fyle/dashboard/dashboard.service.ts b/src/app/fyle/dashboard/dashboard.service.ts index d7e0bfa9c6..cd3846016d 100644 --- a/src/app/fyle/dashboard/dashboard.service.ts +++ b/src/app/fyle/dashboard/dashboard.service.ts @@ -9,8 +9,6 @@ import { Stats } from '../../core/models/stats.model'; import { StatsResponse } from '../../core/models/v2/stats-response.model'; import { ReportService } from '../../core/services/report.service'; import { SpenderReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; -import { report } from 'process'; -import { approversData1 } from 'src/app/core/mock-data/approver.data'; @Injectable() export class DashboardService { @@ -61,61 +59,21 @@ export class DashboardService { state: 'eq.APPROVED', }); const paymentPendingStats = this.spenderReportsService.getReportsStats({ - state: 'eq.DRAFT', + state: 'eq.PAYMENT_PENDING', }); - const draftStats = this.spenderReportsService.getReportsStats({ - state: 'eq.DRAFT', + const paymentProcessingStats = this.spenderReportsService.getReportsStats({ + state: 'eq.PAYMENT_PROCESSING', + }); + const reportStatsObservable$ = forkJoin({ + draft: draftStats, + report: reportedStats, + approved: approvedStats, + paymentPending: paymentPendingStats, + processing: paymentProcessingStats, }); - const reportStatsObservable$ = forkJoin([]); - draft; - report; - approvers; - paymentPending; - paymentProcessing; return reportStatsObservable$; } - getReportAggregates(reportsStatsResponse: StatsResponse): ReportStats { - const reportDatum = reportsStatsResponse.getDatum(0); - const reportAggregateValues = reportDatum.value; - const stateWiseAggregatesMap = reportAggregateValues - .map((reportAggregateValue) => { - const key = reportAggregateValue.key[0].column_value; - const countAggregate = reportAggregateValue.aggregates.find( - (aggregate) => aggregate.function_name === 'count(rp_id)' - ); - const sumAggregate = reportAggregateValue.aggregates.find( - (aggregate) => aggregate.function_name === 'sum(rp_amount)' - ); - return { - key, - count: countAggregate && countAggregate.function_value, - sum: sumAggregate && sumAggregate.function_value, - }; - }) - .reduce((acc, curr) => { - acc[curr.key] = { - count: curr.count, - sum: curr.sum, - }; - return acc; - }, {} as { [key: string]: { count: number; sum: number } }); - - const draftReportStats = stateWiseAggregatesMap.DRAFT || { sum: 0, count: 0 }; - const reportedReportStats = stateWiseAggregatesMap.APPROVER_PENDING || { sum: 0, count: 0 }; - const approvedReportStats = stateWiseAggregatesMap.APPROVED || { sum: 0, count: 0 }; - const paymentPendingReportStats = stateWiseAggregatesMap.PAYMENT_PENDING || { sum: 0, count: 0 }; - const processingReportStats = stateWiseAggregatesMap.PAYMENT_PROCESSING || { sum: 0, count: 0 }; - - return { - draft: draftReportStats, - report: reportedReportStats, - approved: approvedReportStats, - paymentPending: paymentPendingReportStats, - processing: processingReportStats, - }; - } - getCCCDetails(): Observable { return this.corporateCreditCardExpenseService.getAssignedCards(); } diff --git a/src/app/fyle/dashboard/stats/stats.component.html b/src/app/fyle/dashboard/stats/stats.component.html index 837864ffa1..40220b269a 100644 --- a/src/app/fyle/dashboard/stats/stats.component.html +++ b/src/app/fyle/dashboard/stats/stats.component.html @@ -15,7 +15,7 @@ [name]="'Draft'" [reportState]="ReportStates.DRAFT" [count]="reportStatsData.reportStats?.draft?.count" - [value]="reportStatsData.reportStats?.draft?.sum" + [value]="reportStatsData.reportStats?.draft?.total_amount" (badgeClicked)="goToReportsPage($event)" > @@ -26,7 +26,7 @@ [name]="reportStatsData.simplifyReportsSettings.enabled ? 'Submitted' : 'Reported'" [reportState]="ReportStates.APPROVER_PENDING" [count]="reportStatsData.reportStats?.report?.count" - [value]="reportStatsData.reportStats?.report?.sum" + [value]="reportStatsData.reportStats?.report?.total_amount" (badgeClicked)="goToReportsPage($event)" > @@ -42,7 +42,7 @@ [name]="'Approved'" [reportState]="ReportStates.APPROVED" [count]="reportStatsData.reportStats?.approved?.count" - [value]="reportStatsData.reportStats?.approved?.sum" + [value]="reportStatsData.reportStats?.approved?.total_amount" (badgeClicked)="goToReportsPage($event)" > @@ -57,7 +57,7 @@ [name]="'Processing'" [reportState]="ReportStates.PAYMENT_PROCESSING" [count]="reportStatsData.reportStats?.processing?.count" - [value]="reportStatsData.reportStats?.processing?.sum" + [value]="reportStatsData.reportStats?.processing?.total_amount" (badgeClicked)="goToReportsPage($event)" > @@ -68,7 +68,7 @@ [name]="'Payment Pending'" [reportState]="ReportStates.PAYMENT_PENDING" [count]="reportStatsData.reportStats?.paymentPending?.count" - [value]="reportStatsData.reportStats?.paymentPending?.sum" + [value]="reportStatsData.reportStats?.paymentPending?.total_amount" (badgeClicked)="goToReportsPage($event)" > diff --git a/src/app/fyle/dashboard/stats/stats.component.ts b/src/app/fyle/dashboard/stats/stats.component.ts index 47db5fe852..ff86ee6f21 100644 --- a/src/app/fyle/dashboard/stats/stats.component.ts +++ b/src/app/fyle/dashboard/stats/stats.component.ts @@ -15,6 +15,8 @@ import { OrgSettingsService } from 'src/app/core/services/org-settings.service'; import { OrgService } from 'src/app/core/services/org.service'; import { PaymentModesService } from 'src/app/core/services/payment-modes.service'; import { ReportStatsData } from 'src/app/core/models/report-stats-data.model'; +import { StatsResponse } from 'src/app/core/models/platform/v1/stats-response.model'; +import { ReportsStatsResponsePlatform } from 'src/app/core/models/platform/v1/report-stats-response.model'; @Component({ selector: 'app-stats', @@ -22,13 +24,13 @@ import { ReportStatsData } from 'src/app/core/models/report-stats-data.model'; styleUrls: ['./stats.component.scss'], }) export class StatsComponent implements OnInit { - draftStats$: Observable<{ count: number; sum: number }>; + draftStats$: Observable; - approvedStats$: Observable<{ count: number; sum: number }>; + approvedStats$: Observable; - paymentPendingStats$: Observable<{ count: number; sum: number }>; + paymentPendingStats$: Observable; - processingStats$: Observable<{ count: number; sum: number }>; + processingStats$: Observable; homeCurrency$: Observable; From f8ed65d20f379d13b9bd723767ecc393964d601d Mon Sep 17 00:00:00 2001 From: aastha Date: Mon, 29 Apr 2024 13:08:41 +0530 Subject: [PATCH 33/46] Minor --- .../v1/approver/reports.service.spec.ts | 5 +- .../v1/spender/reports.service.spec.ts | 5 +- .../fyle/dashboard/dashboard.service.spec.ts | 81 +++++++++++++------ src/app/fyle/dashboard/dashboard.service.ts | 8 +- 4 files changed, 69 insertions(+), 30 deletions(-) diff --git a/src/app/core/services/platform/v1/approver/reports.service.spec.ts b/src/app/core/services/platform/v1/approver/reports.service.spec.ts index fb47e70c57..95ef9c5bc4 100644 --- a/src/app/core/services/platform/v1/approver/reports.service.spec.ts +++ b/src/app/core/services/platform/v1/approver/reports.service.spec.ts @@ -13,6 +13,7 @@ import { } from 'src/app/core/mock-data/platform-report.data'; import { ReportsQueryParams } from 'src/app/core/models/platform/v1/reports-query-params.model'; import { StatsResponse } from 'src/app/core/models/platform/v1/stats-response.model'; +import { expectedReportStats } from 'src/app/core/mock-data/report-stats.data'; describe('ApproverReportsService', () => { let approverReportsService: ApproverReportsService; @@ -159,14 +160,14 @@ describe('ApproverReportsService', () => { count: 2, total_amount: 1200, }; - approverPlatformApiService.post.and.returnValue(of({ data: statsResponse })); + approverPlatformApiService.post.and.returnValue(of({ data: expectedReportStats.draft })); const params = { state: 'eq.DRAFT', }; approverReportsService.getReportsStats(params).subscribe((res) => { - expect(res).toEqual(statsResponse); + expect(res).toEqual(expectedReportStats.draft); expect(approverPlatformApiService.post).toHaveBeenCalledOnceWith('/reports/stats', { data: { query_params: `state=${params.state}`, diff --git a/src/app/core/services/platform/v1/spender/reports.service.spec.ts b/src/app/core/services/platform/v1/spender/reports.service.spec.ts index 2a41ed0354..6d1a8044c4 100644 --- a/src/app/core/services/platform/v1/spender/reports.service.spec.ts +++ b/src/app/core/services/platform/v1/spender/reports.service.spec.ts @@ -12,6 +12,7 @@ import { mockQueryParams, } from 'src/app/core/mock-data/platform-report.data'; import { ReportsQueryParams } from 'src/app/core/models/platform/v1/reports-query-params.model'; +import { expectedReportStats } from 'src/app/core/mock-data/report-stats.data'; describe('SpenderReportsService', () => { let spenderReportsService: SpenderReportsService; @@ -157,14 +158,14 @@ describe('SpenderReportsService', () => { count: 2, total_amount: 1200, }; - spenderPlatformV1ApiService.post.and.returnValue(of({ data: statsResponse })); + spenderPlatformV1ApiService.post.and.returnValue(of({ data: expectedReportStats.draft })); const params = { state: 'eq.DRAFT', }; spenderReportsService.getReportsStats(params).subscribe((res) => { - expect(res).toEqual(statsResponse); + expect(res).toEqual(expectedReportStats.draft); expect(spenderPlatformV1ApiService.post).toHaveBeenCalledOnceWith('/reports/stats', { data: { query_params: `state=${params.state}`, diff --git a/src/app/fyle/dashboard/dashboard.service.spec.ts b/src/app/fyle/dashboard/dashboard.service.spec.ts index d26b7dc7f3..b874433ac8 100644 --- a/src/app/fyle/dashboard/dashboard.service.spec.ts +++ b/src/app/fyle/dashboard/dashboard.service.spec.ts @@ -11,45 +11,32 @@ import { ExpensesService } from 'src/app/core/services/platform/v1/spender/expen import { ReportService } from 'src/app/core/services/report.service'; import { expectedAssignedCCCStats } from '../../core/mock-data/ccc-expense.details.data'; import { expectedEmptyReportStats, expectedReportStats } from '../../core/mock-data/report-stats.data'; -import { - apiAssignedCardDetailsRes, - apiReportStatsEmptyRes, - apiReportStatsRes, -} from '../../core/mock-data/stats-response.data'; +import { apiAssignedCardDetailsRes } from '../../core/mock-data/stats-response.data'; import { emptyStatsAgg, expectedIncompleteExpStats2, expectedUnreportedExpStats2, } from '../../core/mock-data/stats.data'; import { DashboardService } from './dashboard.service'; +import { SpenderReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; -describe('DashboardService', () => { +fdescribe('DashboardService', () => { let dashboardService: DashboardService; - let reportService: jasmine.SpyObj; let expensesService: jasmine.SpyObj; let authService: jasmine.SpyObj; let apiV2Service: jasmine.SpyObj; - - const apiReportStatParams: Partial = { - scalar: false, - dimension_1_1: 'rp_state', - aggregates: 'sum(rp_amount),count(rp_id)', - }; + let spenderReportsService: jasmine.SpyObj; beforeEach(() => { - const reportServiceSpy = jasmine.createSpyObj('ReportService', ['getReportStats']); const expensesServiceSpy = jasmine.createSpyObj('ExpensesService', ['getExpenseStats']); const authServiceSpy = jasmine.createSpyObj('AuthService', ['getEou']); const apiV2ServiceSpy = jasmine.createSpyObj('ApiV2Service', ['get', 'getStats']); + const spenderReportsServiceSpy = jasmine.createSpyObj('SpenderReportsService', ['getReportsStats']); TestBed.configureTestingModule({ imports: [HttpClientTestingModule], providers: [ DashboardService, CorporateCreditCardExpenseService, - { - provide: ReportService, - useValue: reportServiceSpy, - }, { provide: AuthService, useValue: authServiceSpy, @@ -62,13 +49,17 @@ describe('DashboardService', () => { provide: ExpensesService, useValue: expensesServiceSpy, }, + { + provide: SpenderReportsService, + useValue: spenderReportsServiceSpy, + }, ], }); dashboardService = TestBed.inject(DashboardService); - reportService = TestBed.inject(ReportService) as jasmine.SpyObj; expensesService = TestBed.inject(ExpensesService) as jasmine.SpyObj; authService = TestBed.inject(AuthService) as jasmine.SpyObj; apiV2Service = TestBed.inject(ApiV2Service) as jasmine.SpyObj; + spenderReportsService = TestBed.inject(SpenderReportsService) as jasmine.SpyObj; }); it('should be created', () => { @@ -130,23 +121,63 @@ describe('DashboardService', () => { }); it('getReportStats(): should get Report stats', (done) => { - reportService.getReportStats.and.returnValue(of(new StatsResponse(apiReportStatsRes))); + spenderReportsService.getReportsStats.and.returnValues( + of(expectedReportStats.draft), + of(expectedReportStats.report), + of(expectedReportStats.approved), + of(expectedReportStats.paymentPending), + of(expectedReportStats.processing) + ); dashboardService.getReportsStats().subscribe((res) => { expect(res).toEqual(expectedReportStats); - expect(reportService.getReportStats).toHaveBeenCalledTimes(1); - expect(reportService.getReportStats).toHaveBeenCalledWith(apiReportStatParams); + expect(spenderReportsService.getReportsStats).toHaveBeenCalledTimes(5); + expect(spenderReportsService.getReportsStats).toHaveBeenCalledWith({ + state: 'eq.DRAFT', + }); + expect(spenderReportsService.getReportsStats).toHaveBeenCalledWith({ + state: 'eq.APPROVER_PENDING', + }); + expect(spenderReportsService.getReportsStats).toHaveBeenCalledWith({ + state: 'eq.APPROVED', + }); + expect(spenderReportsService.getReportsStats).toHaveBeenCalledWith({ + state: 'eq.PAYMENT_PENDING', + }); + expect(spenderReportsService.getReportsStats).toHaveBeenCalledWith({ + state: 'eq.PAYMENT_PROCESSING', + }); done(); }); }); it('getReportStats(): should return empty response as various report stats data is empty', (done) => { - reportService.getReportStats.and.returnValue(of(new StatsResponse(apiReportStatsEmptyRes))); + spenderReportsService.getReportsStats.and.returnValues( + of(expectedEmptyReportStats.draft), + of(expectedEmptyReportStats.report), + of(expectedEmptyReportStats.approved), + of(expectedEmptyReportStats.paymentPending), + of(expectedEmptyReportStats.processing) + ); dashboardService.getReportsStats().subscribe((res) => { expect(res).toEqual(expectedEmptyReportStats); - expect(reportService.getReportStats).toHaveBeenCalledTimes(1); - expect(reportService.getReportStats).toHaveBeenCalledWith(apiReportStatParams); + expect(spenderReportsService.getReportsStats).toHaveBeenCalledTimes(5); + expect(spenderReportsService.getReportsStats).toHaveBeenCalledWith({ + state: 'eq.DRAFT', + }); + expect(spenderReportsService.getReportsStats).toHaveBeenCalledWith({ + state: 'eq.APPROVER_PENDING', + }); + expect(spenderReportsService.getReportsStats).toHaveBeenCalledWith({ + state: 'eq.APPROVED', + }); + expect(spenderReportsService.getReportsStats).toHaveBeenCalledWith({ + state: 'eq.PAYMENT_PENDING', + }); + expect(spenderReportsService.getReportsStats).toHaveBeenCalledWith({ + state: 'eq.PAYMENT_PROCESSING', + }); done(); }); }); diff --git a/src/app/fyle/dashboard/dashboard.service.ts b/src/app/fyle/dashboard/dashboard.service.ts index cd3846016d..5183c5c255 100644 --- a/src/app/fyle/dashboard/dashboard.service.ts +++ b/src/app/fyle/dashboard/dashboard.service.ts @@ -9,11 +9,11 @@ import { Stats } from '../../core/models/stats.model'; import { StatsResponse } from '../../core/models/v2/stats-response.model'; import { ReportService } from '../../core/services/report.service'; import { SpenderReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; +import { ReportsStatsResponsePlatform } from 'src/app/core/models/platform/v1/report-stats-response.model'; @Injectable() export class DashboardService { constructor( - private reportService: ReportService, private corporateCreditCardExpenseService: CorporateCreditCardExpenseService, private expensesService: ExpensesService, private spenderReportsService: SpenderReportsService @@ -48,6 +48,12 @@ export class DashboardService { ); } + getSpenderReportsStats(): Observable { + return this.spenderReportsService.getReportsStats({ + state: 'eq.DRAFT', + }); + } + getReportsStats(): Observable { const draftStats = this.spenderReportsService.getReportsStats({ state: 'eq.DRAFT', From ce1ea5d63fdc5f7380d4eaa2c5620f3a8fefd710 Mon Sep 17 00:00:00 2001 From: aastha Date: Mon, 29 Apr 2024 13:10:46 +0530 Subject: [PATCH 34/46] Minor --- src/app/core/services/report.service.spec.ts | 14 -------------- src/app/core/services/report.service.ts | 14 -------------- src/app/fyle/dashboard/dashboard.service.spec.ts | 4 ++-- 3 files changed, 2 insertions(+), 30 deletions(-) diff --git a/src/app/core/services/report.service.spec.ts b/src/app/core/services/report.service.spec.ts index a6960cd6fc..231fa4932d 100644 --- a/src/app/core/services/report.service.spec.ts +++ b/src/app/core/services/report.service.spec.ts @@ -1099,18 +1099,4 @@ describe('ReportService', () => { }); }); }); - - it('getReportStats(): should get report stats', (done) => { - authService.getEou.and.returnValue(Promise.resolve(apiEouRes)); - apiv2Service.get.and.returnValue(of(new StatsResponse(apiReportStatsRes))); - - reportService.getReportStats(apiReportStatParams).subscribe((res) => { - expect(res).toEqual(new StatsResponse(apiReportStatsRes)); - expect(apiv2Service.get).toHaveBeenCalledOnceWith('/reports/stats', { - params: { rp_org_user_id: `eq.ouX8dwsbLCLv`, ...apiReportStatParams }, - }); - expect(authService.getEou).toHaveBeenCalledTimes(1); - done(); - }); - }); }); diff --git a/src/app/core/services/report.service.ts b/src/app/core/services/report.service.ts index 3a598c402f..d052ed5c98 100644 --- a/src/app/core/services/report.service.ts +++ b/src/app/core/services/report.service.ts @@ -595,20 +595,6 @@ export class ReportService { ); } - getReportStats(params: Partial): Observable { - return from(this.authService.getEou()).pipe( - switchMap((eou) => - this.apiv2Service.get('/reports/stats', { - params: { - rp_org_user_id: `eq.${eou.ou.id}`, - ...params, - }, - }) - ), - map((rawStatsResponse: StatsResponse) => new StatsResponse(rawStatsResponse)) - ); - } - approverUpdateReportPurpose(erpt: ExtendedReport): Observable { const params: { data: Pick } = { data: { diff --git a/src/app/fyle/dashboard/dashboard.service.spec.ts b/src/app/fyle/dashboard/dashboard.service.spec.ts index b874433ac8..85b809868d 100644 --- a/src/app/fyle/dashboard/dashboard.service.spec.ts +++ b/src/app/fyle/dashboard/dashboard.service.spec.ts @@ -120,7 +120,7 @@ fdescribe('DashboardService', () => { }); }); - it('getReportStats(): should get Report stats', (done) => { + it('getReportsStats(): should get Report stats', (done) => { spenderReportsService.getReportsStats.and.returnValues( of(expectedReportStats.draft), of(expectedReportStats.report), @@ -151,7 +151,7 @@ fdescribe('DashboardService', () => { }); }); - it('getReportStats(): should return empty response as various report stats data is empty', (done) => { + it('getReportsStats(): should return empty response as various report stats data is empty', (done) => { spenderReportsService.getReportsStats.and.returnValues( of(expectedEmptyReportStats.draft), of(expectedEmptyReportStats.report), From d8e2708d398ea261938f28d469e60a12b1812d6c Mon Sep 17 00:00:00 2001 From: Aastha Bist Date: Mon, 29 Apr 2024 16:01:02 +0530 Subject: [PATCH 35/46] Update dashboard.service.spec.ts --- src/app/fyle/dashboard/dashboard.service.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/fyle/dashboard/dashboard.service.spec.ts b/src/app/fyle/dashboard/dashboard.service.spec.ts index 85b809868d..04f4e5045b 100644 --- a/src/app/fyle/dashboard/dashboard.service.spec.ts +++ b/src/app/fyle/dashboard/dashboard.service.spec.ts @@ -20,7 +20,7 @@ import { import { DashboardService } from './dashboard.service'; import { SpenderReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; -fdescribe('DashboardService', () => { +describe('DashboardService', () => { let dashboardService: DashboardService; let expensesService: jasmine.SpyObj; let authService: jasmine.SpyObj; From 210ba4446c7dc8fdc228aa9dc2ae6e414fd44963 Mon Sep 17 00:00:00 2001 From: Aastha Bist Date: Mon, 29 Apr 2024 16:32:57 +0530 Subject: [PATCH 36/46] Update dashboard.service.ts --- src/app/fyle/dashboard/dashboard.service.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/app/fyle/dashboard/dashboard.service.ts b/src/app/fyle/dashboard/dashboard.service.ts index 5183c5c255..38de4e679b 100644 --- a/src/app/fyle/dashboard/dashboard.service.ts +++ b/src/app/fyle/dashboard/dashboard.service.ts @@ -48,12 +48,6 @@ export class DashboardService { ); } - getSpenderReportsStats(): Observable { - return this.spenderReportsService.getReportsStats({ - state: 'eq.DRAFT', - }); - } - getReportsStats(): Observable { const draftStats = this.spenderReportsService.getReportsStats({ state: 'eq.DRAFT', From 7023bbf206f60a647964f8b75ac88d5d000f4a0b Mon Sep 17 00:00:00 2001 From: Aastha Bist Date: Tue, 7 May 2024 09:29:51 +0530 Subject: [PATCH 37/46] fix: fix platform spender reports test coverage (#2950) --- .../core/mock-data/platform-report.data.ts | 5 ++++ .../v1/approver/reports.service.spec.ts | 4 +++- .../v1/spender/reports.service.spec.ts | 23 ++++++++++++++++++- .../platform/v1/spender/reports.service.ts | 7 ------ 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/app/core/mock-data/platform-report.data.ts b/src/app/core/mock-data/platform-report.data.ts index cf3aae730a..3714c78737 100644 --- a/src/app/core/mock-data/platform-report.data.ts +++ b/src/app/core/mock-data/platform-report.data.ts @@ -4,6 +4,11 @@ import { PlatformApiResponse } from '../models/platform/platform-api-response.mo export const mockQueryParams: ReportsQueryParams = { state: 'in.(DRAFT,APPROVER_PENDING,APPROVER_INQUIRY)', + order: 'created_at.desc,id.desc', +}; + +export const mockQueryParamsForCount: ReportsQueryParams = { + state: 'in.(DRAFT,APPROVER_PENDING,APPROVER_INQUIRY)', }; export const platformReportData: Report = { diff --git a/src/app/core/services/platform/v1/approver/reports.service.spec.ts b/src/app/core/services/platform/v1/approver/reports.service.spec.ts index 95ef9c5bc4..2902ee0623 100644 --- a/src/app/core/services/platform/v1/approver/reports.service.spec.ts +++ b/src/app/core/services/platform/v1/approver/reports.service.spec.ts @@ -9,6 +9,7 @@ import { expectedReportsPaginated, expectedReportsSinglePage, mockQueryParams, + mockQueryParamsForCount, platformReportCountData, } from 'src/app/core/mock-data/platform-report.data'; import { ReportsQueryParams } from 'src/app/core/models/platform/v1/reports-query-params.model'; @@ -62,7 +63,7 @@ describe('ApproverReportsService', () => { spyOn(approverReportsService, 'getReportsByParams').and.returnValue(of(platformReportCountData)); const expectedParams: ReportsQueryParams = { - ...mockQueryParams, + ...mockQueryParamsForCount, limit: 1, offset: 0, }; @@ -97,6 +98,7 @@ describe('ApproverReportsService', () => { expect(res).toEqual(expectedReportsPaginated); expect(approverReportsService.getReportsCount).toHaveBeenCalledOnceWith({ state: 'in.(DRAFT,APPROVER_PENDING,APPROVER_INQUIRY)', + order: 'created_at.desc,id.desc', }); expect(getReportsByParams).toHaveBeenCalledWith(expectedParams1); expect(getReportsByParams).toHaveBeenCalledWith(expectedParams2); diff --git a/src/app/core/services/platform/v1/spender/reports.service.spec.ts b/src/app/core/services/platform/v1/spender/reports.service.spec.ts index 6d1a8044c4..566b641ede 100644 --- a/src/app/core/services/platform/v1/spender/reports.service.spec.ts +++ b/src/app/core/services/platform/v1/spender/reports.service.spec.ts @@ -10,6 +10,7 @@ import { platformReportCountData, expectedReportsSinglePage, mockQueryParams, + mockQueryParamsForCount, } from 'src/app/core/mock-data/platform-report.data'; import { ReportsQueryParams } from 'src/app/core/models/platform/v1/reports-query-params.model'; import { expectedReportStats } from 'src/app/core/mock-data/report-stats.data'; @@ -42,7 +43,7 @@ describe('SpenderReportsService', () => { spyOn(spenderReportsService, 'getReportsByParams').and.returnValue(of(platformReportCountData)); const expectedParams: ReportsQueryParams = { - ...mockQueryParams, + ...mockQueryParamsForCount, limit: 1, offset: 0, }; @@ -77,6 +78,7 @@ describe('SpenderReportsService', () => { expect(res).toEqual(expectedReportsPaginated); expect(spenderReportsService.getReportsCount).toHaveBeenCalledOnceWith({ state: 'in.(DRAFT,APPROVER_PENDING,APPROVER_INQUIRY)', + order: 'created_at.desc,id.desc', }); expect(getReportsByParams).toHaveBeenCalledWith(expectedParams1); expect(getReportsByParams).toHaveBeenCalledWith(expectedParams2); @@ -93,6 +95,7 @@ describe('SpenderReportsService', () => { ...mockQueryParams, offset: 0, limit: 2, + order: 'created_at.desc,id.desc', }; getReportsByParams.withArgs(expectedParams).and.returnValue(of(allReportsPaginated1)); @@ -110,6 +113,7 @@ describe('SpenderReportsService', () => { state: 'DRAFT', offset: 0, limit: 2, + order: 'created_at.desc,id.desc', }; const expectedConfig = { params: { @@ -193,4 +197,21 @@ describe('SpenderReportsService', () => { done(); }); }); + + it('createDraft(): should create a draft report and return the report', (done) => { + spenderPlatformV1ApiService.post.and.returnValue(of({ data: allReportsPaginated1.data[0] })); + + const reportParam = { + data: { + purpose: 'A draft Report', + source: 'MOBILE', + }, + }; + + spenderReportsService.createDraft(reportParam).subscribe((res) => { + expect(res).toEqual(allReportsPaginated1.data[0]); + expect(spenderPlatformV1ApiService.post).toHaveBeenCalledOnceWith('/reports', reportParam); + done(); + }); + }); }); diff --git a/src/app/core/services/platform/v1/spender/reports.service.ts b/src/app/core/services/platform/v1/spender/reports.service.ts index b97969cf83..3ae08c3169 100644 --- a/src/app/core/services/platform/v1/spender/reports.service.ts +++ b/src/app/core/services/platform/v1/spender/reports.service.ts @@ -34,13 +34,6 @@ export class SpenderReportsService { limit: this.paginationSize, }; - if (order) { - params = { - ...params, - order, - }; - } - return this.getReportsByParams(params); }), reduce((acc, curr) => acc.concat(curr.data), [] as Report[]) From a540c60b7d4debc62411c6b3196396906740c029 Mon Sep 17 00:00:00 2001 From: aastha Date: Tue, 7 May 2024 14:36:47 +0530 Subject: [PATCH 38/46] Minor --- src/app/core/models/report-stats.model.ts | 2 -- src/app/core/services/platform/v1/spender/reports.service.ts | 1 - src/app/core/services/report.service.ts | 2 +- src/app/fyle/dashboard/dashboard.service.spec.ts | 2 -- src/app/fyle/dashboard/dashboard.service.ts | 3 --- src/app/fyle/dashboard/stats/stats.component.ts | 1 - 6 files changed, 1 insertion(+), 10 deletions(-) diff --git a/src/app/core/models/report-stats.model.ts b/src/app/core/models/report-stats.model.ts index 5aac064b5e..fb8781fd4e 100644 --- a/src/app/core/models/report-stats.model.ts +++ b/src/app/core/models/report-stats.model.ts @@ -1,6 +1,4 @@ import { ReportsStatsResponsePlatform } from './platform/v1/report-stats-response.model'; -import { StatsResponse } from './platform/v1/stats-response.model'; - export interface ReportStats { draft: ReportsStatsResponsePlatform; report: ReportsStatsResponsePlatform; diff --git a/src/app/core/services/platform/v1/spender/reports.service.ts b/src/app/core/services/platform/v1/spender/reports.service.ts index 58833f49ab..e0bee40475 100644 --- a/src/app/core/services/platform/v1/spender/reports.service.ts +++ b/src/app/core/services/platform/v1/spender/reports.service.ts @@ -10,7 +10,6 @@ import { CreateDraftParams } from 'src/app/core/models/platform/v1/create-draft- import { PlatformApiPayload } from 'src/app/core/models/platform/platform-api-payload.model'; import { StatsResponse } from 'src/app/core/models/platform/v1/stats-response.model'; import { PlatformStatsRequestParams } from 'src/app/core/models/platform/v1/platform-stats-request-param.model'; -import { ReportsStatsResponsePlatform } from 'src/app/core/models/platform/v1/report-stats-response.model'; import { CacheBuster } from 'ts-cacheable'; import { UserEventService } from '../../../user-event.service'; import { TransactionService } from '../../../transaction.service'; diff --git a/src/app/core/services/report.service.ts b/src/app/core/services/report.service.ts index 109ec0309a..81d3fbbba1 100644 --- a/src/app/core/services/report.service.ts +++ b/src/app/core/services/report.service.ts @@ -20,7 +20,7 @@ import { ReportV1 } from '../models/report-v1.model'; import { ApproverPlatformApiService } from './approver-platform-api.service'; import { ExtendedReport } from '../models/report.model'; import { Approver } from '../models/v1/approver.model'; -import { Datum, StatsResponse } from '../models/v2/stats-response.model'; +import { Datum } from '../models/v2/stats-response.model'; import { ApiV2Service } from './api-v2.service'; import { ApiService } from './api.service'; import { AuthService } from './auth.service'; diff --git a/src/app/fyle/dashboard/dashboard.service.spec.ts b/src/app/fyle/dashboard/dashboard.service.spec.ts index 04f4e5045b..7f4fa332b5 100644 --- a/src/app/fyle/dashboard/dashboard.service.spec.ts +++ b/src/app/fyle/dashboard/dashboard.service.spec.ts @@ -3,12 +3,10 @@ import { TestBed } from '@angular/core/testing'; import { of } from 'rxjs'; import { apiEouRes } from 'src/app/core/mock-data/extended-org-user.data'; import { completeStats, emptyStats, incompleteStats } from 'src/app/core/mock-data/platform/v1/expenses-stats.data'; -import { StatsResponse } from 'src/app/core/models/v2/stats-response.model'; import { ApiV2Service } from 'src/app/core/services/api-v2.service'; import { AuthService } from 'src/app/core/services/auth.service'; import { CorporateCreditCardExpenseService } from 'src/app/core/services/corporate-credit-card-expense.service'; import { ExpensesService } from 'src/app/core/services/platform/v1/spender/expenses.service'; -import { ReportService } from 'src/app/core/services/report.service'; import { expectedAssignedCCCStats } from '../../core/mock-data/ccc-expense.details.data'; import { expectedEmptyReportStats, expectedReportStats } from '../../core/mock-data/report-stats.data'; import { apiAssignedCardDetailsRes } from '../../core/mock-data/stats-response.data'; diff --git a/src/app/fyle/dashboard/dashboard.service.ts b/src/app/fyle/dashboard/dashboard.service.ts index 38de4e679b..7634356eb6 100644 --- a/src/app/fyle/dashboard/dashboard.service.ts +++ b/src/app/fyle/dashboard/dashboard.service.ts @@ -6,10 +6,7 @@ import { ReportStats } from 'src/app/core/models/report-stats.model'; import { CorporateCreditCardExpenseService } from 'src/app/core/services/corporate-credit-card-expense.service'; import { ExpensesService } from 'src/app/core/services/platform/v1/spender/expenses.service'; import { Stats } from '../../core/models/stats.model'; -import { StatsResponse } from '../../core/models/v2/stats-response.model'; -import { ReportService } from '../../core/services/report.service'; import { SpenderReportsService } from 'src/app/core/services/platform/v1/spender/reports.service'; -import { ReportsStatsResponsePlatform } from 'src/app/core/models/platform/v1/report-stats-response.model'; @Injectable() export class DashboardService { diff --git a/src/app/fyle/dashboard/stats/stats.component.ts b/src/app/fyle/dashboard/stats/stats.component.ts index ff86ee6f21..4bd6949633 100644 --- a/src/app/fyle/dashboard/stats/stats.component.ts +++ b/src/app/fyle/dashboard/stats/stats.component.ts @@ -15,7 +15,6 @@ import { OrgSettingsService } from 'src/app/core/services/org-settings.service'; import { OrgService } from 'src/app/core/services/org.service'; import { PaymentModesService } from 'src/app/core/services/payment-modes.service'; import { ReportStatsData } from 'src/app/core/models/report-stats-data.model'; -import { StatsResponse } from 'src/app/core/models/platform/v1/stats-response.model'; import { ReportsStatsResponsePlatform } from 'src/app/core/models/platform/v1/report-stats-response.model'; @Component({ From f3f49919cc8263341309063aaef2fe65f50dfe58 Mon Sep 17 00:00:00 2001 From: aastha Date: Tue, 7 May 2024 14:38:51 +0530 Subject: [PATCH 39/46] Minor --- src/app/core/services/platform/v1/approver/reports.service.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/app/core/services/platform/v1/approver/reports.service.ts b/src/app/core/services/platform/v1/approver/reports.service.ts index 48cbbfa8f5..1779dca19a 100644 --- a/src/app/core/services/platform/v1/approver/reports.service.ts +++ b/src/app/core/services/platform/v1/approver/reports.service.ts @@ -7,7 +7,6 @@ import { PAGINATION_SIZE } from 'src/app/constants'; import { Report } from 'src/app/core/models/platform/v1/report.model'; import { PlatformStatsRequestParams } from 'src/app/core/models/platform/v1/platform-stats-request-param.model'; import { StatsResponse } from 'src/app/core/models/platform/v1/stats-response.model'; -import { ReportsStatsResponsePlatform } from 'src/app/core/models/platform/v1/report-stats-response.model'; @Injectable({ providedIn: 'root', From d368a8541d3bfcbfc1a9bcccf941817635356b01 Mon Sep 17 00:00:00 2001 From: aastha Date: Tue, 7 May 2024 14:39:29 +0530 Subject: [PATCH 40/46] Minor --- src/app/fyle/dashboard/dashboard.service.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/fyle/dashboard/dashboard.service.spec.ts b/src/app/fyle/dashboard/dashboard.service.spec.ts index 7f4fa332b5..60bbdf1d44 100644 --- a/src/app/fyle/dashboard/dashboard.service.spec.ts +++ b/src/app/fyle/dashboard/dashboard.service.spec.ts @@ -181,7 +181,7 @@ describe('DashboardService', () => { }); it('getCCCDetails(): should get assigned card details', (done) => { - authService.getEou.and.returnValue(Promise.resolve(apiEouRes)); + authService.getEou.and.resolveTo(apiEouRes); apiV2Service.getStats.and.returnValue(of(apiAssignedCardDetailsRes)); const apiParams = From c6aea7536abda83bffa329b7b2a8cea1c8f92a2c Mon Sep 17 00:00:00 2001 From: aastha Date: Tue, 7 May 2024 15:52:19 +0530 Subject: [PATCH 41/46] Minor --- .../platform/v1/spender/reports.service.spec.ts | 14 +++++--------- .../platform/v1/spender/reports.service.ts | 5 +++-- src/app/fyle/dashboard/dashboard.service.ts | 5 +++-- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/app/core/services/platform/v1/spender/reports.service.spec.ts b/src/app/core/services/platform/v1/spender/reports.service.spec.ts index b74baf6974..76336e3c18 100644 --- a/src/app/core/services/platform/v1/spender/reports.service.spec.ts +++ b/src/app/core/services/platform/v1/spender/reports.service.spec.ts @@ -170,18 +170,14 @@ describe('SpenderReportsService', () => { }); it('getReportsStats(): should get advance request stats', (done) => { - const statsResponse = { - count: 2, - total_amount: 1200, - }; - spenderPlatformV1ApiService.post.and.returnValue(of({ data: statsResponse })); + spenderPlatformV1ApiService.post.and.returnValue(of({ data: expectedReportStats.draft })); const params = { state: 'eq.DRAFT', }; spenderReportsService.getReportsStats(params).subscribe((res) => { - expect(res).toEqual(statsResponse); + expect(res).toEqual(expectedReportStats.draft); expect(spenderPlatformV1ApiService.post).toHaveBeenCalledOnceWith('/reports/stats', { data: { query_params: `state=${params.state}`, @@ -191,13 +187,13 @@ describe('SpenderReportsService', () => { }); }); - it('getReport(): should get a report by id', () => { + it('getReportById(): should get a report by id', () => { spyOn(spenderReportsService, 'getReportsByParams').and.returnValue(of(allReportsPaginated1)); const queryParams = { id: 'eq.rpvcIMRMyM3A', }; - spenderReportsService.getReport('rpvcIMRMyM3A').subscribe((res) => { - console.log(res); + spenderReportsService.getReportById('rpvcIMRMyM3A').subscribe((res) => { + expect(res).toEqual(allReportsPaginated1.data[0]); expect(spenderReportsService.getReportsByParams).toHaveBeenCalledOnceWith(queryParams); }); }); diff --git a/src/app/core/services/platform/v1/spender/reports.service.ts b/src/app/core/services/platform/v1/spender/reports.service.ts index e0bee40475..2056f62cdd 100644 --- a/src/app/core/services/platform/v1/spender/reports.service.ts +++ b/src/app/core/services/platform/v1/spender/reports.service.ts @@ -13,6 +13,7 @@ import { PlatformStatsRequestParams } from 'src/app/core/models/platform/v1/plat import { CacheBuster } from 'ts-cacheable'; import { UserEventService } from '../../../user-event.service'; import { TransactionService } from '../../../transaction.service'; +import { ReportsStatsResponsePlatform } from 'src/app/core/models/platform/v1/report-stats-response.model'; const reportsCacheBuster$ = new Subject(); @@ -121,14 +122,14 @@ export class SpenderReportsService { .pipe(map((res) => res.data)); } - getReportsStats(params: PlatformStatsRequestParams): Observable { + getReportsStats(params: PlatformStatsRequestParams): Observable { const queryParams = { data: { query_params: `state=${params.state}`, }, }; return this.spenderPlatformV1ApiService - .post<{ data: StatsResponse }>('/reports/stats', queryParams) + .post<{ data: ReportsStatsResponsePlatform }>('/reports/stats', queryParams) .pipe(map((res) => res.data)); } } diff --git a/src/app/fyle/dashboard/dashboard.service.ts b/src/app/fyle/dashboard/dashboard.service.ts index 7634356eb6..5847af7076 100644 --- a/src/app/fyle/dashboard/dashboard.service.ts +++ b/src/app/fyle/dashboard/dashboard.service.ts @@ -61,13 +61,14 @@ export class DashboardService { const paymentProcessingStats = this.spenderReportsService.getReportsStats({ state: 'eq.PAYMENT_PROCESSING', }); - const reportStatsObservable$ = forkJoin({ + const reportStatsValues = { draft: draftStats, report: reportedStats, approved: approvedStats, paymentPending: paymentPendingStats, processing: paymentProcessingStats, - }); + }; + const reportStatsObservable$ = forkJoin(reportStatsValues); return reportStatsObservable$; } From fd01bbdc4494af0d144f52040f7ef295f8c1c735 Mon Sep 17 00:00:00 2001 From: aastha Date: Tue, 7 May 2024 15:54:11 +0530 Subject: [PATCH 42/46] Minor --- src/app/core/services/platform/v1/spender/reports.service.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/app/core/services/platform/v1/spender/reports.service.ts b/src/app/core/services/platform/v1/spender/reports.service.ts index 2056f62cdd..9fb40854e5 100644 --- a/src/app/core/services/platform/v1/spender/reports.service.ts +++ b/src/app/core/services/platform/v1/spender/reports.service.ts @@ -8,7 +8,6 @@ import { ReportsQueryParams } from 'src/app/core/models/platform/v1/reports-quer import { PAGINATION_SIZE } from 'src/app/constants'; import { CreateDraftParams } from 'src/app/core/models/platform/v1/create-draft-params.model'; import { PlatformApiPayload } from 'src/app/core/models/platform/platform-api-payload.model'; -import { StatsResponse } from 'src/app/core/models/platform/v1/stats-response.model'; import { PlatformStatsRequestParams } from 'src/app/core/models/platform/v1/platform-stats-request-param.model'; import { CacheBuster } from 'ts-cacheable'; import { UserEventService } from '../../../user-event.service'; From c6f43404eff3ad24db9f47aa0299c223caa84d56 Mon Sep 17 00:00:00 2001 From: Aastha Bist Date: Tue, 7 May 2024 16:16:43 +0530 Subject: [PATCH 43/46] Update reports.service.spec.ts --- .../v1/spender/reports.service.spec.ts | 22 ------------------- 1 file changed, 22 deletions(-) diff --git a/src/app/core/services/platform/v1/spender/reports.service.spec.ts b/src/app/core/services/platform/v1/spender/reports.service.spec.ts index 76336e3c18..bb66513b2a 100644 --- a/src/app/core/services/platform/v1/spender/reports.service.spec.ts +++ b/src/app/core/services/platform/v1/spender/reports.service.spec.ts @@ -198,28 +198,6 @@ describe('SpenderReportsService', () => { }); }); - it('getReportsStats(): should get advance request stats', (done) => { - const statsResponse = { - count: 2, - total_amount: 1200, - }; - spenderPlatformV1ApiService.post.and.returnValue(of({ data: expectedReportStats.draft })); - - const params = { - state: 'eq.DRAFT', - }; - - spenderReportsService.getReportsStats(params).subscribe((res) => { - expect(res).toEqual(expectedReportStats.draft); - expect(spenderPlatformV1ApiService.post).toHaveBeenCalledOnceWith('/reports/stats', { - data: { - query_params: `state=${params.state}`, - }, - }); - done(); - }); - }); - it('ejectExpenses(): should remove an expense from a report', (done) => { spenderPlatformV1ApiService.post.and.returnValue(of(null)); spyOn(spenderReportsService, 'clearTransactionCache').and.returnValue(of(null)); From 5aa02599a10c818b122f1a4b2649fe613196ab5b Mon Sep 17 00:00:00 2001 From: aastha Date: Tue, 7 May 2024 16:27:12 +0530 Subject: [PATCH 44/46] Minor --- src/app/core/services/platform/v1/approver/reports.service.ts | 2 +- src/app/core/services/platform/v1/spender/reports.service.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/core/services/platform/v1/approver/reports.service.ts b/src/app/core/services/platform/v1/approver/reports.service.ts index 1779dca19a..99641f721b 100644 --- a/src/app/core/services/platform/v1/approver/reports.service.ts +++ b/src/app/core/services/platform/v1/approver/reports.service.ts @@ -44,7 +44,7 @@ export class ApproverReportsService { return this.getReportsByParams(params).pipe(map((res) => res.count)); } - getReportsByParams(queryParams: ReportsQueryParams = {}): Observable> { + getReportsByParams(queryParams: ReportsQueryParams): Observable> { const config = { params: { ...queryParams, diff --git a/src/app/core/services/platform/v1/spender/reports.service.ts b/src/app/core/services/platform/v1/spender/reports.service.ts index 9fb40854e5..459d96ece9 100644 --- a/src/app/core/services/platform/v1/spender/reports.service.ts +++ b/src/app/core/services/platform/v1/spender/reports.service.ts @@ -101,7 +101,7 @@ export class SpenderReportsService { return this.getReportsByParams(params).pipe(map((res) => res.count)); } - getReportsByParams(queryParams: ReportsQueryParams = {}): Observable> { + getReportsByParams(queryParams: ReportsQueryParams): Observable> { const config = { params: { ...queryParams, From eb3f340ea67807ba982084633db6f1f4fd73c6ee Mon Sep 17 00:00:00 2001 From: aastha Date: Tue, 7 May 2024 17:57:54 +0530 Subject: [PATCH 45/46] Minor --- src/app/fyle/dashboard/dashboard.page.spec.ts | 28 +++++++++++-------- src/app/fyle/dashboard/dashboard.page.ts | 4 +-- .../fyle/dashboard/stats/stats.component.ts | 2 +- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/app/fyle/dashboard/dashboard.page.spec.ts b/src/app/fyle/dashboard/dashboard.page.spec.ts index 3bdaab90e1..3a763dbe6a 100644 --- a/src/app/fyle/dashboard/dashboard.page.spec.ts +++ b/src/app/fyle/dashboard/dashboard.page.spec.ts @@ -47,23 +47,23 @@ describe('DashboardPage', () => { let navController: jasmine.SpyObj; beforeEach(waitForAsync(() => { - let networkServiceSpy = jasmine.createSpyObj('NetworkService', ['connectivityWatcher', 'isOnline']); - let currencyServiceSpy = jasmine.createSpyObj('CurrencyService', ['getHomeCurrency']); - let routerSpy = jasmine.createSpyObj('Router', ['navigate', 'url']); - let trackingServiceSpy = jasmine.createSpyObj('TrackingService', [ + const networkServiceSpy = jasmine.createSpyObj('NetworkService', ['connectivityWatcher', 'isOnline']); + const currencyServiceSpy = jasmine.createSpyObj('CurrencyService', ['getHomeCurrency']); + const routerSpy = jasmine.createSpyObj('Router', ['navigate', 'url']); + const trackingServiceSpy = jasmine.createSpyObj('TrackingService', [ 'tasksPageOpened', 'footerHomeTabClicked', 'dashboardActionSheetButtonClicked', 'dashboardActionSheetOpened', ]); - let actionSheetControllerSpy = jasmine.createSpyObj('ActionSheetController', ['create']); - let tasksServiceSpy = jasmine.createSpyObj('TasksService', ['getTotalTaskCount']); - let smartlookServiceSpy = jasmine.createSpyObj('SmartlookService', ['init']); - let orgSettingsServiceSpy = jasmine.createSpyObj('OrgSettingsService', ['get']); - let orgUserSettingsServiceSpy = jasmine.createSpyObj('OrgUserSettingsService', ['get']); + const actionSheetControllerSpy = jasmine.createSpyObj('ActionSheetController', ['create']); + const tasksServiceSpy = jasmine.createSpyObj('TasksService', ['getTotalTaskCount']); + const smartlookServiceSpy = jasmine.createSpyObj('SmartlookService', ['init']); + const orgSettingsServiceSpy = jasmine.createSpyObj('OrgSettingsService', ['get']); + const orgUserSettingsServiceSpy = jasmine.createSpyObj('OrgUserSettingsService', ['get']); const categoriesServiceSpy = jasmine.createSpyObj('CategoriesService', ['getMileageOrPerDiemCategories']); - let backButtonServiceSpy = jasmine.createSpyObj('BackButtonService', ['showAppCloseAlert']); - let navControllerSpy = jasmine.createSpyObj('NavController', ['back']); + const backButtonServiceSpy = jasmine.createSpyObj('BackButtonService', ['showAppCloseAlert']); + const navControllerSpy = jasmine.createSpyObj('NavController', ['back']); TestBed.configureTestingModule({ declarations: [DashboardPage], @@ -154,6 +154,12 @@ describe('DashboardPage', () => { expect(component.filterPills).toEqual(creditTxnFilterPill); }); + it('get filterPills(): should return undefined when filter pills are undefined', () => { + const tasksComponentSpy = jasmine.createSpyObj('TasksComponent', [], { taskCount: 1 }); + component.tasksComponent = tasksComponentSpy; + expect(component.filterPills).toBeUndefined(); + }); + it('ionViewWillLeave(): should call unsubscribe hardware back button and set onPageExit to null', () => { spyOn(component.onPageExit$, 'next'); component.hardwareBackButtonAction = new Subscription(); diff --git a/src/app/fyle/dashboard/dashboard.page.ts b/src/app/fyle/dashboard/dashboard.page.ts index 7bf2222d70..96b50d1b89 100644 --- a/src/app/fyle/dashboard/dashboard.page.ts +++ b/src/app/fyle/dashboard/dashboard.page.ts @@ -89,12 +89,12 @@ export class DashboardPage { } get filterPills(): FilterPill[] { - return this.tasksComponent?.filterPills; + return this.tasksComponent.filterPills; } ionViewWillLeave(): void { this.onPageExit$.next(null); - this.hardwareBackButtonAction?.unsubscribe(); + this.hardwareBackButtonAction.unsubscribe(); } setupNetworkWatcher(): void { diff --git a/src/app/fyle/dashboard/stats/stats.component.ts b/src/app/fyle/dashboard/stats/stats.component.ts index 4bd6949633..05ba1d7a99 100644 --- a/src/app/fyle/dashboard/stats/stats.component.ts +++ b/src/app/fyle/dashboard/stats/stats.component.ts @@ -90,7 +90,7 @@ export class StatsComponent implements OnInit { const orgSettings$ = this.orgSettingsService.get().pipe(shareReplay(1)); const simplifyReportsSettings$ = orgSettings$.pipe( - map((orgSettings) => ({ enabled: orgSettings?.simplified_report_closure_settings?.enabled })) + map((orgSettings) => ({ enabled: orgSettings.simplified_report_closure_settings?.enabled })) ); const isNonReimbursableOrg$ = orgSettings$.pipe( From 52b2f57c26214fab0d17fa61e28f611f038acfbd Mon Sep 17 00:00:00 2001 From: Aastha Bist Date: Tue, 7 May 2024 21:52:56 +0530 Subject: [PATCH 46/46] Update report-stats.data.ts --- src/app/core/mock-data/report-stats.data.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/core/mock-data/report-stats.data.ts b/src/app/core/mock-data/report-stats.data.ts index 110195d994..4f2edf25ac 100644 --- a/src/app/core/mock-data/report-stats.data.ts +++ b/src/app/core/mock-data/report-stats.data.ts @@ -44,8 +44,8 @@ export const expectedReportStats: ReportStats = deepFreeze({ total_amount: 5012.12, failed_amount: null, failed_count: null, - processing_amount: null, - processing_count: null, + processing_amount: 5012.12, + processing_count: 7, reimbursable_amount: null, }, });