Skip to content

Commit

Permalink
Minor
Browse files Browse the repository at this point in the history
  • Loading branch information
bistaastha committed May 17, 2024
1 parent 0af40e0 commit db8f84d
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 38 deletions.
29 changes: 18 additions & 11 deletions src/app/core/services/tasks.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ import {
expectedSentBackResponseSingularReport,
} from '../mock-data/report-stats.data';
import { expectedReportsSinglePage } from '../mock-data/platform-report.data';
import { apiEouRes } from '../mock-data/extended-org-user.data';

describe('TasksService', () => {
let tasksService: TasksService;
Expand All @@ -89,7 +88,6 @@ describe('TasksService', () => {
const reportServiceSpy = jasmine.createSpyObj('ReportService', [
'getReportAutoSubmissionDetails',
'getAllExtendedReports',
'getReportStatsData',
]);
const expensesServiceSpy = jasmine.createSpyObj('ExpensesService', ['getExpenseStats', 'getDuplicateSets']);
const userEventServiceSpy = jasmine.createSpyObj('UserEventService', ['onTaskCacheClear']);
Expand Down Expand Up @@ -291,7 +289,7 @@ describe('TasksService', () => {
});
});

it('should be able to fetch team reports tasks', (done) => {
it('should be able to fetch team reports tasks is role is APPROVER', (done) => {
authService.getEou.and.returnValue(new Promise((resolve) => resolve(extendedOrgUserResponse)));
currencyService.getHomeCurrency.and.returnValue(of(homeCurrency));

Expand All @@ -315,6 +313,23 @@ describe('TasksService', () => {
});
});

it('should be able to return dummy team reports tasks is role is not APPROVER', (done) => {
authService.getEou.and.returnValue(new Promise((resolve) => resolve(extendedOrgUserResponseSpender)));
currencyService.getHomeCurrency.and.returnValue(of(homeCurrency));

humanizeCurrencyPipe.transform
.withArgs(expectedReportStats.report.total_amount, homeCurrency, true)
.and.returnValue('733.48K');
humanizeCurrencyPipe.transform
.withArgs(expectedReportStats.report.total_amount, homeCurrency)
.and.returnValue('₹733.48K');

tasksService.getTeamReportsTasks().subscribe((teamReportsTasks) => {
expect(teamReportsTasks).toEqual([]);
done();
});
});

it('should be able to fetch potential duplicate tasks', (done) => {
setupData();
expensesService.getDuplicateSets.and.returnValue(of(expenseDuplicateSets));
Expand Down Expand Up @@ -359,14 +374,6 @@ describe('TasksService', () => {
});
});

it('should make sure that stats dont fail even if aggregates are not present in response', () => {
const mappedStatsReponse = tasksService.getStatsFromResponse([], 'count(rp_id)', 'sum(rp_amount)');
expect(mappedStatsReponse).toEqual({
totalCount: 0,
totalAmount: 0,
});
});

it('should be able to fetch expensesTaskCount', (done) => {
tasksService.expensesTaskCount$.next(10);
tasksService
Expand Down
42 changes: 18 additions & 24 deletions src/app/core/services/tasks.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import { SpenderReportsService } from './platform/v1/spender/reports.service';
import { PlatformReportsStatsResponse } from '../models/platform/v1/report-stats-response.model';
import { ApproverReportsService } from './platform/v1/approver/reports.service';
import { ReportState } from '../models/platform/v1/report.model';
import { Datum } from '../models/v2/stats-response.model';

@Injectable({
providedIn: 'root',
Expand Down Expand Up @@ -477,12 +476,24 @@ export class TasksService {

getTeamReportsStats(): Observable<PlatformReportsStatsResponse> {
return from(this.authService.getEou()).pipe(
switchMap((eou) =>
this.approverReportsService.getReportsStats({
next_approver_user_ids: `cs.[${eou.us.id}]`,
state: `eq.${ReportState.APPROVER_PENDING}`,
})
)
switchMap((eou) => {
if (eou.ou.roles.includes('APPROVER')) {
return this.approverReportsService.getReportsStats({
next_approver_user_ids: `cs.[${eou.us.id}]`,
state: `eq.${ReportState.APPROVER_PENDING}`,
});
}
const zeroResponse: PlatformReportsStatsResponse = {
count: 0,
failed_amount: null,
failed_count: null,
processing_amount: 0,
processing_count: 0,
reimbursable_amount: 0,
total_amount: 0,
};
return of(zeroResponse);
})
);
}

Expand Down Expand Up @@ -529,23 +540,6 @@ export class TasksService {
return task;
}

getStatsFromResponse(
statsResponse: Datum[],
countName: string,
sumName: string
): { totalCount: number; totalAmount: number } {
const countAggregate = statsResponse[0]?.aggregates.find((aggregate) => aggregate.function_name === countName) || 0;
const amountAggregate = statsResponse[0]?.aggregates.find((aggregate) => aggregate.function_name === sumName) || 0;
return {
totalCount: countAggregate && countAggregate.function_value,
totalAmount: amountAggregate && amountAggregate.function_value,
};
}

mapScalarReportStatsResponse(statsResponse: Datum[]): { totalCount: number; totalAmount: number } {
return this.getStatsFromResponse(statsResponse, 'count(rp_id)', 'sum(rp_amount)');
}

mapPotentialDuplicatesTasks(duplicateSets: string[][]): DashboardTask[] {
if (duplicateSets.length > 0) {
const duplicateIds = duplicateSets.reduce((acc, curVal) => acc.concat(curVal), []);
Expand Down
3 changes: 1 addition & 2 deletions src/app/fyle/dashboard/tasks/tasks-2.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import { SpenderReportsService } from 'src/app/core/services/platform/v1/spender
import { ApproverReportsService } from 'src/app/core/services/platform/v1/approver/reports.service';
import { expectedReportsSinglePage } from 'src/app/core/mock-data/platform-report.data';
import { apiEouRes } from 'src/app/core/mock-data/extended-org-user.data';
import { apiReportRes } from 'src/app/core/mock-data/api-reports.data';

export function TestCases2(getTestBed) {
return describe('test case set 2', () => {
Expand Down Expand Up @@ -363,7 +362,7 @@ export function TestCases2(getTestBed) {
loaderService.showLoader.and.resolveTo();
loaderService.hideLoader.and.resolveTo();
authService.getEou.and.resolveTo(apiEouRes);
reportService.getTeamReports.and.returnValue(of(apiReportRes));
approverReportsService.getAllReportsByParams.and.returnValue(of(expectedReportsSinglePage));
});

it('should get all team reports and navigate to my view report page if task count is 1', fakeAsync(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/app/fyle/dashboard/tasks/tasks.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ export class TasksComponent implements OnInit {
from(this.authService.getEou()).subscribe((eou) => {
const queryParams = {
next_approver_user_ids: `cs.[${eou.us.id}]`,
state: 'eq.APPROVER_PENDING',
state: `eq.${ReportState.APPROVER_PENDING}`,
};
return from(this.loaderService.showLoader('Opening your report...'))
.pipe(
Expand Down

0 comments on commit db8f84d

Please sign in to comment.