From 0a5eefe290e7860672b9283160f9b0f207569e61 Mon Sep 17 00:00:00 2001 From: Arjun Date: Tue, 10 Dec 2024 20:00:31 +0530 Subject: [PATCH 1/2] standardize custom fields for policy check --- src/app/fyle/add-edit-expense/add-edit-expense.page.ts | 7 +++---- src/app/fyle/add-edit-mileage/add-edit-mileage.page.ts | 3 +++ src/app/fyle/add-edit-per-diem/add-edit-per-diem.page.ts | 3 +++ 3 files changed, 9 insertions(+), 4 deletions(-) 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 d9a2c7b43f..198ed2a17a 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 @@ -3518,14 +3518,13 @@ export class AddEditExpensePage implements OnInit { const isAdvanceWalletEnabled = res.orgSettings?.advances?.advance_wallets_enabled; let customProperties = res.customProperties; customProperties = customProperties.map((customProperty) => { + if (!customProperty.value) { + customProperty = this.customFieldsService.setDefaultValue(customProperty, customProperty.type); + } if (customProperty.type === 'DATE') { customProperty.value = customProperty.value ? this.dateService.getUTCDate(new Date(customProperty.value as string)) : null; - } else if (customProperty.type === 'LOCATION' && !customProperty.value) { - customProperty.value = {}; - } else if (customProperty.type === 'BOOLEAN' && !customProperty.value) { - customProperty.value = false; } return customProperty; }); diff --git a/src/app/fyle/add-edit-mileage/add-edit-mileage.page.ts b/src/app/fyle/add-edit-mileage/add-edit-mileage.page.ts index 7f0044cc4c..eb9e92bc16 100644 --- a/src/app/fyle/add-edit-mileage/add-edit-mileage.page.ts +++ b/src/app/fyle/add-edit-mileage/add-edit-mileage.page.ts @@ -2415,6 +2415,9 @@ export class AddEditMileagePage implements OnInit { const formValue = this.getFormValues(); let customProperties = res.customProperties; customProperties = customProperties?.map((customProperty) => { + if (!customProperty.value) { + customProperty = this.customFieldsService.setDefaultValue(customProperty, customProperty.type); + } if (customProperty.type === 'DATE') { customProperty.value = customProperty.value && this.dateService.getUTCDate(new Date(customProperty.value as string)); diff --git a/src/app/fyle/add-edit-per-diem/add-edit-per-diem.page.ts b/src/app/fyle/add-edit-per-diem/add-edit-per-diem.page.ts index ee9a115bfe..428451509c 100644 --- a/src/app/fyle/add-edit-per-diem/add-edit-per-diem.page.ts +++ b/src/app/fyle/add-edit-per-diem/add-edit-per-diem.page.ts @@ -1697,6 +1697,9 @@ export class AddEditPerDiemPage implements OnInit { const isAdvanceWalletEnabled = res.orgSettings?.advances?.advance_wallets_enabled; let customProperties = res.customProperties; customProperties = customProperties.map((customProperty) => { + if (!customProperty.value) { + customProperty = this.customFieldsService.setDefaultValue(customProperty, customProperty.type); + } if (customProperty.type === 'DATE') { customProperty.value = customProperty.value && this.dateService.getUTCDate(new Date(customProperty.value as string)); From ed38183f516f2cee598a2c79968b010c3c4acda2 Mon Sep 17 00:00:00 2001 From: Arjun Date: Tue, 10 Dec 2024 20:54:40 +0530 Subject: [PATCH 2/2] fix tests --- src/app/fyle/add-edit-expense/add-edit-expense.page.ts | 2 +- src/app/fyle/add-edit-expense/add-edit-expense.setup.spec.ts | 5 ++++- .../add-edit-mileage/add-edit-mileage.page.setup.spec.ts | 5 ++++- src/app/fyle/add-edit-mileage/add-edit-mileage.page.ts | 2 +- .../add-edit-per-diem/add-edit-per-diem.page.setup.spec.ts | 5 ++++- src/app/fyle/add-edit-per-diem/add-edit-per-diem.page.ts | 2 +- 6 files changed, 15 insertions(+), 6 deletions(-) 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 198ed2a17a..513922528e 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 @@ -3519,7 +3519,7 @@ export class AddEditExpensePage implements OnInit { let customProperties = res.customProperties; customProperties = customProperties.map((customProperty) => { if (!customProperty.value) { - customProperty = this.customFieldsService.setDefaultValue(customProperty, customProperty.type); + this.customFieldsService.setDefaultValue(customProperty, customProperty.type); } if (customProperty.type === 'DATE') { customProperty.value = customProperty.value diff --git a/src/app/fyle/add-edit-expense/add-edit-expense.setup.spec.ts b/src/app/fyle/add-edit-expense/add-edit-expense.setup.spec.ts index eeade6fa19..c784bba396 100644 --- a/src/app/fyle/add-edit-expense/add-edit-expense.setup.spec.ts +++ b/src/app/fyle/add-edit-expense/add-edit-expense.setup.spec.ts @@ -103,7 +103,10 @@ describe('AddEditExpensePage', () => { 'addExpenses', ]); const customInputsServiceSpy = jasmine.createSpyObj('CustomInputsService', ['getAll', 'filterByCategory']); - const customFieldsServiceSpy = jasmine.createSpyObj('CustomFieldsService', ['standardizeCustomFields']); + const customFieldsServiceSpy = jasmine.createSpyObj('CustomFieldsService', [ + 'standardizeCustomFields', + 'setDefaultValue', + ]); const transactionServiceSpy = jasmine.createSpyObj('TransactionService', [ 'delete', 'getRemoveCardExpenseDialogBody', diff --git a/src/app/fyle/add-edit-mileage/add-edit-mileage.page.setup.spec.ts b/src/app/fyle/add-edit-mileage/add-edit-mileage.page.setup.spec.ts index 176123e784..b529d6704b 100644 --- a/src/app/fyle/add-edit-mileage/add-edit-mileage.page.setup.spec.ts +++ b/src/app/fyle/add-edit-mileage/add-edit-mileage.page.setup.spec.ts @@ -108,7 +108,10 @@ describe('AddEditMileagePage', () => { const advanceWalletsServiceSpy = jasmine.createSpyObj('AdvanceWalletsService', ['getAllAdvanceWallets']); const spenderServiceSpy = jasmine.createSpyObj('SpenderService', ['get', 'post']); const customInputsServiceSpy = jasmine.createSpyObj('CustomInputsService', ['getAll', 'filterByCategory']); - const customFieldsServiceSpy = jasmine.createSpyObj('CustomFieldsService', ['standardizeCustomFields']); + const customFieldsServiceSpy = jasmine.createSpyObj('CustomFieldsService', [ + 'standardizeCustomFields', + 'setDefaultValue', + ]); const transactionServiceSpy = jasmine.createSpyObj('TransactionService', [ 'delete', 'getRemoveCardExpenseDialogBody', diff --git a/src/app/fyle/add-edit-mileage/add-edit-mileage.page.ts b/src/app/fyle/add-edit-mileage/add-edit-mileage.page.ts index eb9e92bc16..f13f959c9f 100644 --- a/src/app/fyle/add-edit-mileage/add-edit-mileage.page.ts +++ b/src/app/fyle/add-edit-mileage/add-edit-mileage.page.ts @@ -2416,7 +2416,7 @@ export class AddEditMileagePage implements OnInit { let customProperties = res.customProperties; customProperties = customProperties?.map((customProperty) => { if (!customProperty.value) { - customProperty = this.customFieldsService.setDefaultValue(customProperty, customProperty.type); + this.customFieldsService.setDefaultValue(customProperty, customProperty.type); } if (customProperty.type === 'DATE') { customProperty.value = diff --git a/src/app/fyle/add-edit-per-diem/add-edit-per-diem.page.setup.spec.ts b/src/app/fyle/add-edit-per-diem/add-edit-per-diem.page.setup.spec.ts index 185bebd754..9334bd1d5d 100644 --- a/src/app/fyle/add-edit-per-diem/add-edit-per-diem.page.setup.spec.ts +++ b/src/app/fyle/add-edit-per-diem/add-edit-per-diem.page.setup.spec.ts @@ -57,7 +57,10 @@ describe('AddEditPerDiemPage', () => { ]); const perDiemServiceSpy = jasmine.createSpyObj('PerDiemService', ['getRates', 'getAllowedPerDiems']); const customInputsServiceSpy = jasmine.createSpyObj('CustomInputsService', ['getAll', 'filterByCategory']); - const customFieldsServiceSpy = jasmine.createSpyObj('CustomFieldsService', ['standardizeCustomFields']); + const customFieldsServiceSpy = jasmine.createSpyObj('CustomFieldsService', [ + 'standardizeCustomFields', + 'setDefaultValue', + ]); const currencyServiceSpy = jasmine.createSpyObj('CurrencyService', [ 'getHomeCurrency', 'getAmountWithCurrencyFraction', diff --git a/src/app/fyle/add-edit-per-diem/add-edit-per-diem.page.ts b/src/app/fyle/add-edit-per-diem/add-edit-per-diem.page.ts index 428451509c..2dae6ea4c5 100644 --- a/src/app/fyle/add-edit-per-diem/add-edit-per-diem.page.ts +++ b/src/app/fyle/add-edit-per-diem/add-edit-per-diem.page.ts @@ -1698,7 +1698,7 @@ export class AddEditPerDiemPage implements OnInit { let customProperties = res.customProperties; customProperties = customProperties.map((customProperty) => { if (!customProperty.value) { - customProperty = this.customFieldsService.setDefaultValue(customProperty, customProperty.type); + this.customFieldsService.setDefaultValue(customProperty, customProperty.type); } if (customProperty.type === 'DATE') { customProperty.value =