From de8624d491e5ad8fccf4393982d35df7b96d3c81 Mon Sep 17 00:00:00 2001 From: suyashpatil78 Date: Tue, 16 Jan 2024 22:51:22 +0530 Subject: [PATCH 1/3] fix: BR fix for not updating incomplete expense incase extracted date is present --- .../add-edit-expense-2.spec.ts | 24 ++++++++++++++++--- .../add-edit-expense/add-edit-expense.page.ts | 4 ++-- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/app/fyle/add-edit-expense/add-edit-expense-2.spec.ts b/src/app/fyle/add-edit-expense/add-edit-expense-2.spec.ts index 335cf0b4d8..5069da8488 100644 --- a/src/app/fyle/add-edit-expense/add-edit-expense-2.spec.ts +++ b/src/app/fyle/add-edit-expense/add-edit-expense-2.spec.ts @@ -93,6 +93,7 @@ import { FileObject } from 'src/app/core/models/file-obj.model'; import { CustomField } from 'src/app/core/models/custom_field.model'; import { ExpensesService } from 'src/app/core/services/platform/v1/spender/expenses.service'; import { expenseDuplicateSet2 } from 'src/app/core/mock-data/platform/v1/expense-duplicate-sets.data'; +import { cloneDeep } from 'lodash'; const properties = { cssClass: 'fy-modal', @@ -459,9 +460,7 @@ export function TestCases2(getTestBed) { expect(categoriesService.getCategoryByName).toHaveBeenCalledOnceWith( unflattenedTxnWithExtractedData.tx.extracted_data.category ); - expect(dateService.getUTCDate).toHaveBeenCalledWith( - new Date(unflattenedTxnWithExtractedData.tx.extracted_data.date) - ); + expect(dateService.getUTCDate).not.toHaveBeenCalled(); expect(component.isIncompleteExpense).toBeTrue(); done(); }); @@ -488,6 +487,25 @@ export function TestCases2(getTestBed) { done(); }); }); + + it('should update txn date with extracted date if txn date is not defined in original expense', (done) => { + const mockedTxn = cloneDeep(unflattenedTxnWithExtractedData2); + const extractedDate = new Date('2023-01-24'); + + mockedTxn.tx.txn_dt = null; + mockedTxn.tx.extracted_data.invoice_dt = null; + mockedTxn.tx.extracted_data.date = extractedDate; + + transactionService.getETxnUnflattened.and.returnValue(of(mockedTxn)); + dateService.getUTCDate.and.returnValue(extractedDate); + + component.getEditExpenseObservable().subscribe((res) => { + expect(res).toEqual(unflattenedTxnWithExtractedData2); + expect(dateService.getUTCDate).toHaveBeenCalledOnceWith(mockedTxn.tx.extracted_data.date); + expect(mockedTxn.tx.txn_dt).toEqual(extractedDate); + done(); + }); + }); }); it('goToPrev(): should go to the previous txn', () => { 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 caa7c64a4c..986baf1c6b 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 @@ -2562,11 +2562,11 @@ export class AddEditExpensePage implements OnInit { etxn.tx.currency = etxn.tx.extracted_data.currency; } - if (etxn.tx.extracted_data.date) { + if (etxn.tx.extracted_data.date && !etxn.tx.txn_dt) { etxn.tx.txn_dt = this.dateService.getUTCDate(new Date(etxn.tx.extracted_data.date)); } - if (etxn.tx.extracted_data.invoice_dt) { + if (etxn.tx.extracted_data.invoice_dt && !etxn.tx.txn_dt) { etxn.tx.txn_dt = this.dateService.getUTCDate(new Date(etxn.tx.extracted_data.invoice_dt)); } From 313778b6d02e15c4d528ad3560374a930f7fd2f3 Mon Sep 17 00:00:00 2001 From: suyashpatil78 Date: Tue, 16 Jan 2024 22:56:06 +0530 Subject: [PATCH 2/3] minor --- src/app/fyle/add-edit-expense/add-edit-expense-2.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/fyle/add-edit-expense/add-edit-expense-2.spec.ts b/src/app/fyle/add-edit-expense/add-edit-expense-2.spec.ts index 5069da8488..6244313160 100644 --- a/src/app/fyle/add-edit-expense/add-edit-expense-2.spec.ts +++ b/src/app/fyle/add-edit-expense/add-edit-expense-2.spec.ts @@ -483,7 +483,7 @@ export function TestCases2(getTestBed) { component.getEditExpenseObservable().subscribe((res) => { expect(res).toEqual(unflattenedTxnWithExtractedData2); expect(transactionService.getETxnUnflattened).toHaveBeenCalledTimes(1); - expect(dateService.getUTCDate).toHaveBeenCalledTimes(2); + expect(dateService.getUTCDate).not.toHaveBeenCalled(); done(); }); }); From 085dbbbcf2a6ff1df70a795b020cdefecdf23116 Mon Sep 17 00:00:00 2001 From: suyashpatil78 Date: Tue, 16 Jan 2024 22:57:03 +0530 Subject: [PATCH 3/3] minor --- src/app/fyle/add-edit-expense/add-edit-expense-2.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/fyle/add-edit-expense/add-edit-expense-2.spec.ts b/src/app/fyle/add-edit-expense/add-edit-expense-2.spec.ts index 6244313160..ac9ac1e645 100644 --- a/src/app/fyle/add-edit-expense/add-edit-expense-2.spec.ts +++ b/src/app/fyle/add-edit-expense/add-edit-expense-2.spec.ts @@ -500,7 +500,7 @@ export function TestCases2(getTestBed) { dateService.getUTCDate.and.returnValue(extractedDate); component.getEditExpenseObservable().subscribe((res) => { - expect(res).toEqual(unflattenedTxnWithExtractedData2); + expect(res).toEqual(mockedTxn); expect(dateService.getUTCDate).toHaveBeenCalledOnceWith(mockedTxn.tx.extracted_data.date); expect(mockedTxn.tx.txn_dt).toEqual(extractedDate); done();