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

fix: Arrays failed to validate using their validationRegexp #4359

Merged
merged 5 commits into from
Oct 15, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ public static String checkRequiredExpression(
}

static Map<String, Object> convertRowToMap(List<Column> columns, Row row) {
Map<String, Object> map = new LinkedHashMap<>(row.getValueMap());
Map<String, Object> map = new LinkedHashMap<>();
for (Column c : columns) {
if (c.isReference()) {
map.put(c.getIdentifier(), getRefFromRow(row, c));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package org.molgenis.emx2.sql;

import static org.junit.jupiter.api.Assertions.*;
import static org.molgenis.emx2.Column.column;
import static org.molgenis.emx2.Row.row;
import static org.molgenis.emx2.TableMetadata.table;
import static org.molgenis.emx2.sql.SqlTypeUtils.applyValidationAndComputed;
import static org.molgenis.emx2.sql.SqlTypeUtils.convertRowToMap;

import java.util.*;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.molgenis.emx2.*;
Expand Down Expand Up @@ -51,4 +55,25 @@ void autoIdGetsGeneratedWithPreFix() {
applyValidationAndComputed(tableMetadata.getColumns(), copy);
assertEquals(row.getString("myCol"), row.getString("myCol"));
}

@Test
void testArrayConversionToMap() {
List<Column> columns = List.of(column("STRING array", ColumnType.STRING_ARRAY));
Row row = row("STRING array", "aa,bb");

Map<String, Object> output = convertRowToMap(columns, row);

assertAll(
() -> assertEquals(Set.of("sTRINGArray"), output.keySet()),
() ->
assertEquals(List.of("aa", "bb"), Arrays.asList((String[]) output.get("sTRINGArray"))));
}

@Test
void testWorkingValidationForEmailArray() {
List<Column> columns = List.of(column("SPAM blocklist", ColumnType.EMAIL_ARRAY));
Row row = row("SPAM blocklist", "[email protected],[email protected]");

assertDoesNotThrow(() -> applyValidationAndComputed(columns, row));
}
}