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

FIO 8178: correctly add "validator" param to interpolated error object #75

Merged
merged 3 commits into from
Apr 9, 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
6 changes: 4 additions & 2 deletions src/error/FieldError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ type FieldErrorContext = ValidationContext & {
export class FieldError {
context: FieldErrorContext
errorKeyOrMessage: string;
ruleName: string;
level?: string;
constructor(errorKeyOrMessage: string, context: FieldErrorContext) {
constructor(errorKeyOrMessage: string, context: FieldErrorContext, ruleName: string = errorKeyOrMessage) {
const { component, hasLabel = true, field = getComponentErrorField(component, context), level = 'error' } = context;
this.ruleName = ruleName;
if (context.component.validate?.customMessage) {
this.errorKeyOrMessage = context.component.validate.customMessage;
this.context = { ...context, hasLabel: false, field, level };
Expand All @@ -40,4 +42,4 @@ export class FieldError {
}
}

export type InterpolateErrorFn = (text: string, context: FieldErrorContext) => string;
export type InterpolateErrorFn = (text: string, context: FieldErrorContext) => string;
5 changes: 3 additions & 2 deletions src/process/validation/__tests__/Validator.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import get from 'lodash/get';
import { expect } from 'chai';
import { validateProcess } from '../index';
import { rules } from "../rules";
import { simpleForm } from './fixtures/forms';
import { ProcessorType, ValidationScope } from 'types';
import get from 'lodash/get';

it('Validator will throw the correct errors given a flat components array', async () => {
let errors: string[] = [];
const data = {
Expand All @@ -27,7 +28,7 @@ it('Validator will throw the correct errors given a flat components array', asyn
path,
value: get(data, component.key),
processor: ProcessorType.Validate,
rules: rules
rules
});
if (scope.errors) {
errors = [...errors, ...scope.errors.map((error) => error.errorKeyOrMessage)];
Expand Down
31 changes: 0 additions & 31 deletions src/process/validation/__tests__/fixtures/components.d.ts

This file was deleted.

196 changes: 0 additions & 196 deletions src/process/validation/__tests__/fixtures/components.js

This file was deleted.

Loading
Loading