Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing predicates tests #69

Merged
merged 4 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"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": "_nlike"
},
"value": {
"type": "scalar",
"value": "%Rock%"
}
},
"limit": 10
},
"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": {}
}
38 changes: 36 additions & 2 deletions crates/ndc-sqlserver/tests/query_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ mod predicates {
insta::assert_json_snapshot!(result);
}

#[tokio::test]
async fn select_where_name_nlike() {
let result = run_query("select_where_name_nlike").await;
insta::assert_json_snapshot!(result);
}

#[tokio::test]
async fn select_where_name_not_like() {
let result = run_query("select_where_name_not_like").await;
Expand Down Expand Up @@ -96,19 +102,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"
}
]
}
]
Loading