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

fix: Fix tests for tasks page stats changes [2] #2928

Merged
merged 21 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
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
115 changes: 68 additions & 47 deletions src/app/core/mock-data/report-stats.data.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,44 @@
import deepFreeze from 'deep-freeze-strict';

import { ReportStats } from '../models/report-stats.model';
import { PlatformReportsStatsResponse } from '../models/platform/v1/report-stats-response.model';

export const expectedReportStats: ReportStats = deepFreeze({
draft: {
count: 6,
failed_amount: null,
failed_count: null,
processing_amount: null,
processing_count: null,
reimbursable_amount: null,
count: 2,
total_amount: 93165.91,
failed_amount: 0,
failed_count: 0,
processing_amount: 0,
processing_count: 0,
reimbursable_amount: 0,
},
report: {
count: 45,
count: 2,
total_amount: 5177243929.65219,
failed_amount: null,
failed_count: null,
processing_amount: null,
processing_count: null,
reimbursable_amount: null,
failed_amount: 0,
failed_count: 0,
processing_amount: 0,
processing_count: 0,
reimbursable_amount: 0,
},
approved: {
count: 56,
total_amount: 28758273650702.816,
failed_amount: null,
failed_count: null,
processing_amount: null,
processing_count: null,
reimbursable_amount: null,
failed_amount: 0,
failed_count: 0,
processing_amount: 0,
processing_count: 0,
reimbursable_amount: 0,
},
paymentPending: {
count: 4,
total_amount: 501602.12,
failed_amount: null,
failed_count: null,
processing_amount: null,
processing_count: null,
reimbursable_amount: null,
failed_amount: 0,
failed_count: 0,
processing_amount: 0,
processing_count: 0,
reimbursable_amount: 0,
},
processing: {
count: 7,
Expand All @@ -54,46 +55,66 @@ export const expectedEmptyReportStats: ReportStats = deepFreeze({
draft: {
total_amount: 0,
count: 0,
failed_amount: null,
failed_count: null,
processing_amount: null,
processing_count: null,
reimbursable_amount: null,
failed_amount: 0,
failed_count: 0,
processing_amount: 0,
processing_count: 0,
reimbursable_amount: 0,
},
report: {
total_amount: 0,
count: 0,
failed_amount: null,
failed_count: null,
processing_amount: null,
processing_count: null,
reimbursable_amount: null,
failed_amount: 0,
failed_count: 0,
processing_amount: 0,
processing_count: 0,
reimbursable_amount: 0,
},
approved: {
total_amount: 0,
count: 0,
failed_amount: null,
failed_count: null,
processing_amount: null,
processing_count: null,
reimbursable_amount: null,
failed_amount: 0,
failed_count: 0,
processing_amount: 0,
processing_count: 0,
reimbursable_amount: 0,
},
paymentPending: {
total_amount: 0,
count: 0,
failed_amount: null,
failed_count: null,
processing_amount: null,
processing_count: null,
reimbursable_amount: null,
failed_amount: 0,
failed_count: 0,
processing_amount: 0,
processing_count: 0,
reimbursable_amount: 0,
},
processing: {
total_amount: 0,
count: 0,
failed_amount: null,
failed_count: null,
processing_amount: null,
processing_count: null,
reimbursable_amount: null,
failed_amount: 0,
failed_count: 0,
processing_amount: 0,
processing_count: 0,
reimbursable_amount: 0,
},
});

export const expectedSentBackResponse: PlatformReportsStatsResponse = deepFreeze({
total_amount: 4500,
count: 2,
failed_amount: 0,
failed_count: 0,
processing_amount: 0,
processing_count: 0,
reimbursable_amount: 0,
});

export const expectedSentBackResponseSingularReport: PlatformReportsStatsResponse = deepFreeze({
total_amount: 4500,
count: 1,
failed_amount: 0,
failed_count: 0,
processing_amount: 0,
processing_count: 0,
reimbursable_amount: 0,
});
22 changes: 18 additions & 4 deletions src/app/core/mock-data/task.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,24 @@ export const teamReportTaskSample = deepFreeze({
});

export const sentBackReportTaskSample = deepFreeze({
amount: '44.53',
amount: '4.5K',
count: 2,
header: 'Reports sent back!',
subheader: '2 reports worth ₹4.5K were sent back by your approver',
icon: TaskIcon.REPORT,
ctas: [
{
content: 'View Reports',
event: TASKEVENT.openSentBackReport,
},
],
});

export const sentBackReportTaskSingularSample = deepFreeze({
amount: '4.5K',
count: 1,
header: 'Report sent back!',
subheader: '1 report worth ₹44.53 was sent back by your approver',
subheader: '1 report worth ₹4.5K was sent back by your approver',
icon: TaskIcon.REPORT,
ctas: [
{
Expand Down Expand Up @@ -102,10 +116,10 @@ export const unreportedExpenseTaskSample2 = deepFreeze({
});

export const unsubmittedReportTaskSample = deepFreeze({
amount: '0.00',
amount: '93.17K',
count: 2,
header: 'Unsubmitted reports',
subheader: '2 reports remain in draft state',
subheader: '2 reports worth ₹93.17K remain in draft state',
icon: TaskIcon.REPORT,
ctas: [
{
Expand Down
4 changes: 2 additions & 2 deletions src/app/core/models/approver.model.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export interface Approver {
full_name: string;
email: string;
full_name: string | null;
email: string | null;
bistaastha marked this conversation as resolved.
Show resolved Hide resolved
}
export interface AdvanceApprover {
added_by: string;
Expand Down
2 changes: 1 addition & 1 deletion src/app/core/models/custom_field.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { AbstractControl } from '@angular/forms';
export interface CustomField {
id?: number;
name: string;
value: string | boolean | number | Date | string[] | { display: string };
value: string | boolean | number | Date | string[] | { display: string } | null;
type?: string;
displayValue?: string | boolean | number | Date | string[] | { display: string };
mandatory?: boolean;
Expand Down
28 changes: 14 additions & 14 deletions src/app/core/models/org-user.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ export interface OrgUser {
user_id?: string;
employee_id?: number | string;
location: string;
level?: number | string;
level?: number | string | null;
level_id?: string;
band?: string;
business_unit?: string;
department_id?: string;
department?: string;
sub_department?: string;
band?: string | null;
business_unit?: string | null;
department_id?: string | null;
department?: string | null;
sub_department?: string | null;
roles?: string[];
approver1_id?: string;
approver2_id?: string;
approver3_id?: string;
delegatee_id?: string;
delegation_start_at?: Date;
delegation_end_at?: Date;
approver2_id?: string | null;
approver3_id?: string | null;
delegatee_id?: string | null;
delegation_start_at?: Date | null;
delegation_end_at?: Date | null;
title?: string;
status: string;
branch_ifsc?: string;
Expand All @@ -29,16 +29,16 @@ export interface OrgUser {
mobile_verified?: boolean;
mobile_verified_at?: Date;
is_primary?: boolean;
owner?: boolean;
joining_dt?: Date;
owner?: boolean | null;
joining_dt?: Date | null;
special_email?: string;
custom_field_values?: CustomField[];
org_name: string;
settings_id?: string;
default_cost_center_id?: number;
default_cost_center_name?: string;
default_cost_center_code?: string;
rank?: number;
rank?: number | null;
cost_center_ids?: number[];
mobile_verification_attempts_left?: number;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
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';
import { ReportState } from '../../../../models/platform/v1/report.model';

describe('ApproverReportsService', () => {
let approverReportsService: ApproverReportsService;
Expand Down Expand Up @@ -58,6 +59,15 @@ describe('ApproverReportsService', () => {
});
});

it('generateStatsQueryParams(): should generate stats query params', () => {
const queryParams = {
state: `eq.${ReportState.DRAFT}`,
};

const result = approverReportsService.generateStatsQueryParams(queryParams);
expect(result).toEqual('state=eq.DRAFT');
});

it('getReportsCount(): should get a count of reports', (done) => {
// Mock the response of getReportsByParams
spyOn(approverReportsService, 'getReportsByParams').and.returnValue(of(platformReportCountData));
Expand Down Expand Up @@ -158,14 +168,10 @@ describe('ApproverReportsService', () => {
});

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',
state: `eq.${ReportState.DRAFT}`,
};

approverReportsService.getReportsStats(params).subscribe((res) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Inject, Injectable, PlatformRef } from '@angular/core';
import { Inject, Injectable } from '@angular/core';
import { Observable, Subject, range } from 'rxjs';
import { concatMap, map, reduce, switchMap, tap } from 'rxjs/operators';
import { Report } from 'src/app/core/models/platform/v1/report.model';
Expand Down Expand Up @@ -73,7 +73,7 @@ export class SpenderReportsService {
);
}

getAllReportsByParams(queryParams: ReportsQueryParams, order?: string): Observable<Report[]> {
getAllReportsByParams(queryParams: ReportsQueryParams): Observable<Report[]> {
return this.getReportsCount(queryParams).pipe(
switchMap((count) => {
count = count > this.paginationSize ? count / this.paginationSize : 1;
Expand Down
Loading
Loading