Skip to content

Commit

Permalink
fix: BR fix for not updating incomplete expense incase extracted date…
Browse files Browse the repository at this point in the history
… is present (#2672)

* fix: BR fix for not updating incomplete expense incase extracted date is present

* minor

* minor
  • Loading branch information
suyashpatil78 authored Jan 17, 2024
1 parent 84c6cbc commit b205b66
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
26 changes: 22 additions & 4 deletions src/app/fyle/add-edit-expense/add-edit-expense-2.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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();
});
Expand All @@ -484,7 +483,26 @@ 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();
});
});

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(mockedTxn);
expect(dateService.getUTCDate).toHaveBeenCalledOnceWith(mockedTxn.tx.extracted_data.date);
expect(mockedTxn.tx.txn_dt).toEqual(extractedDate);
done();
});
});
Expand Down
4 changes: 2 additions & 2 deletions src/app/fyle/add-edit-expense/add-edit-expense.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down

0 comments on commit b205b66

Please sign in to comment.