Skip to content

Commit

Permalink
Minor
Browse files Browse the repository at this point in the history
  • Loading branch information
bistaastha committed Apr 29, 2024
1 parent c11842b commit f8ed65d
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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}`,
Expand Down
81 changes: 56 additions & 25 deletions src/app/fyle/dashboard/dashboard.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ReportService>;
let expensesService: jasmine.SpyObj<ExpensesService>;
let authService: jasmine.SpyObj<AuthService>;
let apiV2Service: jasmine.SpyObj<ApiV2Service>;

const apiReportStatParams: Partial<StatsResponse> = {
scalar: false,
dimension_1_1: 'rp_state',
aggregates: 'sum(rp_amount),count(rp_id)',
};
let spenderReportsService: jasmine.SpyObj<SpenderReportsService>;

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,
Expand All @@ -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<ReportService>;
expensesService = TestBed.inject(ExpensesService) as jasmine.SpyObj<ExpensesService>;
authService = TestBed.inject(AuthService) as jasmine.SpyObj<AuthService>;
apiV2Service = TestBed.inject(ApiV2Service) as jasmine.SpyObj<ApiV2Service>;
spenderReportsService = TestBed.inject(SpenderReportsService) as jasmine.SpyObj<SpenderReportsService>;
});

it('should be created', () => {
Expand Down Expand Up @@ -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();
});
});
Expand Down
8 changes: 7 additions & 1 deletion src/app/fyle/dashboard/dashboard.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -48,6 +48,12 @@ export class DashboardService {
);
}

getSpenderReportsStats(): Observable<ReportsStatsResponsePlatform> {
return this.spenderReportsService.getReportsStats({
state: 'eq.DRAFT',
});
}

getReportsStats(): Observable<ReportStats> {
const draftStats = this.spenderReportsService.getReportsStats({
state: 'eq.DRAFT',
Expand Down

0 comments on commit f8ed65d

Please sign in to comment.