diff --git a/src/app/core/services/report.service.spec.ts b/src/app/core/services/report.service.spec.ts index a6960cd6fc..0f50176022 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)); @@ -541,23 +521,26 @@ describe('ReportService', () => { it('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..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(); @@ -140,30 +139,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$, })