Skip to content

Commit

Permalink
feat: Add API for partial approval (#3134)
Browse files Browse the repository at this point in the history
  • Loading branch information
bistaastha authored Jul 11, 2024
1 parent 91f3050 commit e9a8508
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 21 deletions.
13 changes: 13 additions & 0 deletions src/app/core/services/platform/v1/approver/reports.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }));

Expand Down
8 changes: 8 additions & 0 deletions src/app/core/services/platform/v1/approver/reports.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ export class ApproverReportsService {
.pipe(map((res) => res.data));
}

approve(rptId: string): Observable<Report> {
const data = {
id: rptId,
};

return this.approverPlatformApiService.post('/reports/partially_approve', { data });
}

ejectExpenses(rptId: string, expenseId: string, comment?: string[]): Observable<void> {
const payload = {
data: {
Expand Down
10 changes: 0 additions & 10 deletions src/app/core/services/report.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
7 changes: 0 additions & 7 deletions src/app/core/services/report.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,6 @@ export class ReportService {
return this.transactionService.clearCache();
}

@CacheBuster({
cacheBusterNotifier: reportsCacheBuster$,
})
approve(rptId: string): Observable<void> {
return this.apiService.post('/reports/' + rptId + '/approve');
}

@CacheBuster({
cacheBusterNotifier: reportsCacheBuster$,
})
Expand Down
6 changes: 3 additions & 3 deletions src/app/fyle/view-team-report/view-team-report.page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -131,6 +130,7 @@ describe('ViewTeamReportPageV2', () => {
'permissions',
'postComment',
'sendBack',
'approve',
]);

TestBed.configureTestingModule({
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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']);
});
Expand Down
2 changes: 1 addition & 1 deletion src/app/fyle/view-team-report/view-team-report.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
});
Expand Down

0 comments on commit e9a8508

Please sign in to comment.