Skip to content

Commit

Permalink
test variable used in multiple type contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
hallettj committed Jul 11, 2024
1 parent 8ecb46d commit 85e2739
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 31 deletions.
70 changes: 39 additions & 31 deletions crates/integration-tests/src/tests/remote_relationship.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{graphql_query, run_connector_query};
use insta::assert_yaml_snapshot;
use ndc_test_helpers::{asc, binop, field, query, query_request, target, variable};
use ndc_test_helpers::{and, asc, binop, field, query, query_request, target, variable};
use serde_json::json;

#[tokio::test]
Expand Down Expand Up @@ -67,33 +67,41 @@ async fn handles_request_with_single_variable_set() -> anyhow::Result<()> {
Ok(())
}

// #[tokio::test]
// async fn variable_type_does_not_match_column_type() -> anyhow::Result<()> {
// // Skip this test in MongoDB 5 because the example fails there. We're getting an error:
// //
// // > Kind: Command failed: Error code 5491300 (Location5491300): $documents' is not allowed in user requests, labels: {}
// //
// // This means that remote joins are not working in MongoDB 5
// if let Ok(image) = std::env::var("MONGODB_IMAGE") {
// if image == "mongo:5" {
// return Ok(());
// }
// }
//
// assert_yaml_snapshot!(
// run_connector_query(
// query_request()
// .variables([[("count", 1)], [("count", 2)], [("count", 3)]])
// .collection("title_word_frequency")
// .query(
// query()
// .predicate(binop("_eq", target!("count"), variable!(count)))
// .order_by([asc!("_id")])
// .limit(20)
// .fields([field!("_id"), field!("count")]),
// )
// )
// .await?
// );
// Ok(())
// }
#[tokio::test]
async fn variable_used_in_multiple_type_contexts() -> anyhow::Result<()> {
// Skip this test in MongoDB 5 because the example fails there. We're getting an error:
//
// > Kind: Command failed: Error code 5491300 (Location5491300): $documents' is not allowed in user requests, labels: {}
//
// This means that remote joins are not working in MongoDB 5
if let Ok(image) = std::env::var("MONGODB_IMAGE") {
if image == "mongo:5" {
return Ok(());
}
}

assert_yaml_snapshot!(
run_connector_query(
query_request()
.variables([[("dateInput", "2015-09-15T00:00Z")]])
.collection("movies")
.query(
query()
.predicate(and([
binop("_gt", target!("released"), variable!(dateInput)), // type is date
binop("_gt", target!("lastupdated"), variable!(dateInput)), // type is string
]))
.order_by([asc!("_id")])
.limit(20)
.fields([
field!("_id"),
field!("title"),
field!("released"),
field!("lastupdated")
]),
)
)
.await?
);
Ok(())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
source: crates/integration-tests/src/tests/remote_relationship.rs
expression: "run_connector_query(query_request().variables([[(\"dateInput\",\n \"2015-09-15T00:00Z\")]]).collection(\"movies\").query(query().predicate(and([binop(\"_gt\",\n target!(\"released\"), variable!(dateInput)),\n binop(\"_gt\", target!(\"lastupdated\"),\n variable!(dateInput))])).order_by([asc!(\"_id\")]).limit(20).fields([field!(\"_id\"),\n field!(\"title\"), field!(\"released\"),\n field!(\"lastupdated\")]))).await?"
---
- rows:
- _id: 573a13d3f29313caabd967ef
lastupdated: "2015-09-17 03:51:47.073000000"
released: "2015-11-01T00:00:00.000000000Z"
title: Another World
- _id: 573a13eaf29313caabdcfa99
lastupdated: "2015-09-16 07:39:43.980000000"
released: "2015-10-02T00:00:00.000000000Z"
title: Sicario
- _id: 573a13ebf29313caabdd0792
lastupdated: "2015-09-16 13:01:10.653000000"
released: "2015-11-04T00:00:00.000000000Z"
title: April and the Extraordinary World
- _id: 573a13f0f29313caabdd9b5d
lastupdated: "2015-09-17 04:41:09.897000000"
released: "2015-09-17T00:00:00.000000000Z"
title: The Wait
- _id: 573a13f1f29313caabddc788
lastupdated: "2015-09-17 03:17:32.967000000"
released: "2015-12-18T00:00:00.000000000Z"
title: Son of Saul
- _id: 573a13f2f29313caabddd3b6
lastupdated: "2015-09-17 02:59:54.573000000"
released: "2016-01-13T00:00:00.000000000Z"
title: Bang Gang (A Modern Love Story)
- _id: 573a13f4f29313caabde0bfd
lastupdated: "2015-09-17 02:00:44.673000000"
released: "2016-02-19T00:00:00.000000000Z"
title: Shut In

0 comments on commit 85e2739

Please sign in to comment.