Skip to content

Commit 9c7b9fd

Browse files
committed
chaged validationError constructor
Signed-off-by: Antonio Mendoza Pérez <antmendoza@gmail.com>
1 parent 86f11ee commit 9c7b9fd

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

src/lib/validation-error.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
import { ErrorObject } from 'ajv';
2+
13
export class ValidationError {
2-
constructor(readonly message: string) {}
4+
readonly message: string;
5+
6+
constructor(readonly error: ErrorObject) {
7+
this.message = `invalid: ${error.instancePath} | ${error.schemaPath} | ${error.message}`;
8+
}
39
}

src/lib/workflow-validator.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,20 @@ import { ValidationError } from './validation-error';
2222

2323
export class WorkflowValidator {
2424
/** The validation errors after running validate(), if any */
25-
errors: ValidationError[] | never[] = [];
25+
readonly errors: ValidationError[] | never[] = [];
2626

2727
/** Whether the workflow is valid or not */
28-
isValid: boolean;
28+
readonly isValid: boolean;
2929

3030
/**
3131
* Creates a new WorkflowValidator for the provided workflow
3232
* @param {Workflow} workflow The workflow to validate
3333
*/
3434
constructor(private workflow: Specification.Workflow) {
35-
this.validate();
36-
}
37-
38-
/**
39-
* Validates the workflow, populates the errors if any
40-
*/
41-
private validate(): void {
4235
const validateFn = validators.get('Workflow') as ValidateFunction<Specification.Workflow>;
4336
this.isValid = validateFn(this.workflow);
4437
if (validateFn.errors) {
45-
this.errors = validateFn.errors.map(
46-
(error) => new ValidationError(`invalid: ${error.instancePath} | ${error.schemaPath} | ${error.message}`)
47-
);
38+
this.errors = validateFn.errors.map((error) => new ValidationError(error));
4839
}
4940
}
5041
}

tests/workflow-validator.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ describe('workflow-validator', () => {
3535
expect(workflowValidator.errors[0].constructor === ValidationError).toBeTruthy(
3636
'Expected errors to be instance of ValidationError'
3737
);
38+
expect(workflowValidator.errors[0].message).toMatch("states");
39+
3840
});
3941

4042
it('should have no errors if the workflow is valid', () => {

0 commit comments

Comments
 (0)