From 02636bfed03ed1e0c3690bc7845a9a4ce78a76cb Mon Sep 17 00:00:00 2001 From: Daniel Harvey Date: Tue, 14 Nov 2023 10:38:14 +0000 Subject: [PATCH] Add all relevant predicates tests from ndc-postgres --- .../tests/goldenfiles/select_where_and.json | 40 +++++++++ .../select_where_array_relationship.json | 87 +++++++++++++++++++ .../goldenfiles/select_where_name_eq.json | 35 ++++++++ .../goldenfiles/select_where_name_neq.json | 49 +++++++++++ .../tests/goldenfiles/select_where_or.json | 52 +++++++++++ crates/ndc-sqlserver/tests/query_tests.rs | 32 ++++++- ...y_tests__predicates__select_where_and.snap | 13 +++ ...sts__predicates__select_where_name_eq.snap | 14 +++ ...ts__predicates__select_where_name_neq.snap | 30 +++++++ ...ry_tests__predicates__select_where_or.snap | 16 ++++ 10 files changed, 366 insertions(+), 2 deletions(-) create mode 100644 crates/ndc-sqlserver/tests/goldenfiles/select_where_and.json create mode 100644 crates/ndc-sqlserver/tests/goldenfiles/select_where_array_relationship.json create mode 100644 crates/ndc-sqlserver/tests/goldenfiles/select_where_name_eq.json create mode 100644 crates/ndc-sqlserver/tests/goldenfiles/select_where_name_neq.json create mode 100644 crates/ndc-sqlserver/tests/goldenfiles/select_where_or.json create mode 100644 crates/ndc-sqlserver/tests/snapshots/query_tests__predicates__select_where_and.snap create mode 100644 crates/ndc-sqlserver/tests/snapshots/query_tests__predicates__select_where_name_eq.snap create mode 100644 crates/ndc-sqlserver/tests/snapshots/query_tests__predicates__select_where_name_neq.snap create mode 100644 crates/ndc-sqlserver/tests/snapshots/query_tests__predicates__select_where_or.snap diff --git a/crates/ndc-sqlserver/tests/goldenfiles/select_where_and.json b/crates/ndc-sqlserver/tests/goldenfiles/select_where_and.json new file mode 100644 index 00000000..3680cf0f --- /dev/null +++ b/crates/ndc-sqlserver/tests/goldenfiles/select_where_and.json @@ -0,0 +1,40 @@ +{ + "collection": "Album", + "query": { + "fields": { "Title": { "type": "column", "column": "Title" } }, + "where": { + "type": "and", + "expressions": [ + { + "type": "and", + "expressions": [ + { + "type": "and", + "expressions": [ + { + "type": "binary_comparison_operator", + "column": { "type": "column", "name": "Title", "path": [] }, + "operator": { "type": "other", "name": "_like" }, + "value": { "type": "scalar", "value": "Van %" } + } + ] + }, + { + "type": "and", + "expressions": [ + { + "type": "binary_comparison_operator", + "column": { "type": "column", "name": "Title", "path": [] }, + "operator": { "type": "other", "name": "_like" }, + "value": { "type": "scalar", "value": "% Halen III" } + } + ] + } + ] + } + ] + } + }, + "arguments": {}, + "collection_relationships": {} +} diff --git a/crates/ndc-sqlserver/tests/goldenfiles/select_where_array_relationship.json b/crates/ndc-sqlserver/tests/goldenfiles/select_where_array_relationship.json new file mode 100644 index 00000000..6bf9a741 --- /dev/null +++ b/crates/ndc-sqlserver/tests/goldenfiles/select_where_array_relationship.json @@ -0,0 +1,87 @@ +{ + "collection": "Artist", + "query": { + "fields": { + "title": { + "type": "column", + "column": "Name", + "arguments": {} + }, + "albums": { + "type": "relationship", + "relationship": "Artist_Albums", + "arguments": {}, + "query": { + "fields": { + "title": { + "type": "column", + "column": "Title", + "arguments": {} + } + }, + "order_by": { + "elements": [ + { + "order_direction": "asc", + "target": { + "type": "column", + "name": "AlbumId", + "path": [] + } + } + ] + } + } + } + }, + "where": { + "type": "binary_comparison_operator", + "column": { + "type": "column", + "name": "Title", + "path": [ + { + "relationship": "Artist_Albums", + "arguments": {}, + "predicate": { + "type": "and", + "expressions": [] + } + } + ] + }, + "operator": { + "type": "other", + "name": "_like" + }, + "value": { + "type": "scalar", + "value": "Supernatural" + } + }, + "order_by": { + "elements": [ + { + "order_direction": "asc", + "target": { + "type": "column", + "name": "ArtistId", + "path": [] + } + } + ] + } + }, + "arguments": {}, + "collection_relationships": { + "Artist_Albums": { + "arguments": {}, + "column_mapping": { + "ArtistId": "ArtistId" + }, + "relationship_type": "array", + "source_collection_or_type": "Artist", + "target_collection": "Album" + } + } +} diff --git a/crates/ndc-sqlserver/tests/goldenfiles/select_where_name_eq.json b/crates/ndc-sqlserver/tests/goldenfiles/select_where_name_eq.json new file mode 100644 index 00000000..39599369 --- /dev/null +++ b/crates/ndc-sqlserver/tests/goldenfiles/select_where_name_eq.json @@ -0,0 +1,35 @@ +{ + "collection": "Album", + "query": { + "limit": 5, + "fields": { + "AlbumId": { + "type": "column", + "column": "AlbumId", + "arguments": {} + }, + "Title": { + "type": "column", + "column": "Title", + "arguments": {} + } + }, + "where": { + "type": "binary_comparison_operator", + "column": { + "type": "column", + "name": "Title", + "path": [] + }, + "operator": { + "type": "equal" + }, + "value": { + "type": "scalar", + "value": "Houses Of The Holy" + } + } + }, + "arguments": {}, + "collection_relationships": {} +} diff --git a/crates/ndc-sqlserver/tests/goldenfiles/select_where_name_neq.json b/crates/ndc-sqlserver/tests/goldenfiles/select_where_name_neq.json new file mode 100644 index 00000000..58ab13c8 --- /dev/null +++ b/crates/ndc-sqlserver/tests/goldenfiles/select_where_name_neq.json @@ -0,0 +1,49 @@ +{ + "collection": "Album", + "query": { + "fields": { + "AlbumId": { + "type": "column", + "column": "AlbumId", + "arguments": {} + }, + "Title": { + "type": "column", + "column": "Title", + "arguments": {} + } + }, + "where": { + "type": "binary_comparison_operator", + "column": { + "type": "column", + "name": "Title", + "path": [] + }, + "operator": { + "type": "other", + "name": "_neq" + }, + "value": { + "type": "scalar", + "value": "Houses Of The Holy" + } + }, + "order_by": { + "elements": [ + { + "order_direction": "asc", + "target": { + "type": "column", + "name": "AlbumId", + "path": [] + } + } + ] + }, + "limit": 5, + "offset": 125 + }, + "arguments": {}, + "collection_relationships": {} +} diff --git a/crates/ndc-sqlserver/tests/goldenfiles/select_where_or.json b/crates/ndc-sqlserver/tests/goldenfiles/select_where_or.json new file mode 100644 index 00000000..2750597c --- /dev/null +++ b/crates/ndc-sqlserver/tests/goldenfiles/select_where_or.json @@ -0,0 +1,52 @@ +{ + "collection": "Album", + "query": { + "fields": { "Title": { "type": "column", "column": "Title" } }, + "where": { + "type": "and", + "expressions": [ + { + "type": "or", + "expressions": [ + { + "type": "and", + "expressions": [ + { + "type": "binary_comparison_operator", + "column": { "type": "column", "name": "Title", "path": [] }, + "operator": { "type": "equal" }, + "value": { "type": "scalar", "value": "IV" } + } + ] + }, + { + "type": "and", + "expressions": [ + { + "type": "binary_comparison_operator", + "column": { "type": "column", "name": "Title", "path": [] }, + "operator": { "type": "equal" }, + "value": { "type": "scalar", "value": "Van Halen III" } + } + ] + } + ] + } + ] + }, + "order_by": { + "elements": [ + { + "order_direction": "asc", + "target": { + "type": "column", + "name": "AlbumId", + "path": [] + } + } + ] + } + }, + "arguments": {}, + "collection_relationships": {} +} diff --git a/crates/ndc-sqlserver/tests/query_tests.rs b/crates/ndc-sqlserver/tests/query_tests.rs index f89d6e4c..0bbecdbb 100644 --- a/crates/ndc-sqlserver/tests/query_tests.rs +++ b/crates/ndc-sqlserver/tests/query_tests.rs @@ -96,19 +96,47 @@ mod predicates { insta::assert_json_snapshot!(result); } - // fix exists implementation #[tokio::test] async fn select_where_unrelated_exists() { let result = run_query("select_where_unrelated_exists").await; insta::assert_json_snapshot!(result); } - // fix exists implementation #[tokio::test] async fn select_where_related_exists() { let result = run_query("select_where_related_exists").await; insta::assert_json_snapshot!(result); } + + #[tokio::test] + async fn select_where_name_eq() { + let result = run_query("select_where_name_eq").await; + insta::assert_json_snapshot!(result); + } + + #[tokio::test] + async fn select_where_name_neq() { + let result = run_query("select_where_name_neq").await; + insta::assert_json_snapshot!(result); + } + + #[tokio::test] + async fn select_where_or() { + let result = run_query("select_where_or").await; + insta::assert_json_snapshot!(result); + } + + #[tokio::test] + async fn select_where_and() { + let result = run_query("select_where_and").await; + insta::assert_json_snapshot!(result); + } + + #[tokio::test] + async fn select_where_array_relationship() { + let result = run_query("select_where_array_relationship").await; + insta::assert_json_snapshot!(result); + } } mod sorting { diff --git a/crates/ndc-sqlserver/tests/snapshots/query_tests__predicates__select_where_and.snap b/crates/ndc-sqlserver/tests/snapshots/query_tests__predicates__select_where_and.snap new file mode 100644 index 00000000..0a9c21e1 --- /dev/null +++ b/crates/ndc-sqlserver/tests/snapshots/query_tests__predicates__select_where_and.snap @@ -0,0 +1,13 @@ +--- +source: crates/ndc-sqlserver/tests/query_tests.rs +expression: result +--- +[ + { + "rows": [ + { + "Title": "Van Halen III" + } + ] + } +] diff --git a/crates/ndc-sqlserver/tests/snapshots/query_tests__predicates__select_where_name_eq.snap b/crates/ndc-sqlserver/tests/snapshots/query_tests__predicates__select_where_name_eq.snap new file mode 100644 index 00000000..b4d879b6 --- /dev/null +++ b/crates/ndc-sqlserver/tests/snapshots/query_tests__predicates__select_where_name_eq.snap @@ -0,0 +1,14 @@ +--- +source: crates/ndc-sqlserver/tests/query_tests.rs +expression: result +--- +[ + { + "rows": [ + { + "AlbumId": 129, + "Title": "Houses Of The Holy" + } + ] + } +] diff --git a/crates/ndc-sqlserver/tests/snapshots/query_tests__predicates__select_where_name_neq.snap b/crates/ndc-sqlserver/tests/snapshots/query_tests__predicates__select_where_name_neq.snap new file mode 100644 index 00000000..1895e466 --- /dev/null +++ b/crates/ndc-sqlserver/tests/snapshots/query_tests__predicates__select_where_name_neq.snap @@ -0,0 +1,30 @@ +--- +source: crates/ndc-sqlserver/tests/query_tests.rs +expression: result +--- +[ + { + "rows": [ + { + "AlbumId": 126, + "Title": "Unplugged [Live]" + }, + { + "AlbumId": 127, + "Title": "BBC Sessions [Disc 2] [Live]" + }, + { + "AlbumId": 128, + "Title": "Coda" + }, + { + "AlbumId": 130, + "Title": "In Through The Out Door" + }, + { + "AlbumId": 131, + "Title": "IV" + } + ] + } +] diff --git a/crates/ndc-sqlserver/tests/snapshots/query_tests__predicates__select_where_or.snap b/crates/ndc-sqlserver/tests/snapshots/query_tests__predicates__select_where_or.snap new file mode 100644 index 00000000..14d13aa3 --- /dev/null +++ b/crates/ndc-sqlserver/tests/snapshots/query_tests__predicates__select_where_or.snap @@ -0,0 +1,16 @@ +--- +source: crates/ndc-sqlserver/tests/query_tests.rs +expression: result +--- +[ + { + "rows": [ + { + "Title": "IV" + }, + { + "Title": "Van Halen III" + } + ] + } +]