Skip to content

Commit

Permalink
Add all relevant predicates tests from ndc-postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
danieljharvey committed Nov 14, 2023
1 parent 1a69e90 commit 02636bf
Show file tree
Hide file tree
Showing 10 changed files with 366 additions and 2 deletions.
40 changes: 40 additions & 0 deletions crates/ndc-sqlserver/tests/goldenfiles/select_where_and.json
Original file line number Diff line number Diff line change
@@ -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": {}
}
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
35 changes: 35 additions & 0 deletions crates/ndc-sqlserver/tests/goldenfiles/select_where_name_eq.json
Original file line number Diff line number Diff line change
@@ -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": {}
}
49 changes: 49 additions & 0 deletions crates/ndc-sqlserver/tests/goldenfiles/select_where_name_neq.json
Original file line number Diff line number Diff line change
@@ -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": {}
}
52 changes: 52 additions & 0 deletions crates/ndc-sqlserver/tests/goldenfiles/select_where_or.json
Original file line number Diff line number Diff line change
@@ -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": {}
}
32 changes: 30 additions & 2 deletions crates/ndc-sqlserver/tests/query_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
source: crates/ndc-sqlserver/tests/query_tests.rs
expression: result
---
[
{
"rows": [
{
"Title": "Van Halen III"
}
]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
source: crates/ndc-sqlserver/tests/query_tests.rs
expression: result
---
[
{
"rows": [
{
"AlbumId": 129,
"Title": "Houses Of The Holy"
}
]
}
]
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
source: crates/ndc-sqlserver/tests/query_tests.rs
expression: result
---
[
{
"rows": [
{
"Title": "IV"
},
{
"Title": "Van Halen III"
}
]
}
]

0 comments on commit 02636bf

Please sign in to comment.