From b23b23c071175ceb21a57708929442e6b1de4d74 Mon Sep 17 00:00:00 2001 From: lane-formio Date: Tue, 23 Apr 2024 09:57:39 -0500 Subject: [PATCH] =?UTF-8?q?Revert=20"FIO-8037:=20fixed=20an=20issue=20wher?= =?UTF-8?q?e=20number=20component=20can=20be=20sent=20text=20thro=E2=80=A6?= =?UTF-8?q?"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/process/validation/i18n/en.ts | 3 +- .../rules/__tests__/validateNumber.test.ts | 27 ------------- src/process/validation/rules/clientRules.ts | 4 +- .../validation/rules/validateNumber.ts | 39 ------------------- 4 files changed, 2 insertions(+), 71 deletions(-) delete mode 100644 src/process/validation/rules/__tests__/validateNumber.test.ts delete mode 100644 src/process/validation/rules/validateNumber.ts diff --git a/src/process/validation/i18n/en.ts b/src/process/validation/i18n/en.ts index 3362078d..ede84533 100644 --- a/src/process/validation/i18n/en.ts +++ b/src/process/validation/i18n/en.ts @@ -34,7 +34,6 @@ export const EN_ERRORS = { captchaTokenValidation: 'ReCAPTCHA: Token validation error', captchaTokenNotSpecified: 'ReCAPTCHA: Token is not specified in submission', captchaFailure: 'ReCaptcha: Response token not found', - time: '{{field}} is not a valid time.', + time: '{{field}} is not a valid time', invalidDate: '{{field}} is not a valid date', - number: '{{field}} is not a valid number.' }; diff --git a/src/process/validation/rules/__tests__/validateNumber.test.ts b/src/process/validation/rules/__tests__/validateNumber.test.ts deleted file mode 100644 index 6ca89ccb..00000000 --- a/src/process/validation/rules/__tests__/validateNumber.test.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { expect } from 'chai'; - -import { FieldError } from 'error'; -import { simpleNumberField } from './fixtures/components'; -import { generateProcessorContext } from './fixtures/util'; -import { validateNumber } from '../validateNumber'; - -it('Validating a valid number will return null', async () => { - const component = simpleNumberField; - const data = { - component: 45, - }; - const context = generateProcessorContext(component, data); - const result = await validateNumber(context); - expect(result).to.equal(null); -}); - -it('Validating an invalid number will return a FieldError', async () => { - const component = simpleNumberField; - const data = { - component: 'text', - }; - const context = generateProcessorContext(component, data); - const result = await validateNumber(context); - expect(result).to.be.instanceOf(FieldError); - expect(result?.errorKeyOrMessage).to.contain('number'); -}); diff --git a/src/process/validation/rules/clientRules.ts b/src/process/validation/rules/clientRules.ts index cb6b1c35..065b9dec 100644 --- a/src/process/validation/rules/clientRules.ts +++ b/src/process/validation/rules/clientRules.ts @@ -23,7 +23,6 @@ import { validateRequiredDayInfo } from "./validateRequiredDay"; import { validateTimeInfo } from "./validateTime"; import { validateUrlInfo } from "./validateUrl"; import { validateValuePropertyInfo } from "./validateValueProperty"; -import { validateNumberInfo } from "./validateNumber"; // These are the validations that are performed in the client. export const clientRules: ValidationRuleInfo[] = [ @@ -50,6 +49,5 @@ export const clientRules: ValidationRuleInfo[] = [ validateRequiredDayInfo, validateTimeInfo, validateUrlInfo, - validateValuePropertyInfo, - validateNumberInfo + validateValuePropertyInfo ]; diff --git a/src/process/validation/rules/validateNumber.ts b/src/process/validation/rules/validateNumber.ts deleted file mode 100644 index 283bb9ce..00000000 --- a/src/process/validation/rules/validateNumber.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { FieldError } from '../../../error/FieldError'; -import { NumberComponent, RuleFn, RuleFnSync, ValidationContext } from '../../../types/index'; -import { ProcessorInfo } from 'types/process/ProcessorInfo'; - -const isValidatableNumberComponent = (component: any): component is NumberComponent => { - return component && component.type === 'number'; -}; - -export const shouldValidate = (context: ValidationContext) => { - const { component, value } = context; - if (!value) { - return false; - } - if (!isValidatableNumberComponent(component)) { - return false; - } - return true; -}; - -export const validateNumber: RuleFn = async (context: ValidationContext) => { - return validateNumberSync(context); -}; - -export const validateNumberSync: RuleFnSync = (context: ValidationContext) => { - const error = new FieldError('number', context); - const { value } = context; - - if (typeof value !== 'number') { - return error; - } - return null; -}; - -export const validateNumberInfo: ProcessorInfo = { - name: 'validateNumber', - process: validateNumber, - processSync: validateNumberSync, - shouldProcess: shouldValidate, -}; \ No newline at end of file