Skip to content

Commit

Permalink
Add test for query with group by and onConflict
Browse files Browse the repository at this point in the history
  • Loading branch information
LakshanWeerasinghe committed Mar 29, 2024
1 parent a7e115e commit 7727e5f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ public void testMapConstructNestedQueryWithConflictingKeys() {
BRunUtil.invoke(result, "testMapConstructNestedQueryWithConflictingKeys");
}

@Test(description = "Test map creating query with group by clause having an onConflict error")
public void testMapConstructQueryWithConflictingKeys() {
BRunUtil.invoke(result, "testMapConstructQueryWithConflictingKeys");
}

@Test(description = "Test negative scenarios for query expr with query construct type")
public void testNegativeScenarios() {
int index = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1921,6 +1921,19 @@ function testMapConstructNestedQueryWithConflictingKeys() {
assertEqual((<error>result[0]).message(), "Error key: 1 iteration: 1");
}

function testMapConstructQueryWithConflictingKeys() {
Customer c1 = {id: 1, name: "Abba", noOfItems: 10};
Customer c2 = {id: 2, name: "Jim", noOfItems: 20};
Customer c3 = {id: 3, name: "James", noOfItems: 30};
Customer c4 = {id: 3, name: "Abba", noOfItems: 40};
Customer[] customerList = [c1, c2, c3, c4];
anydata|error result = map from var {name, noOfItems} in customerList
group by name
select [name, [noOfItems]]
on conflict error(string `value: ${[noOfItems].toString()}`);
assertEqual(result is map<anydata>, true);
}

function assertEqual(anydata|error actual, anydata|error expected) {
anydata expectedValue = (expected is error)? (<error> expected).message() : expected;
anydata actualValue = (actual is error)? (<error> actual).message() : actual;
Expand Down

0 comments on commit 7727e5f

Please sign in to comment.