Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/FYLE-86cuqn6db-tasks' into FYLE-…
Browse files Browse the repository at this point in the history
…86cuqn6db-tasks-v2-reports
  • Loading branch information
bistaastha committed May 14, 2024
2 parents 3aa62ec + 518256a commit 804f697
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 7 deletions.
20 changes: 19 additions & 1 deletion src/app/core/services/tasks.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { TaskIcon } from '../models/task-icon.enum';
import {
allExtendedReportsResponse,
extendedOrgUserResponse,
extendedOrgUserResponseSpender,
incompleteExpensesResponse,
potentialDuplicatesApiResponse,
sentBackAdvancesResponse,
Expand Down Expand Up @@ -288,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 @@ -312,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
24 changes: 18 additions & 6 deletions src/app/core/services/tasks.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,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
8 changes: 8 additions & 0 deletions src/app/core/test-data/tasks.service.spec.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,14 @@ export const extendedOrgUserResponse: ExtendedOrgUser = deepFreeze({
},
});

export const extendedOrgUserResponseSpender: ExtendedOrgUser = deepFreeze({
...extendedOrgUserResponse,
ou: {
...extendedOrgUserResponse.ou,
roles: ['FYLER'],
},
});

export const teamReportResponse = deepFreeze([
{
aggregates: [
Expand Down

0 comments on commit 804f697

Please sign in to comment.