From e9a85088db3bdc0d89ec4354a286556836444c6d Mon Sep 17 00:00:00 2001 From: Aastha Bist Date: Thu, 11 Jul 2024 23:43:03 +0530 Subject: [PATCH] feat: Add API for partial approval (#3134) --- .../platform/v1/approver/reports.service.spec.ts | 13 +++++++++++++ .../platform/v1/approver/reports.service.ts | 8 ++++++++ src/app/core/services/report.service.spec.ts | 10 ---------- src/app/core/services/report.service.ts | 7 ------- .../view-team-report/view-team-report.page.spec.ts | 6 +++--- .../fyle/view-team-report/view-team-report.page.ts | 2 +- 6 files changed, 25 insertions(+), 21 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 c906e257ef..9008965f43 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 @@ -230,6 +230,19 @@ describe('ApproverReportsService', () => { }); }); + it('approve(): should approve a report', (done) => { + approverPlatformApiService.post.and.returnValue(of(null)); + + const reportID = 'rpShFuVCUIXk'; + const data = { + id: reportID, + }; + approverReportsService.approve(reportID).subscribe(() => { + expect(approverPlatformApiService.post).toHaveBeenCalledOnceWith(`/reports/partially_approve`, { data }); + done(); + }); + }); + it('getReportsStats(): should get advance request stats', (done) => { approverPlatformApiService.post.and.returnValue(of({ data: expectedReportStats.draft })); 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 1398c9e333..9f509612aa 100644 --- a/src/app/core/services/platform/v1/approver/reports.service.ts +++ b/src/app/core/services/platform/v1/approver/reports.service.ts @@ -107,6 +107,14 @@ export class ApproverReportsService { .pipe(map((res) => res.data)); } + approve(rptId: string): Observable { + const data = { + id: rptId, + }; + + return this.approverPlatformApiService.post('/reports/partially_approve', { data }); + } + ejectExpenses(rptId: string, expenseId: string, comment?: string[]): Observable { const payload = { data: { diff --git a/src/app/core/services/report.service.spec.ts b/src/app/core/services/report.service.spec.ts index 2a76faab0d..ab79873139 100644 --- a/src/app/core/services/report.service.spec.ts +++ b/src/app/core/services/report.service.spec.ts @@ -250,16 +250,6 @@ describe('ReportService', () => { }); }); - it('approve(): should approve a report', (done) => { - apiService.post.and.returnValue(of(null)); - - const reportID = 'rpShFuVCUIXk'; - reportService.approve(reportID).subscribe(() => { - expect(apiService.post).toHaveBeenCalledOnceWith(`/reports/${reportID}/approve`); - done(); - }); - }); - it('delete(): should delete a report', (done) => { apiService.delete.and.returnValue(of(null)); spyOn(reportService, 'clearTransactionCache').and.returnValue(of(null)); diff --git a/src/app/core/services/report.service.ts b/src/app/core/services/report.service.ts index e4eac0a087..91d80174bb 100644 --- a/src/app/core/services/report.service.ts +++ b/src/app/core/services/report.service.ts @@ -67,13 +67,6 @@ export class ReportService { return this.transactionService.clearCache(); } - @CacheBuster({ - cacheBusterNotifier: reportsCacheBuster$, - }) - approve(rptId: string): Observable { - return this.apiService.post('/reports/' + rptId + '/approve'); - } - @CacheBuster({ cacheBusterNotifier: reportsCacheBuster$, }) diff --git a/src/app/fyle/view-team-report/view-team-report.page.spec.ts b/src/app/fyle/view-team-report/view-team-report.page.spec.ts index 4cbd7726e2..e8692dd74f 100644 --- a/src/app/fyle/view-team-report/view-team-report.page.spec.ts +++ b/src/app/fyle/view-team-report/view-team-report.page.spec.ts @@ -14,7 +14,6 @@ import { } from '@ionic/angular'; import { finalize, of } from 'rxjs'; import { click, getElementBySelector, getTextContent } from 'src/app/core/dom-helpers'; -import { approversData1, approversData4, approversData5, approversData6 } from 'src/app/core/mock-data/approver.data'; import { apiEouRes } from 'src/app/core/mock-data/extended-org-user.data'; import { apiReportPermissions } from 'src/app/core/mock-data/report-permissions.data'; import { ExpenseView } from 'src/app/core/models/expense-view.enum'; @@ -131,6 +130,7 @@ describe('ViewTeamReportPageV2', () => { 'permissions', 'postComment', 'sendBack', + 'approve', ]); TestBed.configureTestingModule({ @@ -601,7 +601,7 @@ describe('ViewTeamReportPageV2', () => { }); popoverController.create.and.resolveTo(popoverSpy); - reportService.approve.and.returnValue(of(undefined)); + approverReportsService.approve.and.returnValue(of(undefined)); refinerService.startSurvey.and.returnValue(null); component.report$ = of(reportWithExpenses); @@ -632,7 +632,7 @@ describe('ViewTeamReportPageV2', () => { reportWithExpenses.currency, false ); - expect(reportService.approve).toHaveBeenCalledOnceWith(platformReportData.id); + expect(approverReportsService.approve).toHaveBeenCalledOnceWith(platformReportData.id); expect(refinerService.startSurvey).toHaveBeenCalledOnceWith({ actionName: 'Approve Report' }); expect(router.navigate).toHaveBeenCalledOnceWith(['/', 'enterprise', 'team_reports']); }); diff --git a/src/app/fyle/view-team-report/view-team-report.page.ts b/src/app/fyle/view-team-report/view-team-report.page.ts index 9f5c25cb6d..b52ee2f2fa 100644 --- a/src/app/fyle/view-team-report/view-team-report.page.ts +++ b/src/app/fyle/view-team-report/view-team-report.page.ts @@ -419,7 +419,7 @@ export class ViewTeamReportPage { const { data } = (await popover.onWillDismiss()) as { data: { action: string } }; if (data && data.action === 'approve') { - this.reportService.approve(report.id).subscribe(() => { + this.approverReportsService.approve(report.id).subscribe(() => { this.refinerService.startSurvey({ actionName: 'Approve Report' }); this.router.navigate(['/', 'enterprise', 'team_reports']); });