From 91fe0d99be73c7742be63d6ff1a2496a1d7eb2b4 Mon Sep 17 00:00:00 2001 From: aastha Date: Mon, 29 Apr 2024 08:36:50 +0530 Subject: [PATCH 1/3] Minor --- src/app/core/services/report.service.spec.ts | 37 ++++++-------------- src/app/core/services/report.service.ts | 32 +++++++---------- 2 files changed, 22 insertions(+), 47 deletions(-) diff --git a/src/app/core/services/report.service.spec.ts b/src/app/core/services/report.service.spec.ts index a6960cd6fc..7760d3880f 100644 --- a/src/app/core/services/report.service.spec.ts +++ b/src/app/core/services/report.service.spec.ts @@ -247,26 +247,6 @@ describe('ReportService', () => { }); }); - it('removeTransaction(): should remove a transaction from report', (done) => { - apiService.post.and.returnValue(of(null)); - spyOn(reportService, 'clearTransactionCache').and.returnValue(of(null)); - - const reportID = 'rpvcIMRMyM3A'; - const txnID = 'txTQVBx7W8EO'; - - const params = { - status: { - comment: null, - }, - }; - - reportService.removeTransaction(reportID, txnID, null).subscribe(() => { - expect(apiService.post).toHaveBeenCalledOnceWith(`/reports/${reportID}/txns/${txnID}/remove`, params); - expect(reportService.clearTransactionCache).toHaveBeenCalledTimes(1); - done(); - }); - }); - describe('getMyReports()', () => { it('should get reports from API as specified by params', (done) => { authService.getEou.and.returnValue(Promise.resolve(apiEouRes)); @@ -539,25 +519,28 @@ describe('ReportService', () => { }); }); - it('create(): should create a new report', (done) => { + fit('create(): should create a new report', (done) => { spyOn(reportService, 'createDraft').and.returnValue(of(reportUnflattenedData2)); - apiService.post.and.returnValue(of(null)); + spenderPlatformV1ApiService.post.and.returnValue(of(null)); spyOn(reportService, 'submit').and.returnValue(of(null)); const reportPurpose = { purpose: 'A new report', source: 'MOBILE', }; - const txnIds = ['tx6Oe6FaYDZl']; + const expenseIds = ['tx6Oe6FaYDZl']; const reportID = 'rp5eUkeNm9wB'; - const txnParam = { - ids: txnIds, + const payload = { + data: { + id: reportID, + expense_ids: expenseIds, + }, }; - reportService.create(reportPurpose, txnIds).subscribe((res) => { + reportService.create(reportPurpose, expenseIds).subscribe((res) => { expect(res).toEqual(reportUnflattenedData2); expect(reportService.createDraft).toHaveBeenCalledOnceWith(reportPurpose); - expect(apiService.post).toHaveBeenCalledOnceWith(`/reports/${reportID}/txns`, txnParam); + expect(spenderPlatformV1ApiService.post).toHaveBeenCalledOnceWith('/reports/add_expenses', payload); expect(reportService.submit).toHaveBeenCalledOnceWith(reportID); done(); }); diff --git a/src/app/core/services/report.service.ts b/src/app/core/services/report.service.ts index 3a598c402f..908adae095 100644 --- a/src/app/core/services/report.service.ts +++ b/src/app/core/services/report.service.ts @@ -140,30 +140,22 @@ export class ReportService { @CacheBuster({ cacheBusterNotifier: reportsCacheBuster$, }) - create(report: ReportPurpose, txnIds: string[]): Observable { + create(report: ReportPurpose, expenseIds: string[]): Observable { return this.createDraft(report).pipe( - switchMap((newReport: ReportV1) => - this.apiService - .post('/reports/' + newReport.id + '/txns', { ids: txnIds }) - .pipe(switchMap(() => this.submit(newReport.id).pipe(map(() => newReport)))) - ) + switchMap((newReport: ReportV1) => { + const payload = { + data: { + id: newReport.id, + expense_ids: expenseIds, + }, + }; + return this.spenderPlatformV1ApiService + .post('/reports/add_expenses', payload) + .pipe(switchMap(() => this.submit(newReport.id).pipe(map(() => newReport)))); + }) ); } - @CacheBuster({ - cacheBusterNotifier: reportsCacheBuster$, - }) - removeTransaction(rptId: string, txnId: string, comment?: string[]): Observable { - const aspy = { - status: { - comment, - }, - }; - return this.apiService - .post('/reports/' + rptId + '/txns/' + txnId + '/remove', aspy) - .pipe(tap(() => this.clearTransactionCache())); - } - @CacheBuster({ cacheBusterNotifier: reportsCacheBuster$, }) From 155ef94b2ad2d1a2e057e0a96e8a45bdb1cbd8a0 Mon Sep 17 00:00:00 2001 From: Aastha Bist Date: Mon, 29 Apr 2024 08:38:05 +0530 Subject: [PATCH 2/3] Update report.service.spec.ts --- src/app/core/services/report.service.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/core/services/report.service.spec.ts b/src/app/core/services/report.service.spec.ts index 7760d3880f..0f50176022 100644 --- a/src/app/core/services/report.service.spec.ts +++ b/src/app/core/services/report.service.spec.ts @@ -519,7 +519,7 @@ describe('ReportService', () => { }); }); - fit('create(): should create a new report', (done) => { + it('create(): should create a new report', (done) => { spyOn(reportService, 'createDraft').and.returnValue(of(reportUnflattenedData2)); spenderPlatformV1ApiService.post.and.returnValue(of(null)); spyOn(reportService, 'submit').and.returnValue(of(null)); From 5f77dc77ede2a7d11722d42ff18326f44a8e5101 Mon Sep 17 00:00:00 2001 From: Aastha Bist Date: Mon, 29 Apr 2024 20:18:44 +0530 Subject: [PATCH 3/3] Update report.service.ts --- src/app/core/services/report.service.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/app/core/services/report.service.ts b/src/app/core/services/report.service.ts index 908adae095..6ecdc2f6ed 100644 --- a/src/app/core/services/report.service.ts +++ b/src/app/core/services/report.service.ts @@ -33,7 +33,6 @@ import { SpenderPlatformV1ApiService } from './spender-platform-v1-api.service'; import { StorageService } from './storage.service'; import { TransactionService } from './transaction.service'; import { UserEventService } from './user-event.service'; -import { Expense } from '../models/expense.model'; const reportsCacheBuster$ = new Subject();