Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a test for this and changed existing tests

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
Loading