Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This appears to be a simple business logic error. In this PR, we test that array field returned from groupBy queries are properly retrieved from their rows, both when selected and when aggregated. closes prisma/prisma#13097 Internal spec document: https://www.notion.so/prismaio/groupBy-array-columns-a1179e49a56c42c8b1f1bd69f617f26a
- Loading branch information
Showing
4 changed files
with
71 additions
and
2 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
query-engine/connector-test-kit-rs/query-engine-tests/tests/new/regressions/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
mod max_integer; | ||
mod prisma_10098; | ||
mod prisma_13097; | ||
mod prisma_10935; | ||
mod prisma_12929; | ||
mod prisma_14696; | ||
|
68 changes: 68 additions & 0 deletions
68
query-engine/connector-test-kit-rs/query-engine-tests/tests/new/regressions/prisma_13097.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
use query_engine_tests::*; | ||
|
||
#[test_suite(schema(schema), only(Postgres))] | ||
mod prisma_13097 { | ||
fn schema() -> String { | ||
r#" | ||
enum AppCategories { | ||
calendar | ||
messaging | ||
payment | ||
other | ||
} | ||
model App { | ||
slug String @id @unique | ||
categories AppCategories[] | ||
createdAt DateTime @default(now()) | ||
updatedAt DateTime @updatedAt | ||
} | ||
model Opp { | ||
slug String @id @unique | ||
categories Boolean[] | ||
} | ||
"# | ||
.to_owned() | ||
} | ||
|
||
#[connector_test] | ||
async fn group_by_enum_array(runner: Runner) -> TestResult<()> { | ||
// Insert some data first | ||
run_query!( | ||
runner, | ||
r#"mutation { createManyApp(data: [{slug:"a",categories:[calendar,other]},{slug:"b",categories:[]},{slug:"c",categories:[calendar,other]},{slug:"d",categories:[messaging, payment]}]) { count } }"# | ||
); | ||
|
||
let result = run_query!( | ||
runner, | ||
r#"{groupByApp(by: [categories], orderBy: { categories: "desc" }) { _count { slug } categories }}"# | ||
); | ||
assert_eq!(result, "{\"data\":{\"groupByApp\":[{\"_count\":{\"slug\":1},\"categories\":[\"messaging\",\"payment\"]},{\"_count\":{\"slug\":2},\"categories\":[\"calendar\",\"other\"]},{\"_count\":{\"slug\":1},\"categories\":[]}]}}"); | ||
|
||
let result = run_query!( | ||
runner, | ||
r#"{groupByApp(by: [categories], orderBy: { categories: "asc" }) { _count { slug categories } }}"# | ||
); | ||
assert_eq!(result, "{\"data\":{\"groupByApp\":[{\"_count\":{\"slug\":1,\"categories\":1}},{\"_count\":{\"slug\":2,\"categories\":2}},{\"_count\":{\"slug\":1,\"categories\":1}}]}}"); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[connector_test] | ||
async fn group_by_boolean_array(runner: Runner) -> TestResult<()> { | ||
// Insert some data first | ||
run_query!( | ||
runner, | ||
r#"mutation { createManyOpp(data: [{slug:"a",categories:[true,false]},{slug:"b",categories:[]},{slug:"c",categories:[false,true]},{slug:"d",categories:[true,false]}]) { count } }"# | ||
); | ||
|
||
let result = run_query!( | ||
runner, | ||
r#"{groupByOpp(by: [categories], orderBy: { categories: "desc" }) { _count { slug } categories }}"# | ||
); | ||
assert_eq!(result, "{\"data\":{\"groupByOpp\":[{\"_count\":{\"slug\":2},\"categories\":[true,false]},{\"_count\":{\"slug\":1},\"categories\":[false,true]},{\"_count\":{\"slug\":1},\"categories\":[]}]}}"); | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters