diff --git a/src/app/fyle/add-edit-expense/add-edit-expense-3.spec.ts b/src/app/fyle/add-edit-expense/add-edit-expense-3.spec.ts index f4405a10ed..a8ce64efa0 100644 --- a/src/app/fyle/add-edit-expense/add-edit-expense-3.spec.ts +++ b/src/app/fyle/add-edit-expense/add-edit-expense-3.spec.ts @@ -991,6 +991,7 @@ export function TestCases3(getTestBed) { component.mode = 'edit'; component.attachedReceiptsCount = 0; spyOn(component, 'getExpenseAttachments').and.returnValue(of(fileObject4)); + expensesService.getExpenseById.and.returnValue(of(platformExpenseWithExtractedData)); spyOn(component.loadAttachments$, 'next'); loaderService.showLoader.and.resolveTo(); loaderService.hideLoader.and.resolveTo(); @@ -1020,6 +1021,7 @@ export function TestCases3(getTestBed) { mode: 'ios', }); expect(component.loadAttachments$.next).toHaveBeenCalledOnceWith(); + expect(expensesService.getExpenseById).toHaveBeenCalledOnceWith('tx3qHxFNgRcZ'); expect(component.attachedReceiptsCount).toEqual(1); })); @@ -1420,6 +1422,7 @@ export function TestCases3(getTestBed) { transactionOutboxService.fileUpload.and.resolveTo(mockFileData[0]); activatedRoute.snapshot.params.id = mockFileData[0].transaction_id; expensesService.attachReceiptToExpense.and.returnValue(of(platformExpenseWithExtractedData)); + expensesService.getExpenseById.and.returnValue(of(platformExpenseWithExtractedData)); spyOn(component, 'parseFile').and.returnValue(null); spyOn(component.loadAttachments$, 'next'); fixture.detectChanges(); @@ -1435,6 +1438,7 @@ export function TestCases3(getTestBed) { mockFileData[0].transaction_id, mockFileData[0].id ); + expect(expensesService.getExpenseById).toHaveBeenCalledOnceWith('txbO4Xaj4N53'); expect(component.loadAttachments$.next).toHaveBeenCalledOnceWith(); expect(trackingService.fileUploadComplete).toHaveBeenCalledOnceWith({ mode: 'edit', diff --git a/src/app/fyle/add-edit-expense/add-edit-expense.page.ts b/src/app/fyle/add-edit-expense/add-edit-expense.page.ts index cdd6920d26..e1080ba241 100644 --- a/src/app/fyle/add-edit-expense/add-edit-expense.page.ts +++ b/src/app/fyle/add-edit-expense/add-edit-expense.page.ts @@ -4447,8 +4447,11 @@ export class AddEditExpensePage implements OnInit { } }); } else { - const editExpenseAttachments$ = this.etxn$.pipe( - switchMap((etxn) => (etxn.tx.id ? this.platformExpense$ : of({}))), + this.platformExpense$ = this.etxn$.pipe( + switchMap((etxn) => this.expensesService.getExpenseById(etxn.tx.id).pipe(shareReplay(1))) + ); + + const editExpenseAttachments$ = this.platformExpense$.pipe( map((expense: PlatformExpense) => expense.file_ids?.length || 0) ); @@ -4651,6 +4654,10 @@ export class AddEditExpensePage implements OnInit { }; }; + this.platformExpense$ = this.etxn$.pipe( + switchMap((etxn) => this.expensesService.getExpenseById(etxn.tx.id).pipe(shareReplay(1))) + ); + if (this.mode === 'add') { if (data && data.attachments) { this.newExpenseDataUrls = data.attachments;