Skip to content

Commit 3eb473a

Browse files
committed
Revise list test
1 parent 4e41c9c commit 3eb473a

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

modules/triggerTestModule/resources/queries/lists/Employees.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ function beforeInsert(row, errors) {
3333
row.employeeId = "EMP-STRUCT";
3434
row.undeclaredCol = "bad";
3535
}
36+
else if (row.name === "Managed Struct Remove") {
37+
row.employeeId = "EMP-STRUCT-REM";
38+
delete row.SSN;
39+
}
3640

3741
if (!row.employeeId) {
3842
row.employeeId = "EMP-INS1";
@@ -60,6 +64,11 @@ function beforeUpdate(row, oldRow, errors) {
6064
row.employeeId = "EMP-STRUCT";
6165
row.undeclaredCol = "bad";
6266
}
67+
else if (row.name === "Managed Struct Remove") {
68+
row.company = "Struct Remove Co";
69+
row.employeeId = "EMP-STRUCT-REM";
70+
delete row.SSN;
71+
}
6372

6473
if (!row.employeeId) {
6574
row.employeeId = "EMP-UPD1";

src/org/labkey/test/tests/TriggerScriptTest.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public class TriggerScriptTest extends BaseWebDriverTest
8181
private static final String AFTER_DELETE_ERROR = "This is the After Delete Error";
8282

8383
private static final String MANAGED_STRUCT_ADD_ERROR = "attempted to add";
84+
private static final String MANAGED_STRUCT_REMOVE_ERROR = "attempted to remove";
8485

8586
//Dataset constants
8687
private static final String STUDY_SCHEMA = "study";
@@ -372,13 +373,20 @@ public void testListManagedColumnsTriggers() throws Exception
372373
insCmd.addRow(Map.of("Name", "Managed Struct", "SSN", "111222335", "Company", "Test Co"));
373374
assertAPIErrorMessage(insCmd, MANAGED_STRUCT_ADD_ERROR, cn);
374375

376+
// Insert: structural remove error — trigger deletes a column not declared as managed
377+
insCmd = new InsertRowsCommand(LIST_SCHEMA, LIST_NAME);
378+
insCmd.addRow(Map.of("Name", "Managed Struct Remove", "SSN", "111222336", "Company", "Test Co"));
379+
assertAPIErrorMessage(insCmd, MANAGED_STRUCT_REMOVE_ERROR, cn);
380+
375381
// Setup: insert rows for update tests; include "employeeId" in payload so insert validation passes
376382
insCmd = new InsertRowsCommand(LIST_SCHEMA, LIST_NAME);
377383
insCmd.addRow(Map.of("Name", "MC Update Setup", "SSN", "111222340", "Company", "Setup Co", "employeeId", "OLD-ID"));
378384
insCmd.addRow(Map.of("Name", "MC Struct Setup", "SSN", "111222341", "Company", "Setup Co", "employeeId", "OLD-ID-2"));
385+
insCmd.addRow(Map.of("Name", "MC Struct Remove Setup", "SSN", "111222342", "Company", "Setup Co", "employeeId", "OLD-ID-3"));
379386
resp = insCmd.execute(cn, getProjectName());
380387
Integer updateKey = (Integer) resp.getRows().getFirst().get("Key");
381388
Integer structKey = (Integer) resp.getRows().get(1).get("Key");
389+
Integer structRemoveKey = (Integer) resp.getRows().get(2).get("Key");
382390

383391
// Update: trigger sets both declared managed columns "company" and "employeeId"
384392
UpdateRowsCommand updCmd = new UpdateRowsCommand(LIST_SCHEMA, LIST_NAME);
@@ -389,15 +397,21 @@ public void testListManagedColumnsTriggers() throws Exception
389397
Assert.assertEquals("Trigger should have set employeeId", "EMP-UPD", updated.employeeId);
390398

391399
// Update: declared managed column not set by trigger
392-
// "employeeId" is absent from the payload; trigger has no handler for this name and never sets it
400+
// "boomerang" is absent from the payload; SSN="-123" causes the trigger to skip setting it
401+
// Name is explicitly provided so the trigger does not accidentally match a named handler
393402
updCmd = new UpdateRowsCommand(LIST_SCHEMA, LIST_NAME);
394-
updCmd.addRow(Map.of("Key", updateKey, "SSN", "-123", "Company", "Test Co"));
403+
updCmd.addRow(Map.of("Key", updateKey, "Name", "MC Update Setup", "SSN", "-123", "Company", "Test Co"));
395404
assertAPIErrorMessage(updCmd, "declared the managed column 'boomerang'", cn);
396405

397406
// Update: structural add error — trigger adds a column not declared as managed
398407
updCmd = new UpdateRowsCommand(LIST_SCHEMA, LIST_NAME);
399408
updCmd.addRow(Map.of("Key", structKey, "Name", "Managed Struct", "SSN", "111222341"));
400409
assertAPIErrorMessage(updCmd, MANAGED_STRUCT_ADD_ERROR, cn);
410+
411+
// Update: structural remove error — trigger deletes a column not declared as managed
412+
updCmd = new UpdateRowsCommand(LIST_SCHEMA, LIST_NAME);
413+
updCmd.addRow(Map.of("Key", structRemoveKey, "Name", "Managed Struct Remove", "SSN", "111222342"));
414+
assertAPIErrorMessage(updCmd, MANAGED_STRUCT_REMOVE_ERROR, cn);
401415
}
402416

403417
/** Issue 52098 - ensure trigger scripts have a chance to do custom type conversion with the incoming row */

0 commit comments

Comments
 (0)