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

Validation #141

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Validation #141

wants to merge 4 commits into from

Conversation

alaric-rd
Copy link
Contributor

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.

@alaric-rd alaric-rd requested a review from rossjones January 16, 2025 11:01
// undefined values and maps then to "undefined", and converts any validation errors to warnings
exports.optionalType = (baseType) => {
return (inputValue) => {
if(inputValue !== undefined && inputValue != "") {
Copy link
Collaborator

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 != "") {
Copy link
Collaborator

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");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
r = t("foo");
let r = t("foo");

expect(r.warnings).toMatchObject([]);
expect(r.errors).toMatchObject(["This is not a valid number"]);

r = t(123);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
r = t(123);
let r = t(123);

// Also tests that optionalType converts errors into warnings
const t = attributeTypes.optionalType(attributeTypes.basicNumberType);

r = t("foo");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
r = t("foo");
let r = t("foo");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants