-
-
Notifications
You must be signed in to change notification settings - Fork 24
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
WIP: Implement schema validation in Collector #232
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Max line length: 80
this.keys = keys; | ||
if (exact === false) this.exact = false; | ||
if (typeof timeout === 'number') this.#timeout(timeout); | ||
if (schema) this.schema = schema; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (schema) this.schema = schema; | |
this.schema = schema; |
if (!this.schema) return { valid: true, errors: [] }; | ||
|
||
return this.schema.check(data); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (!this.schema) return { valid: true, errors: [] }; | |
return this.schema.check(data); | |
if (!this.schema) return { valid: true, errors: [] }; | |
return this.schema.check(data); |
@@ -48,6 +48,7 @@ | |||
"eslint-config-prettier": "^9.1.0", | |||
"eslint-plugin-import": "^2.29.0", | |||
"eslint-plugin-prettier": "^5.0.0", | |||
"metaschema": "^2.1.5", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"metaschema": "^2.1.5", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we include a type schema in the 'd.ts' file, something like this:
interface ValidationResult {
valid: boolean;
errors: string[];
}
export class Schema {
check(value: any): ValidationResult;
}
or is there another approach?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For testing purposes, we can create a mock Schema class that imitates the functionality of the 'check' method based on the test requirements.
profile2.set('age', 'string'); | ||
|
||
const expectedResult2 = new Error( | ||
'Invalid keys type: Field "id" not of expected type: number; Field "profile.firstname" not of expected type: string; Field "profile.age" not of expected type: number', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Max line: 80
); | ||
|
||
try { | ||
await ac1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In all tests where you should catch an error, you should also throw an extra error if that test passed without the expected error. Otherwise, you simply won't notice that the test went wrong(after npm run test
you will see simply one test less, that is, all test will go successfully without errors). It was recently added in all our tests.
So after all await
in try
you should add this line:
test.error(new Error('Should not be executed'));
); | ||
|
||
try { | ||
await ac1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
await ac1; | |
await ac1; | |
test.error(new Error('Should not be executed')); |
'Invalid keys type: Field "fullName" is not expected', | ||
); | ||
try { | ||
await ac2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
await ac2; | |
await ac2; | |
test.error(new Error('Should not be executed')); |
); | ||
|
||
try { | ||
await ac2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
await ac2; | |
await ac2; | |
test.error(new Error('Should not be executed')); |
I believe that Collector should not know about schemas, it may depend on abstract interface (function validate). @Bespaliy |
Closed in favour of #248 |
npm t
)npm run fmt
)