diff --git a/modules/simpletest/resources/queries/lists/People.js b/modules/simpletest/resources/queries/lists/People.js index 65947bdcb2..e6eebe85b5 100644 --- a/modules/simpletest/resources/queries/lists/People.js +++ b/modules/simpletest/resources/queries/lists/People.js @@ -11,12 +11,26 @@ if (extraContext) var LABKEY = require("labkey"); +// Issue 52098 - do custom parsing to validate trigger script gets a chance to do type conversion +function stripPrefix(row) +{ + if (row.Age && row.Age.toString().indexOf("RemoveMe") === 0) + { + row.Age = row.Age.substring("RemoveMe".length); + } + if (row.FavoriteDateTime && row.FavoriteDateTime.toString().indexOf("RemoveMe") === 0) + { + row.FavoriteDateTime = row.FavoriteDateTime.substring("RemoveMe".length); + } +} + function beforeInsert(row, errors) { // Test row map is case-insensitive if (row.Name != row.nAmE) throw new Error("beforeInsert row properties must be case-insensitive."); + stripPrefix(row); // var result = LABKEY.Query.deleteRows({ // schemaName: "lists", @@ -42,6 +56,8 @@ function beforeUpdate(row, oldRow, errors) // Test oldRow map is case-insensitive if (oldRow.Name != oldRow.nAmE) throw new Error("beforeUpdate oldRow properties must be case-insensitive."); + + stripPrefix(row); } function afterUpdate(row, oldRow, errors) diff --git a/src/org/labkey/test/LabKeySiteWrapper.java b/src/org/labkey/test/LabKeySiteWrapper.java index 353612e2bb..7818a44d95 100644 --- a/src/org/labkey/test/LabKeySiteWrapper.java +++ b/src/org/labkey/test/LabKeySiteWrapper.java @@ -972,7 +972,7 @@ public void checkErrors() else if (currentError.size() == 1) { // Line after the ERROR usually has the exception type and error message - TestLogger.error(" " + iterator.next()); + TestLogger.error(" " + line); } else if (line.startsWith("Caused by:")) { diff --git a/src/org/labkey/test/components/ui/entities/EntityBulkUpdateDialog.java b/src/org/labkey/test/components/ui/entities/EntityBulkUpdateDialog.java index 14716f277d..a0401f67b7 100644 --- a/src/org/labkey/test/components/ui/entities/EntityBulkUpdateDialog.java +++ b/src/org/labkey/test/components/ui/entities/EntityBulkUpdateDialog.java @@ -4,6 +4,7 @@ import org.labkey.remoteapi.CommandException; import org.labkey.test.BootstrapLocators; import org.labkey.test.Locator; +import org.labkey.test.TestProperties; import org.labkey.test.WebDriverWrapper; import org.labkey.test.WebTestHelper; import org.labkey.test.components.Component; @@ -390,7 +391,7 @@ public void clickUpdate(boolean skipAuditEventCheck) // check for the expected number of Data Changes in the latest audit event records AuditLogHelper auditLogHelper = new AuditLogHelper(getWrapper(), () -> WebTestHelper.getRemoteApiConnection(false)); String auditEventName = auditLogHelper.getAuditEventNameFromURL(); - if (!skipAuditEventCheck && auditEventName != null) + if (!skipAuditEventCheck && auditEventName != null && !TestProperties.isTrialServer()) { try { diff --git a/src/org/labkey/test/components/ui/grids/DetailTableEdit.java b/src/org/labkey/test/components/ui/grids/DetailTableEdit.java index 0e0c3afbc9..ec4f0fa610 100644 --- a/src/org/labkey/test/components/ui/grids/DetailTableEdit.java +++ b/src/org/labkey/test/components/ui/grids/DetailTableEdit.java @@ -4,6 +4,7 @@ import org.labkey.remoteapi.CommandException; import org.labkey.test.BootstrapLocators; import org.labkey.test.Locator; +import org.labkey.test.TestProperties; import org.labkey.test.WebDriverWrapper; import org.labkey.test.WebTestHelper; import org.labkey.test.components.Component; @@ -511,7 +512,7 @@ public DetailDataPanel clickSave(boolean skipAuditEventCheck) // check for the expected number of Data Changes in the latest audit event records AuditLogHelper auditLogHelper = new AuditLogHelper(getWrapper(), () -> WebTestHelper.getRemoteApiConnection(false)); String auditEventName = auditLogHelper.getAuditEventNameFromURL(); - if (!skipAuditEventCheck && auditEventName != null) + if (!skipAuditEventCheck && auditEventName != null && !TestProperties.isTrialServer()) { try { diff --git a/src/org/labkey/test/tests/SampleTypeLinkToStudyTest.java b/src/org/labkey/test/tests/SampleTypeLinkToStudyTest.java index eb3d5d7a2d..12c64e7334 100644 --- a/src/org/labkey/test/tests/SampleTypeLinkToStudyTest.java +++ b/src/org/labkey/test/tests/SampleTypeLinkToStudyTest.java @@ -53,6 +53,7 @@ public class SampleTypeLinkToStudyTest extends BaseWebDriverTest final static String SAMPLE_TYPE2 = "Sample type 2"; private final static String visitLabel1 = "Screening"; private final static String visitLabel2 = "Baseline"; + private static final String READER_USER = "reader_user@user.test"; protected DateTimeFormatter _dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); protected String now = LocalDateTime.now().format(_dateTimeFormatter); @@ -71,6 +72,7 @@ private void doSetup() _studyHelper.startCreateStudy() .setTimepointType(StudyHelper.TimepointType.VISIT) .createStudy(); + createUserWithPermissions(READER_USER, VISIT_BASED_STUDY, "Reader"); _containerHelper.createProject(DATE_BASED_STUDY, "Study"); _studyHelper.startCreateStudy() @@ -138,6 +140,13 @@ public void testLinkToStudy() checker().verifyEquals("Incorrect Participant ID's", Arrays.asList("P3", "P4"), table.getColumnDataAsText("ParticipantId")); checker().verifyEquals("Incorrect category for the dataset(Uncategorized case)", " ", getCategory(VISIT_BASED_STUDY, SAMPLE_TYPE1)); + // issue 53194 + impersonate(READER_USER); + log("Verifying the linked sample type in study"); + goToProjectHome(VISIT_BASED_STUDY); + clickAndWait(Locator.linkWithText(SAMPLE_TYPE1)); + stopImpersonating(); + log("Verifying log entries"); goToProjectHome(SAMPLE_TYPE_PROJECT); clickAndWait(Locator.linkWithText(SAMPLE_TYPE1)); @@ -852,6 +861,7 @@ public List getAssociatedModules() @Override protected void doCleanup(boolean afterTest) throws TestTimeoutException { + _userHelper.deleteUsers(false, READER_USER); _containerHelper.deleteProject(SAMPLE_TYPE_PROJECT, afterTest); _containerHelper.deleteProject(VISIT_BASED_STUDY, afterTest); _containerHelper.deleteProject(DATE_BASED_STUDY, afterTest); diff --git a/src/org/labkey/test/tests/TriggerScriptTest.java b/src/org/labkey/test/tests/TriggerScriptTest.java index 0c726ef5f6..8aac943b83 100644 --- a/src/org/labkey/test/tests/TriggerScriptTest.java +++ b/src/org/labkey/test/tests/TriggerScriptTest.java @@ -85,6 +85,7 @@ public class TriggerScriptTest extends BaseWebDriverTest private static final String COMMENTS_FIELD = "Comments"; private static final String COUNTRY_FIELD = "Country"; + public static final String PEOPLE_LIST_NAME = "People"; protected final PortalHelper _portalHelper = new PortalHelper(this); @@ -170,6 +171,7 @@ public static void projectSetup() init.doSetup(); } + protected void doSetup() { _containerHelper.createProject(getProjectName(), null); @@ -187,10 +189,11 @@ protected void doSetup() _listHelper.createList(getProjectName(), LIST_NAME, "Key", columns); - log("Create list in subfolder to prevent query validation failure"); - _listHelper.createList(getProjectName(), "People", "Key", + log("Create the People list"); + _listHelper.createList(getProjectName(), PEOPLE_LIST_NAME, "Key", new FieldDefinition("Name", ColumnType.String).setDescription("Name"), new FieldDefinition("Age", ColumnType.Integer).setDescription("Age"), + new FieldDefinition("FavoriteDateTime", ColumnType.DateAndTime).setDescription("Favorite date time. Who doesn't have one?"), new FieldDefinition("Crazy", ColumnType.Boolean).setDescription("Crazy?")); importFolderFromZip(TestFileUtils.getSampleData("studies/LabkeyDemoStudy.zip")); @@ -300,7 +303,38 @@ public void testListImportTriggers() cleanUpListRows(); } + /** Issue 52098 - ensure trigger scripts have a chance to do custom type conversion with the incoming row */ @Test + public void testListAPITriggerTypeConversion() throws Exception + { + Connection cn = WebTestHelper.getRemoteApiConnection(); + + // Insert a row with a value that can only be handled by the trigger script to make sure it gets a chance + // to do the conversion. People.js should strip the "RemoveMe" prefix from Age and FavoriteDateTime + InsertRowsCommand insCmd = new InsertRowsCommand(LIST_SCHEMA, PEOPLE_LIST_NAME); + insCmd.addRow(Map.of("Name", "Jimbo", "Age", "RemoveMe25", "FavoriteDateTime", "RemoveMe2025-06-11 11:42", "Crazy", "true")); + SaveRowsResponse insResp = insCmd.execute(cn, getProjectName()); + List> insertedRows = insResp.getRows(); + Assert.assertEquals(1, insertedRows.size()); + + Map insertedRow = insertedRows.get(0); + Assert.assertEquals("Jimbo", insertedRow.get("Name")); + Assert.assertEquals(25, insertedRow.get("Age")); + Assert.assertEquals("2025-06-11 11:42:00.000", insertedRow.get("FavoriteDateTime")); + + // Validate update too + UpdateRowsCommand upCmd = new UpdateRowsCommand(LIST_SCHEMA, PEOPLE_LIST_NAME); + insertedRow.put("Age", "RemoveMe26"); + upCmd.addRow(insertedRow); + SaveRowsResponse upResp = upCmd.execute(cn, getProjectName()); + List> updatedRows = upResp.getRows(); + Assert.assertEquals(1, updatedRows.size()); + + Map updatedRow = updatedRows.get(0); + Assert.assertEquals(26, updatedRow.get("Age")); + } + + @Test public void testListAPITriggers() throws Exception { String ssn1 = "111111112";