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

Array of validations is possible #33

Merged
merged 2 commits into from
Apr 26, 2020
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
3 changes: 0 additions & 3 deletions src/utils/validator-lookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ export default function lookupValidator(validationMap: ValidatorMap): ValidatorA

return isPromise(validation)
? (validation as Promise<ValidationResult>).then(result => {
if (Array.isArray(result) && result.length > 0) {
return result[0];
}
return result;
})
: validation;
Expand Down
12 changes: 11 additions & 1 deletion test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ const dummyValidations: Record<string, any> = {
ny: [
(_k: string, value: unknown) => {
return !!value || 'must be present';
},
(_k: string, value: string) => {
return /[A-z]/.test(value) ? true : 'only letters work';
}
]
}
Expand Down Expand Up @@ -209,7 +212,14 @@ describe('Unit | Utility | changeset', () => {
dummyChangeset.set('name', '');

let expectedErrors = [
{ key: 'org.usa.ny', validation: ['must be present'], value: '' },
{ key: 'org.usa.ny', validation: ['must be present', 'only letters work'], value: '' },
{ key: 'name', validation: 'too short', value: '' }
];
expect(dummyChangeset.get('errors')).toEqual(expectedErrors);

dummyChangeset.set('org.usa.ny', '1');
expectedErrors = [
{ key: 'org.usa.ny', validation: ['only letters work'], value: '1' },
{ key: 'name', validation: 'too short', value: '' }
];
expect(dummyChangeset.get('errors')).toEqual(expectedErrors);
Expand Down