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: Add estatuses post call #3018

Closed
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import {
mockQueryParams,
mockQueryParamsForCount,
platformReportCountData,
platformReportData,
} 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';
import { ReportState } from '../../../../models/platform/v1/report.model';
import { apiReportPermissions } from 'src/app/core/mock-data/report-permissions.data';
import { Comment } from 'src/app/core/models/platform/v1/comment.model';

describe('ApproverReportsService', () => {
let approverReportsService: ApproverReportsService;
Expand Down Expand Up @@ -130,6 +132,21 @@ describe('ApproverReportsService', () => {
});
});

it('postComment(): should add a comment', (done) => {
const expectedCommentData: Comment = platformReportData.comments[0];
approverPlatformApiService.post.and.returnValue(of({ data: expectedCommentData }));

const id = 'rpxtbiLXQZUm';
Copy link
Contributor

Choose a reason for hiding this comment

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

fix.


approverReportsService.postComment(id, 'comment').subscribe((res) => {
expect(res).toEqual(expectedCommentData);
expect(approverPlatformApiService.post).toHaveBeenCalledOnceWith('/reports/comments', {
data: { id, comment: 'comment' },
});
done();
});
});

it('getAllReportsByParams(): should get all reports single page', (done) => {
const getReportsByParams = spyOn(approverReportsService, 'getReportsByParams');
spyOn(approverReportsService, 'getReportsCount').and.returnValue(of(1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { PlatformStatsRequestParams } from 'src/app/core/models/platform/v1/plat
import { PlatformReportsStatsResponse } from 'src/app/core/models/platform/v1/report-stats-response.model';
import { PlatformApiPayload } from 'src/app/core/models/platform/platform-api-payload.model';
import { ReportPermissions } from 'src/app/core/models/report-permissions.model';
import { Comment } from 'src/app/core/models/platform/v1/comment.model';

@Injectable({
providedIn: 'root',
Expand Down Expand Up @@ -86,6 +87,12 @@ export class ApproverReportsService {
.pipe(map((res) => res.data));
}

postComment(id: string, comment: string): Observable<Comment> {
return this.approverPlatformApiService
.post<PlatformApiPayload<Comment>>('/reports/comments', { data: { id, comment } })
.pipe(map((res) => res.data));
}

ejectExpenses(rptId: string, expenseId: string, comment?: string[]): Observable<void> {
const payload = {
data: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import {
expectedReportsSinglePage,
mockQueryParams,
mockQueryParamsForCount,
platformReportData,
} 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';
import { UserEventService } from '../../../user-event.service';
import { TransactionService } from '../../../transaction.service';
import { apiReportPermissions } from 'src/app/core/mock-data/report-permissions.data';
import { Comment } from 'src/app/core/models/platform/v1/comment.model';

describe('SpenderReportsService', () => {
let spenderReportsService: SpenderReportsService;
Expand Down Expand Up @@ -80,6 +82,21 @@ describe('SpenderReportsService', () => {
});
});

it('postComment(): should add a comment', (done) => {
const expectedCommentData: Comment = platformReportData.comments[0];
spenderPlatformV1ApiService.post.and.returnValue(of({ data: expectedCommentData }));

const id = 'rpxtbiLXQZUm';
Copy link
Contributor

Choose a reason for hiding this comment

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

fix.


spenderReportsService.postComment(id, 'comment').subscribe((res) => {
expect(res).toEqual(expectedCommentData);
expect(spenderPlatformV1ApiService.post).toHaveBeenCalledOnceWith('/reports/comments', {
data: { id, comment: 'comment' },
});
done();
});
});

it('getAllReportsByParams(): should get all reports multiple pages', (done) => {
const getReportsByParams = spyOn(spenderReportsService, 'getReportsByParams');
spyOn(spenderReportsService, 'getReportsCount').and.returnValue(of(4));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { UserEventService } from '../../../user-event.service';
import { TransactionService } from '../../../transaction.service';
import { PlatformReportsStatsResponse } from 'src/app/core/models/platform/v1/report-stats-response.model';
import { ReportPermissions } from 'src/app/core/models/report-permissions.model';
import { Comment } from 'src/app/core/models/platform/v1/comment.model';

const reportsCacheBuster$ = new Subject<void>();

Expand Down Expand Up @@ -90,6 +91,12 @@ export class SpenderReportsService {
.pipe(map((res) => res.data));
}

postComment(id: string, comment: string): Observable<Comment> {
return this.spenderPlatformV1ApiService
.post<PlatformApiPayload<Comment>>('/reports/comments', { data: { id, comment } })
.pipe(map((res) => res.data));
}

getAllReportsByParams(queryParams: ReportsQueryParams): Observable<Report[]> {
return this.getReportsCount(queryParams).pipe(
switchMap((count) => {
Expand Down
8 changes: 4 additions & 4 deletions src/app/fyle/my-view-report/my-view-report.page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import { NetworkService } from '../../core/services/network.service';
import { TrackingService } from '../../core/services/tracking.service';
import { txnStatusData } from 'src/app/core/mock-data/transaction-status.data';
import {
allReportsPaginated1,
expectedReportsSinglePage,
paidReportData,
platformReportData,
Expand Down Expand Up @@ -130,6 +131,7 @@ describe('MyViewReportPage', () => {
'addExpenses',
'getReportById',
'permissions',
'postComment',
]);

TestBed.configureTestingModule({
Expand Down Expand Up @@ -905,7 +907,7 @@ describe('MyViewReportPage', () => {
component.segmentValue = ReportPageSegment.COMMENTS;
fixture.detectChanges();

statusService.post.and.returnValue(of(txnStatusData));
spenderReportsService.postComment.and.returnValue(of(allReportsPaginated1.data[0].comments[0]));
spyOn(component.content, 'scrollToBottom');
component.newComment = 'comment';
component.segmentValue = ReportPageSegment.COMMENTS;
Expand All @@ -919,9 +921,7 @@ describe('MyViewReportPage', () => {
component.addComment();
fixture.detectChanges();

expect(statusService.post).toHaveBeenCalledOnceWith(component.objectType, component.reportId, {
comment: 'comment',
});
expect(spenderReportsService.postComment).toHaveBeenCalledOnceWith(component.reportId, 'comment');
expect(component.newComment).toBeNull();
expect(component.isCommentAdded).toBeTrue();
});
Expand Down
8 changes: 3 additions & 5 deletions src/app/fyle/my-view-report/my-view-report.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -554,16 +554,14 @@ export class MyViewReportPage {

addComment(): void {
if (this.newComment) {
const data = {
comment: this.newComment,
};
const comment = this.newComment;

this.newComment = null;
this.commentInput.nativeElement.focus();
this.isCommentAdded = true;

this.statusService
.post(this.objectType, this.reportId, data)
this.spenderReportsService
.postComment(this.reportId, comment)
.pipe()
.subscribe(() => {
this.loadReportDetails$.next();
Expand Down
14 changes: 9 additions & 5 deletions src/app/fyle/view-team-report/view-team-report.page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
newEstatusData1,
systemComments1,
systemCommentsWithSt,
userComments,
} from 'src/app/core/test-data/status.service.spec.data';
import { FyPopoverComponent } from 'src/app/shared/components/fy-popover/fy-popover.component';
import { PopupAlertComponent } from 'src/app/shared/components/popup-alert/popup-alert.component';
Expand All @@ -49,6 +50,7 @@ import { pdfExportData1, pdfExportData2 } from 'src/app/core/mock-data/pdf-expor
import { EditReportNamePopoverComponent } from '../my-view-report/edit-report-name-popover/edit-report-name-popover.component';
import { cloneDeep } from 'lodash';
import {
allReportsPaginated1,
allReportsPaginatedWithApproval,
expectedReportsSinglePage,
platformReportData,
Expand Down Expand Up @@ -126,7 +128,11 @@ describe('ViewTeamReportPageV2', () => {
const statusServiceSpy = jasmine.createSpyObj('StatusService', ['find', 'createStatusMap', 'post']);
const humanizeCurrencySpy = jasmine.createSpyObj('HumanizeCurrencyPipe', ['transform']);
const orgSettingsServiceSpy = jasmine.createSpyObj('OrgSettingsService', ['get']);
const approverReportsServiceSpy = jasmine.createSpyObj('ApproverReportsService', ['getReportById', 'permissions']);
const approverReportsServiceSpy = jasmine.createSpyObj('ApproverReportsService', [
'getReportById',
'permissions',
'postComment',
]);

TestBed.configureTestingModule({
declarations: [ViewTeamReportPage, EllipsisPipe, HumanizeCurrencyPipe],
Expand Down Expand Up @@ -886,7 +892,7 @@ describe('ViewTeamReportPageV2', () => {
});

it('addComment(): should add a comment', () => {
statusService.post.and.returnValue(of(txnStatusData));
approverReportsService.postComment.and.returnValue(of(allReportsPaginated1.data[0].comments[0]));
spyOn(component, 'loadReports').and.returnValue(of(expectedReportsSinglePage[0]));
spyOn(component.content, 'scrollToBottom');
// spyOn(component.refreshEstatuses$, 'next');
Expand All @@ -897,9 +903,7 @@ describe('ViewTeamReportPageV2', () => {
spyOn(component.commentInput.nativeElement, 'focus');

component.addComment();
expect(statusService.post).toHaveBeenCalledOnceWith(component.objectType, component.objectId, {
comment: 'comment',
});
expect(approverReportsService.postComment).toHaveBeenCalledOnceWith(component.objectId, 'comment');
expect(component.isCommentAdded).toBeTrue();
expect(component.newComment).toBeNull();
expect(component.loadReports).toHaveBeenCalledTimes(1);
Expand Down
6 changes: 2 additions & 4 deletions src/app/fyle/view-team-report/view-team-report.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { LoaderService } from 'src/app/core/services/loader.service';
import { PopoverController, ModalController, IonContent } from '@ionic/angular';
import { ModalPropertiesService } from 'src/app/core/services/modal-properties.service';
import { switchMap, finalize, map, shareReplay, tap, startWith, take, takeUntil, filter } from 'rxjs/operators';

Check failure on line 9 in src/app/fyle/view-team-report/view-team-report.page.ts

View workflow job for this annotation

GitHub Actions / Run linters

'startWith' is defined but never used
import { PopupService } from 'src/app/core/services/popup.service';
import { NetworkService } from '../../core/services/network.service';
import { TrackingService } from '../../core/services/tracking.service';
Expand Down Expand Up @@ -542,15 +542,13 @@

addComment(): void {
if (this.newComment) {
const data = {
comment: this.newComment,
};
const comment = this.newComment;

this.newComment = null;
(this.commentInput.nativeElement as HTMLElement).focus();
this.isCommentAdded = true;

this.statusService.post(this.objectType, this.objectId, data).subscribe(() => {
this.approverReportsService.postComment(this.objectId, comment).subscribe(() => {
this.loadReports().subscribe();
setTimeout(() => {
this.content.scrollToBottom(500);
Expand Down
Loading