From b7f2270a765c6b0256865503f1bfd81059f177fb Mon Sep 17 00:00:00 2001 From: FitseTLT Date: Fri, 13 Dec 2024 15:38:52 +0300 Subject: [PATCH 1/4] enforce tax claimable to be less than tax rate --- src/libs/PolicyDistanceRatesUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/PolicyDistanceRatesUtils.ts b/src/libs/PolicyDistanceRatesUtils.ts index 64f430ddbc42..6e180e4ecaf8 100644 --- a/src/libs/PolicyDistanceRatesUtils.ts +++ b/src/libs/PolicyDistanceRatesUtils.ts @@ -50,7 +50,7 @@ function validateRateValue( function validateTaxClaimableValue(values: FormOnyxValues, rate: Rate | undefined): FormInputErrors { const errors: FormInputErrors = {}; - if (rate?.rate && Number(values.taxClaimableValue) > rate.rate / 100) { + if (rate?.rate && Number(values.taxClaimableValue) >= rate.rate / 100) { errors.taxClaimableValue = Localize.translateLocal('workspace.taxes.error.updateTaxClaimableFailureMessage'); } return errors; From 4e6fa2ee558d3e982258178649ae5ad844b05d02 Mon Sep 17 00:00:00 2001 From: FitseTLT Date: Mon, 23 Dec 2024 17:15:34 +0300 Subject: [PATCH 2/4] added test --- tests/unit/PolicyDistanceRatesUtilsTest.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 tests/unit/PolicyDistanceRatesUtilsTest.ts diff --git a/tests/unit/PolicyDistanceRatesUtilsTest.ts b/tests/unit/PolicyDistanceRatesUtilsTest.ts new file mode 100644 index 000000000000..f3761d509baa --- /dev/null +++ b/tests/unit/PolicyDistanceRatesUtilsTest.ts @@ -0,0 +1,13 @@ +import {validateTaxClaimableValue} from '@libs/PolicyDistanceRatesUtils'; + +describe('PolicyDistanceRatesUtils', () => { + describe('validateTaxClaimableValue', () => { + it('should return false when taxClaimableValue is equal to rate', () => { + // Given a tax claimable value inserted for a distance rate + // When the taxClaimableValue is equal to the distance rate + const validate = validateTaxClaimableValue({taxClaimableValue: '0.67'}, {rate: 67}); + // Then validateTaxClaimableValue will return an error. + expect(validate.taxClaimableValue).toBeDefined(); + }); + }); +}); From 273b0609cc9b6db055e9d797b596c606be116878 Mon Sep 17 00:00:00 2001 From: FitseTLT Date: Mon, 23 Dec 2024 17:16:07 +0300 Subject: [PATCH 3/4] minor fix --- tests/unit/PolicyDistanceRatesUtilsTest.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/PolicyDistanceRatesUtilsTest.ts b/tests/unit/PolicyDistanceRatesUtilsTest.ts index f3761d509baa..59354f0688f4 100644 --- a/tests/unit/PolicyDistanceRatesUtilsTest.ts +++ b/tests/unit/PolicyDistanceRatesUtilsTest.ts @@ -2,9 +2,9 @@ import {validateTaxClaimableValue} from '@libs/PolicyDistanceRatesUtils'; describe('PolicyDistanceRatesUtils', () => { describe('validateTaxClaimableValue', () => { - it('should return false when taxClaimableValue is equal to rate', () => { + it('should return an error when taxClaimableValue is equal to tax rate', () => { // Given a tax claimable value inserted for a distance rate - // When the taxClaimableValue is equal to the distance rate + // When the taxClaimableValue is equal to the tax rate const validate = validateTaxClaimableValue({taxClaimableValue: '0.67'}, {rate: 67}); // Then validateTaxClaimableValue will return an error. expect(validate.taxClaimableValue).toBeDefined(); From e0605ee6fa4c65ad6b9c9b0c38a115b16b8b5beb Mon Sep 17 00:00:00 2001 From: FitseTLT Date: Fri, 27 Dec 2024 01:05:17 +0300 Subject: [PATCH 4/4] ts fix --- tests/unit/PolicyDistanceRatesUtilsTest.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/PolicyDistanceRatesUtilsTest.ts b/tests/unit/PolicyDistanceRatesUtilsTest.ts index 59354f0688f4..5a72d5336cd0 100644 --- a/tests/unit/PolicyDistanceRatesUtilsTest.ts +++ b/tests/unit/PolicyDistanceRatesUtilsTest.ts @@ -5,7 +5,7 @@ describe('PolicyDistanceRatesUtils', () => { it('should return an error when taxClaimableValue is equal to tax rate', () => { // Given a tax claimable value inserted for a distance rate // When the taxClaimableValue is equal to the tax rate - const validate = validateTaxClaimableValue({taxClaimableValue: '0.67'}, {rate: 67}); + const validate = validateTaxClaimableValue({taxClaimableValue: '0.67'}, {rate: 67, customUnitRateID: ''}); // Then validateTaxClaimableValue will return an error. expect(validate.taxClaimableValue).toBeDefined(); });