Skip to content

Commit 4e41c9c

Browse files
committed
Initial test coverage
1 parent ee14387 commit 4e41c9c

3 files changed

Lines changed: 147 additions & 47 deletions

File tree

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

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,78 @@
55
*/
66
var shared = require("TriggerTestModule/EmployeeLib");
77
var console = require("console");
8-
8+
9+
function managedColumns() {
10+
return {
11+
insert: ["boomerang", "employeeId"],
12+
update: ["boomerang", "company", "employeeId"],
13+
ignored: ["notes"],
14+
};
15+
}
16+
917
function init(event, errors) {
1018
console.log("init got triggered with event: " + event);
1119
console.log(shared.sampleFunc("this is from the shared function"));
1220
}
1321

1422
function beforeInsert(row, errors) {
1523
console.log("list: beforeInsert: row is: " + row);
16-
if(row.name == "Emp 2")
24+
if (row.name === "Emp 2")
1725
row.company = "Inserting Single";
18-
else if(row.name == "Emp 5")
26+
else if (row.name === "Emp 5")
1927
row.company = "Importing TSV";
20-
else if(row.name == "Emp 6")
28+
else if (row.name === "Emp 6")
2129
row.company = "API BeforeInsert";
30+
else if (row.name === "Managed Insert")
31+
row.employeeId = "EMP-INS";
32+
else if (row.name === "Managed Struct") {
33+
row.employeeId = "EMP-STRUCT";
34+
row.undeclaredCol = "bad";
35+
}
36+
37+
if (!row.employeeId) {
38+
row.employeeId = "EMP-INS1";
39+
}
40+
41+
row.notes = "This is a note";
42+
43+
if (row.SSN !== "-123") {
44+
row.boomeRANG = "Back at ya!";
45+
}
2246
console.log("list: edited row is: " + row);
2347
console.log(shared.sampleFunc("list: this is from the shared function"));
2448
}
2549

2650
function beforeUpdate(row, oldRow, errors) {
2751
console.log("list: beforeUpdate: row is: " + row);
28-
if(row.name == "Emp 3" || row.name == "Emp 8" )
52+
if (row.name === "Emp 3" || row.name === "Emp 8")
2953
row.company = "Before Update changed me";
54+
else if (row.name === "Managed Update") {
55+
row.company = "Managed Co";
56+
row.employeeId = "EMP-UPD";
57+
}
58+
else if (row.name === "Managed Struct") {
59+
row.company = "Struct Co";
60+
row.employeeId = "EMP-STRUCT";
61+
row.undeclaredCol = "bad";
62+
}
63+
64+
if (!row.employeeId) {
65+
row.employeeId = "EMP-UPD1";
66+
}
67+
68+
row.notes = "This is a note";
69+
70+
if (row.SSN !== "-123") {
71+
row.boomeRANG = "Back at me!";
72+
}
3073
console.log("list: old row is: " + oldRow);
3174
console.log(shared.sampleFunc("list: this is from the shared function"));
3275
}
3376

3477
function beforeDelete(row, errors) {
3578
console.log("list: beforeDelete: row is: " + row);
36-
if(row.company == "Inserting Single" || row.company == "DeleteMe")
79+
if (row.company === "Inserting Single" || row.company === "DeleteMe")
3780
errors[null] = "This is the Before Delete Error";
3881

3982
console.log(shared.sampleFunc("list: this is from the shared function"));
@@ -42,7 +85,7 @@ function beforeDelete(row, errors) {
4285
function afterInsert(row, errors) {
4386
console.log("list: afterInsert: row is: " + row);
4487

45-
if(row.name == "Emp 1")
88+
if (row.name === "Emp 1")
4689
errors[null] = "This is the After Insert Error";
4790

4891
console.log(shared.sampleFunc("list: this is from the shared function"));
@@ -51,7 +94,7 @@ function afterInsert(row, errors) {
5194
function afterUpdate(row, oldRow, errors) {
5295
console.log("list: afterUpdate: row is: " + row);
5396

54-
if(row.name == "Emp 2" || row.name == "Emp 6" )
97+
if (row.name === "Emp 2" || row.name === "Emp 6" )
5598
errors[null] = "This is the After Update Error";
5699
//throw new Error("This is the After Update Error");
57100

@@ -62,7 +105,7 @@ function afterUpdate(row, oldRow, errors) {
62105
function afterDelete(row, errors) {
63106
console.log("list: afterDelete: row is: " + row);
64107

65-
if(row.company == "Before Update changed me")
108+
if (row.company === "Before Update changed me")
66109
errors[null] = "This is the After Delete Error";
67110

68111
console.log(shared.sampleFunc("list: this is from the shared function"));

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

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import org.labkey.test.util.query.QueryApiHelper;
4747

4848
import java.util.ArrayList;
49-
import java.util.Arrays;
5049
import java.util.Collections;
5150
import java.util.Date;
5251
import java.util.List;
@@ -67,6 +66,7 @@ public class ScriptValidationTest extends BaseWebDriverTest
6766
public static final String MODULE_NAME = "simpletest";
6867
public static final String VEHICLE_SCHEMA = "vehicle";
6968

69+
public static final String COLORS_TABLE = "colors";
7070
public static final String VEHICLES_TABLE = "vehicles";
7171

7272
public static class ColorRecord
@@ -103,7 +103,7 @@ protected void doSetup() throws Exception
103103
_containerHelper.createProject(getProjectName(), null);
104104
_containerHelper.enableModule(getProjectName(), MODULE_NAME);
105105
new QueryApiHelper(createDefaultConnection(), getProjectName(), VEHICLE_SCHEMA, VEHICLES_TABLE).truncateTable();
106-
new QueryApiHelper(createDefaultConnection(), getProjectName(), VEHICLE_SCHEMA, "Colors").truncateTable();
106+
new QueryApiHelper(createDefaultConnection(), getProjectName(), VEHICLE_SCHEMA, COLORS_TABLE).truncateTable();
107107
}
108108

109109
@Test
@@ -127,9 +127,7 @@ public void doTestCrossFolderSaveRows() throws Exception
127127
{
128128
Connection cn = createDefaultConnection();
129129

130-
List<ColorRecord> colors = insertColors(Arrays.asList(
131-
new ColorRecord("Yellow2", "#f00")
132-
));
130+
List<ColorRecord> colors = insertColors(List.of(new ColorRecord("Yellow2", "#f00")));
133131

134132
// Create manufacturers:
135133
ArrayList<Map<String, Object>> list1 = new ArrayList<>();
@@ -156,8 +154,8 @@ public void doTestCrossFolderSaveRows() throws Exception
156154
assertNotNull("RowId not returned for vehicles insert, keys found: " + StringUtils.join(row.keySet(), ","), vehicleRowId);
157155

158156
SelectRowsCommand src = new SelectRowsCommand(VEHICLE_SCHEMA, VEHICLES_TABLE);
159-
src.setColumns(Arrays.asList("Container", "TriggerScriptContainer", "RowId", "ModelId", "Milage"));
160-
src.setSorts(Arrays.asList(new Sort("RowId", Sort.Direction.DESCENDING)));
157+
src.setColumns(List.of("Container", "TriggerScriptContainer", "RowId", "ModelId", "Milage"));
158+
src.setSorts(List.of(new Sort("RowId", Sort.Direction.DESCENDING)));
161159
SelectRowsResponse sr2 = src.execute(cn, getProjectName());
162160
assertEquals("Incorrect model", modelId, sr2.getRows().get(0).get("ModelId"));
163161
assertEquals("Incorrect Milage", 1234, sr2.getRows().get(0).get("Milage"));
@@ -224,7 +222,7 @@ private PostCommand<CommandResponse> prepareSaveRowsCommand(String command, Stri
224222

225223
private void doTestTransformation() throws Exception
226224
{
227-
List<ColorRecord> inserted = insertColors(Arrays.asList(
225+
List<ColorRecord> inserted = insertColors(List.of(
228226
new ColorRecord("Yellow", "#f00"),
229227
new ColorRecord("Cyan", "#0f0")
230228
));
@@ -247,7 +245,7 @@ private void doTestValidation() throws Exception
247245
/* The following exception is logged to the server as it is meant to simulate an unexpected error in
248246
* script validation */
249247
log("** Test errors: throw Error()'");
250-
insertColors(Arrays.asList(new ColorRecord("ShouldError", "not a hex value")));
248+
insertColors(List.of(new ColorRecord("ShouldError", "not a hex value")));
251249
fail("Should throw an exception");
252250
}
253251
catch (CommandException e)
@@ -259,7 +257,7 @@ private void doTestValidation() throws Exception
259257
try
260258
{
261259
log("** Test errors: Field='message' and test extraContext is echoed back");
262-
insertColors(Arrays.asList(new ColorRecord("TestFieldErrorMessage", null)), Maps.of("A", "a", "B", 3));
260+
insertColors(List.of(new ColorRecord("TestFieldErrorMessage", null)), Maps.of("A", "a", "B", 3));
263261
fail("Should throw an exception");
264262
}
265263
catch (CommandException e)
@@ -298,7 +296,7 @@ private void doTestValidation() throws Exception
298296
try
299297
{
300298
log("** Test errors: Field=[array of messages]");
301-
insertColors(Arrays.asList(new ColorRecord("TestFieldErrorArray", null)));
299+
insertColors(List.of(new ColorRecord("TestFieldErrorArray", null)));
302300
fail("Should throw an exception");
303301
}
304302
catch (CommandException e)
@@ -333,7 +331,7 @@ private void doTestValidation() throws Exception
333331
try
334332
{
335333
log("** Test errors: row level error");
336-
insertColors(Arrays.asList(new ColorRecord("TestRowError", null)));
334+
insertColors(List.of(new ColorRecord("TestRowError", null)));
337335
fail("Should throw an exception");
338336
}
339337
catch (CommandException e)
@@ -366,7 +364,7 @@ private void doTestValidation() throws Exception
366364
try
367365
{
368366
log("** Test errors: returning false");
369-
insertColors(Arrays.asList(new ColorRecord("TestReturnFalse", "")));
367+
insertColors(List.of(new ColorRecord("TestReturnFalse", "")));
370368
fail("Should throw an exception");
371369
}
372370
catch (CommandException e)
@@ -402,7 +400,7 @@ private void doTestValidation() throws Exception
402400
try
403401
{
404402
log("** Test errors: error in complete");
405-
insertColors(Arrays.asList(
403+
insertColors(List.of(
406404
new ColorRecord("Yellow", "#f00"),
407405
new ColorRecord("Cyan", "#0f0"),
408406
new ColorRecord("TestErrorInComplete", "")
@@ -438,7 +436,7 @@ private void doTestValidation() throws Exception
438436
try
439437
{
440438
log("** Test errors: adding array of errors in complete");
441-
insertColors(Arrays.asList(new ColorRecord("TestFieldErrorArrayInComplete", "")));
439+
insertColors(List.of(new ColorRecord("TestFieldErrorArrayInComplete", "")));
442440
fail("Should throw an exception");
443441
}
444442
catch (CommandException e)
@@ -485,7 +483,7 @@ private void doTestValidation() throws Exception
485483
try
486484
{
487485
log("** Test errors: script level variables, color regular expression");
488-
insertColors(Arrays.asList(new ColorRecord("ShouldError", "#still not a hex value")));
486+
insertColors(List.of(new ColorRecord("ShouldError", "#still not a hex value")));
489487
fail("Should throw an exception");
490488
}
491489
catch (CommandException e)
@@ -498,7 +496,7 @@ private void doTestValidation() throws Exception
498496
log("** Test errors: updating hex value");
499497
ColorRecord yellow = selectColor("Yellow?").get(0);
500498
yellow.hex = "shouldn't happen";
501-
updateColors(Arrays.asList(yellow));
499+
updateColors(List.of(yellow));
502500
fail("Should throw an exception");
503501
}
504502
catch (CommandException e)
@@ -512,7 +510,7 @@ private List<ColorRecord> selectColor(String... names) throws Exception
512510
log("** Selecting colors...");
513511

514512
Connection cn = createDefaultConnection();
515-
SelectRowsCommand cmd = new SelectRowsCommand(VEHICLE_SCHEMA, "Colors");
513+
SelectRowsCommand cmd = new SelectRowsCommand(VEHICLE_SCHEMA, COLORS_TABLE);
516514
cmd.addFilter("Name", StringUtils.join(names, ";"), Filter.Operator.IN);
517515
SelectRowsResponse response = cmd.execute(cn, getProjectName());
518516
assertEquals("Expected to select " + names.length + " rows.", names.length, response.getRowCount().intValue());
@@ -536,7 +534,7 @@ private List<ColorRecord> insertColors(List<ColorRecord> colors, Map<String, Obj
536534

537535
log("** Inserting colors...");
538536
Connection cn = createDefaultConnection();
539-
InsertRowsCommand cmd = new InsertRowsCommand(VEHICLE_SCHEMA, "Colors");
537+
InsertRowsCommand cmd = new InsertRowsCommand(VEHICLE_SCHEMA, COLORS_TABLE);
540538
cmd.getRows().addAll(list);
541539
cmd.setExtraContext(extraContext);
542540
RowsResponse response = cmd.execute(cn, getProjectName());
@@ -561,7 +559,7 @@ private List<ColorRecord> updateColors(List<ColorRecord> colors, Map<String, Obj
561559

562560
log("** Updating colors...");
563561
Connection cn = createDefaultConnection();
564-
UpdateRowsCommand cmd = new UpdateRowsCommand(VEHICLE_SCHEMA, "Colors");
562+
UpdateRowsCommand cmd = new UpdateRowsCommand(VEHICLE_SCHEMA, COLORS_TABLE);
565563
cmd.getRows().addAll(list);
566564
cmd.setExtraContext(extraContext);
567565
RowsResponse response = cmd.execute(cn, getProjectName());
@@ -581,7 +579,7 @@ private List<ColorRecord> updateColors(List<ColorRecord> colors, Map<String, Obj
581579
@Override
582580
public List<String> getAssociatedModules()
583581
{
584-
return Arrays.asList("simpletest");
582+
return List.of(MODULE_NAME);
585583
}
586584

587585
@Override

0 commit comments

Comments
 (0)