-
Notifications
You must be signed in to change notification settings - Fork 0
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
Validation #141
base: main
Are you sure you want to change the base?
Validation #141
Conversation
# Conflicts: # lib/importer/backend.test.js
// undefined values and maps then to "undefined", and converts any validation errors to warnings | ||
exports.optionalType = (baseType) => { | ||
return (inputValue) => { | ||
if(inputValue !== undefined && inputValue != "") { |
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.
Do we want/need to check for null
as well?
// Create a required version of an existing type, that reports an undefined or empty-string input value as an error | ||
exports.requiredType = (baseType) => { | ||
return (inputValue) => { | ||
if(inputValue !== undefined && inputValue != "") { |
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.
Dupe comment, null check?
test('required basic number', () => { | ||
const t = attributeTypes.requiredType(attributeTypes.basicNumberType); | ||
|
||
r = t("foo"); |
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.
r = t("foo"); | |
let r = t("foo"); |
expect(r.warnings).toMatchObject([]); | ||
expect(r.errors).toMatchObject(["This is not a valid number"]); | ||
|
||
r = t(123); |
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.
r = t(123); | |
let r = t(123); |
// Also tests that optionalType converts errors into warnings | ||
const t = attributeTypes.optionalType(attributeTypes.basicNumberType); | ||
|
||
r = t("foo"); |
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.
r = t("foo"); | |
let r = t("foo"); |
Added a validation mechanism, invoke by providing attribute type validators when setting up the import mapping.
If none are specified, it defaults to everything being strings with no validation, matching current behaviour.
The mapping results may now include errors that cause input rows to be rejected, or warnings where a row could be interpreted but there might be a problem with it (eg, an attribute value was malformed for the required type, but it was marked as optional anyway so we can live without it).
Adding support to display these warnings/errors in the frontend will be a separate bit of work.