Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Move report stats call to platform in dashboard #2907

Merged
merged 54 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
9e33e2c
Minor
bistaastha Apr 18, 2024
e0851cd
Update reports.service.ts
bistaastha Apr 18, 2024
510af5d
Minor
bistaastha Apr 18, 2024
3ee6972
Minor
bistaastha Apr 19, 2024
8b6d202
Minor
bistaastha Apr 19, 2024
a4c88ba
Update reports.service.spec.ts
bistaastha Apr 19, 2024
e1a2cfe
Update reports.service.spec.ts
bistaastha Apr 19, 2024
20433c7
Update view-expense.page.ts
bistaastha Apr 19, 2024
6cd2788
Update view-mileage.page.ts
bistaastha Apr 19, 2024
0f6d646
Update view-per-diem.page.ts
bistaastha Apr 19, 2024
f0aa09b
Update reports.service.ts
bistaastha Apr 25, 2024
cafd8c3
feat: Move add expenses to platform (#2878)
bistaastha Apr 25, 2024
c2a8e74
Minor
bistaastha Apr 25, 2024
94a919d
Minor
bistaastha Apr 26, 2024
5eaefdf
Minor
bistaastha Apr 26, 2024
436ac68
Minor
bistaastha Apr 26, 2024
1943364
Update reports.service.spec.ts
bistaastha Apr 26, 2024
c6e9fcc
Update reports.service.ts
bistaastha Apr 26, 2024
597b6f4
Minor
bistaastha Apr 26, 2024
bf71e82
Mt push
bistaastha Apr 26, 2024
1272999
Update reports.service.spec.ts
bistaastha Apr 26, 2024
d51f7ad
Revert "Minor"
bistaastha Apr 26, 2024
ee8d684
Merge branch 'master' into FYLE-86cuqn6db-add-methods-to-get-reports
bistaastha Apr 26, 2024
5ce284f
Merge branch 'master' into FYLE-86cuqn6db-add-methods-to-get-reports
bistaastha Apr 26, 2024
c1fe7b0
Update reports.service.ts
bistaastha Apr 26, 2024
109fa15
Rename platform-stats-requesst-param.model.ts to platform-stats-reque…
bistaastha Apr 26, 2024
74be123
Update reports.service.ts
bistaastha Apr 26, 2024
bdb940a
Update reports.service.ts
bistaastha Apr 26, 2024
12fa61d
Update reports.service.ts
bistaastha Apr 26, 2024
b8e7994
Merge branch 'FYLE-86cuqn6db-add-methods-to-get-reports' into FYLE-86…
bistaastha Apr 26, 2024
4a812b6
Minor
bistaastha Apr 26, 2024
19cb290
Merge branch 'FYLE-86cuqn6db-add-methods-to-get-reports-approvers' of…
bistaastha Apr 26, 2024
1705f10
Minor
bistaastha Apr 26, 2024
d6614f4
Minor
bistaastha Apr 26, 2024
70482e5
Minor
bistaastha Apr 29, 2024
c7a604f
Minor
bistaastha Apr 29, 2024
c11842b
Minor
bistaastha Apr 29, 2024
f8ed65d
Minor
bistaastha Apr 29, 2024
ce1ea5d
Minor
bistaastha Apr 29, 2024
d8e2708
Update dashboard.service.spec.ts
bistaastha Apr 29, 2024
210ba44
Update dashboard.service.ts
bistaastha Apr 29, 2024
7023bbf
fix: fix platform spender reports test coverage (#2950)
bistaastha May 7, 2024
1fd28ee
Minor
bistaastha May 7, 2024
a540c60
Minor
bistaastha May 7, 2024
f3f4991
Minor
bistaastha May 7, 2024
d368a85
Minor
bistaastha May 7, 2024
c6aea75
Minor
bistaastha May 7, 2024
fd01bbd
Minor
bistaastha May 7, 2024
b4aca49
Merge branch 'master' into FYLE-86cuqn6db-stats
bistaastha May 7, 2024
c6f4340
Update reports.service.spec.ts
bistaastha May 7, 2024
5aa0259
Minor
bistaastha May 7, 2024
35f7595
Merge branch 'FYLE-86cuqn6db-stats' of github.com:fylein/fyle-mobile-…
bistaastha May 7, 2024
eb3f340
Minor
bistaastha May 7, 2024
52b2f57
Update report-stats.data.ts
bistaastha May 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 60 additions & 10 deletions src/app/core/mock-data/report-stats.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should have processing_amount and processing_count, no?

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,
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface PlatformStatsRequestParams {
state: string;
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export interface ReportsQueryParams {
offset?: number;
limit?: number;
order?: string;
id?: string;
}
13 changes: 7 additions & 6 deletions src/app/core/models/report-stats.model.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Stats } from './stats.model';
import { ReportsStatsResponsePlatform } from './platform/v1/report-stats-response.model';
import { StatsResponse } from './platform/v1/stats-response.model';

export interface ReportStats {
draft: Stats;
report: Stats;
approved: Stats;
paymentPending: Stats;
processing: Stats;
draft: ReportsStatsResponsePlatform;
report: ReportsStatsResponsePlatform;
approved: ReportsStatsResponsePlatform;
paymentPending: ReportsStatsResponsePlatform;
processing: ReportsStatsResponsePlatform;
}
141 changes: 139 additions & 2 deletions src/app/core/services/platform/v1/approver/reports.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,36 @@ 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';
import {
allReportsPaginated1,
allReportsPaginated2,
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';
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;
const approverPlatformApiService = jasmine.createSpyObj('ApproverPlatformApiService', ['post']);
let approverPlatformApiService: jasmine.SpyObj<ApproverPlatformApiService>;

beforeEach(() => {
const approverPlatformApiServiceSpy = jasmine.createSpyObj('ApproverPlatformApiService', ['post', 'get']);
TestBed.configureTestingModule({
providers: [
ApproverReportsService,
{ provide: ApproverPlatformApiService, useValue: approverPlatformApiService },
{ provide: PAGINATION_SIZE, useValue: 2 },
{ provide: ApproverPlatformApiService, useValue: approverPlatformApiServiceSpy },
],
});
approverReportsService = TestBed.inject(ApproverReportsService);
approverPlatformApiService = TestBed.inject(
ApproverPlatformApiService
) as jasmine.SpyObj<ApproverPlatformApiService>;
});

it('should be created', () => {
Expand All @@ -39,4 +56,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: StatsResponse = {
count: 2,
total_amount: 1200,
};
approverPlatformApiService.post.and.returnValue(of({ data: expectedReportStats.draft }));

const params = {
state: 'eq.DRAFT',
};

approverReportsService.getReportsStats(params).subscribe((res) => {
expect(res).toEqual(expectedReportStats.draft);
expect(approverPlatformApiService.post).toHaveBeenCalledOnceWith('/reports/stats', {
data: {
query_params: `state=${params.state}`,
},
});
done();
});
});
});
66 changes: 63 additions & 3 deletions src/app/core/services/platform/v1/approver/reports.service.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,72 @@
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';
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',
})
export class ApproverReportsService {
constructor(private approverPlatformApiService: ApproverPlatformApiService) {}
constructor(
@Inject(PAGINATION_SIZE) private paginationSize: number,
private approverPlatformApiService: ApproverPlatformApiService
) {}

getAllReportsByParams(queryParams: ReportsQueryParams): Observable<Report[]> {
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<number> {
let params = {
state: queryParams.state,
limit: 1,
offset: 0,
};
return this.getReportsByParams(params).pipe(map((res) => res.count));
}

getReportsByParams(queryParams: ReportsQueryParams = {}): Observable<PlatformApiResponse<Report>> {
const config = {
params: {
...queryParams,
},
};
return this.approverPlatformApiService.get<PlatformApiResponse<Report>>('/reports', config);
}

getReportsStats(params: PlatformStatsRequestParams): Observable<ReportsStatsResponsePlatform> {
return this.approverPlatformApiService
.post<{ data: ReportsStatsResponsePlatform }>('/reports/stats', {
data: {
query_params: `state=${params.state}`,
},
})
.pipe(map((res) => res.data));
}

getReport(id: string): Observable<Report> {
return this.getReportsByParams({ id: `eq.${id}` }).pipe(map((res) => res.data[0]));
}

ejectExpenses(rptId: string, expenseId: string, comment?: string[]): Observable<void> {
const payload = {
Expand Down
Loading
Loading