mod setup;
use serde_json::json;
#[cfg(feature = "cosmos")]
use setup::cosmos_test_client;
#[cfg(feature = "gremlin")]
use setup::gremlin_test_client;
#[cfg(feature = "neo4j")]
use setup::neo4j_test_client;
#[cfg(any(feature = "cosmos", feature = "gremlin", feature = "neo4j"))]
use setup::{clear_db, init};
use setup::{AppGlobalCtx, AppRequestCtx};
use warpgrapher::client::Client;
#[cfg(feature = "neo4j")]
#[tokio::test]
async fn create_node_with_rel_to_new_neo4j() {
init();
clear_db().await;
let client = neo4j_test_client("./tests/fixtures/minimal.yml").await;
create_node_with_rel_to_new(client).await;
}
#[cfg(feature = "cosmos")]
#[tokio::test]
async fn create_node_with_rel_to_new_cosmos() {
init();
clear_db().await;
let client = cosmos_test_client("./tests/fixtures/minimal.yml").await;
create_node_with_rel_to_new(client).await;
}
#[cfg(feature = "gremlin")]
#[tokio::test]
async fn create_node_with_rel_to_new_gremlin() {
init();
clear_db().await;
let client = gremlin_test_client("./tests/fixtures/minimal.yml").await;
create_node_with_rel_to_new(client).await;
}
#[allow(clippy::cognitive_complexity, dead_code)]
async fn create_node_with_rel_to_new(mut client: Client<AppGlobalCtx, AppRequestCtx>) {
let results0 = client
.create_node(
"Project",
"__typename
id
board {
__typename
id
dst {
... on KanbanBoard {
__typename
id
name
}
}
}",
Some("1234"),
&json!({
"name": "SPARTAN-V",
"board": {
"dst": {
"KanbanBoard": {
"NEW": {
"name": "SPARTAN-V Board"
}
}
}
}
}),
)
.await
.unwrap();
assert!(results0.is_object());
let p0_board = results0.get("board").unwrap();
assert!(p0_board.is_object());
assert_eq!(p0_board.get("__typename").unwrap(), "ProjectBoardRel");
let p0_board_dst = p0_board.get("dst").unwrap();
assert!(p0_board_dst.is_object());
assert_eq!(p0_board_dst.get("__typename").unwrap(), "KanbanBoard");
assert_eq!(p0_board_dst.get("name").unwrap(), "SPARTAN-V Board");
let results1 = client
.read_node(
"KanbanBoard",
"__typename
id
name",
Some("1234"),
Some(&json!({
"name": "SPARTAN-V Board"
})),
)
.await
.unwrap();
assert!(results1.is_array());
let b0 = &results1[0];
assert!(b0.is_object());
assert_eq!(b0.get("__typename").unwrap(), "KanbanBoard");
assert_eq!(b0.get("name").unwrap(), "SPARTAN-V Board");
let results2 = client
.read_node(
"Project",
"__typename
id
name
board {
__typename
dst {
... on KanbanBoard {
__typename
id
name
}
}
}",
Some("1234"),
Some(&json!({
"name": "SPARTAN-V"
})),
)
.await
.unwrap();
assert!(results2.is_array());
assert_eq!(results2.as_array().unwrap().len(), 1);
let p1 = &results2[0];
assert_eq!(p1.get("__typename").unwrap(), "Project");
assert_eq!(p1.get("name").unwrap(), "SPARTAN-V");
let p1_board = p1.get("board").unwrap();
assert_eq!(p1_board.get("__typename").unwrap(), "ProjectBoardRel");
let p1_board_dst = p1_board.get("dst").unwrap();
assert_eq!(p1_board_dst.get("__typename").unwrap(), "KanbanBoard");
assert_eq!(p1_board_dst.get("name").unwrap(), "SPARTAN-V Board");
assert_eq!(p1_board_dst.get("id").unwrap(), b0.get("id").unwrap());
}
#[cfg(feature = "neo4j")]
#[tokio::test]
async fn create_node_with_rel_to_existing_neo4j() {
init();
clear_db().await;
let client = neo4j_test_client("./tests/fixtures/minimal.yml").await;
create_node_with_rel_to_existing(client).await;
}
#[cfg(feature = "cosmos")]
#[tokio::test]
async fn create_node_with_rel_to_existing_cosmos() {
init();
clear_db().await;
let client = cosmos_test_client("./tests/fixtures/minimal.yml").await;
create_node_with_rel_to_existing(client).await;
}
#[cfg(feature = "gremlin")]
#[tokio::test]
async fn create_node_with_rel_to_existing_gremlin() {
init();
clear_db().await;
let client = gremlin_test_client("./tests/fixtures/minimal.yml").await;
create_node_with_rel_to_existing(client).await;
}
#[allow(clippy::cognitive_complexity, dead_code)]
async fn create_node_with_rel_to_existing(mut client: Client<AppGlobalCtx, AppRequestCtx>) {
let results0 = client
.create_node(
"ScrumBoard",
"__typename
id
name
",
Some("1234"),
&json!({
"name": "SPARTAN-VI Board"
}),
)
.await
.unwrap();
assert!(results0.is_object());
assert_eq!(results0.get("__typename").unwrap(), "ScrumBoard");
let results1 = client
.create_node(
"Project",
"__typename
id
board {
__typename
id
dst {
... on ScrumBoard {
__typename
id
name
}
}
}",
Some("1234"),
&json!({
"name": "SPARTAN-VI",
"board": {
"dst": {
"ScrumBoard": {
"EXISTING": {
"name": "SPARTAN-VI Board"
}
}
}
}
}),
)
.await
.unwrap();
assert!(results1.is_object());
assert_eq!(results1.get("__typename").unwrap(), "Project");
let results2 = client
.read_node(
"Project",
"__typename
id
name
board {
dst {
... on ScrumBoard {
__typename
id
name
}
}
}",
Some("1234"),
Some(&json!({
"name": "SPARTAN-VI"
})),
)
.await
.unwrap();
assert!(results2.is_array());
assert_eq!(results2.as_array().unwrap().len(), 1);
let p1 = &results2[0];
assert_eq!(p1.get("__typename").unwrap(), "Project");
let p1_board = p1.get("board").unwrap();
let b1 = p1_board.get("dst").unwrap();
assert_eq!(b1.get("__typename").unwrap(), "ScrumBoard");
assert_eq!(b1.get("name").unwrap(), "SPARTAN-VI Board");
}
#[cfg(feature = "neo4j")]
#[tokio::test]
async fn read_multiple_nodes_with_multiple_rels_neo4j() {
init();
clear_db().await;
let client = neo4j_test_client("./tests/fixtures/minimal.yml").await;
read_multiple_nodes_with_multiple_rels(client).await;
}
#[cfg(feature = "cosmos")]
#[tokio::test]
async fn read_multiple_nodes_with_multiple_rels_cosmos() {
init();
clear_db().await;
let client = cosmos_test_client("./tests/fixtures/minimal.yml").await;
read_multiple_nodes_with_multiple_rels(client).await;
}
#[cfg(feature = "gremlin")]
#[tokio::test]
async fn read_multiple_nodes_with_multiple_rels_gremlin() {
init();
clear_db().await;
let client = gremlin_test_client("./tests/fixtures/minimal.yml").await;
read_multiple_nodes_with_multiple_rels(client).await;
}
#[allow(clippy::cognitive_complexity, dead_code)]
async fn read_multiple_nodes_with_multiple_rels(mut client: Client<AppGlobalCtx, AppRequestCtx>) {
let results0 = client
.create_node(
"Project",
"__typename
id
",
Some("1234"),
&json!({
"name": "SPARTAN-10",
"board": {
"dst": {
"ScrumBoard": {
"NEW": {
"name": "SPARTAN-10 Board"
}
}
}
}
}),
)
.await
.unwrap();
let results1 = client
.create_node(
"Project",
"__typename
id
",
Some("1234"),
&json!({
"name": "SPARTAN-11",
"board": {
"dst": {
"KanbanBoard": {
"NEW": {
"name": "SPARTAN-11 Board"
}
}
}
}
}),
)
.await
.unwrap();
let results2 = client
.create_node(
"Project",
"__typename
id
",
Some("1234"),
&json!({
"name": "SPARTAN-12",
"board": {
"dst": {
"KanbanBoard": {
"NEW": {
"name": "SPARTAN-12 Board"
}
}
}
}
}),
)
.await
.unwrap();
let results3 = client
.read_node(
"Project",
"__typename
id
name
board {
__typename
dst {
__typename
... on ScrumBoard {
id
name
}
... on KanbanBoard {
id
name
}
}
}",
Some("1234"),
None,
)
.await
.unwrap();
assert!(results3.is_array());
let projects = results3.as_array().unwrap();
let p0 = projects
.iter()
.find(|&x| x.get("id").unwrap() == results0.get("id").unwrap())
.unwrap();
assert!(p0.is_object());
let p0_board = p0.get("board").unwrap();
assert_eq!(p0_board.get("__typename").unwrap(), "ProjectBoardRel");
let b0 = p0_board.get("dst").unwrap();
assert_eq!(b0.get("__typename").unwrap(), "ScrumBoard");
assert_eq!(b0.get("name").unwrap(), "SPARTAN-10 Board");
let p1 = projects
.iter()
.find(|&x| x.get("id").unwrap() == results1.get("id").unwrap())
.unwrap();
assert!(p1.is_object());
let p1_board = p1.get("board").unwrap();
assert_eq!(p1_board.get("__typename").unwrap(), "ProjectBoardRel");
let b1 = p1_board.get("dst").unwrap();
assert_eq!(b1.get("__typename").unwrap(), "KanbanBoard");
assert_eq!(b1.get("name").unwrap(), "SPARTAN-11 Board");
let p2 = projects
.iter()
.find(|&x| x.get("id").unwrap() == results2.get("id").unwrap())
.unwrap();
assert!(p2.is_object());
let p2_board = p2.get("board").unwrap();
assert_eq!(p2_board.get("__typename").unwrap(), "ProjectBoardRel");
let b2 = p2_board.get("dst").unwrap();
assert_eq!(b2.get("__typename").unwrap(), "KanbanBoard");
assert_eq!(b2.get("name").unwrap(), "SPARTAN-12 Board");
}
#[cfg(feature = "neo4j")]
#[tokio::test]
async fn read_node_with_matching_props_on_rel_neo4j() {
init();
clear_db().await;
let client = neo4j_test_client("./tests/fixtures/minimal.yml").await;
read_node_with_matching_props_on_rel(client).await;
}
#[cfg(feature = "cosmos")]
#[tokio::test]
async fn read_node_with_matching_props_on_rel_cosmos() {
init();
clear_db().await;
let client = cosmos_test_client("./tests/fixtures/minimal.yml").await;
read_node_with_matching_props_on_rel(client).await;
}
#[cfg(feature = "gremlin")]
#[tokio::test]
async fn read_node_with_matching_props_on_rel_gremlin() {
init();
clear_db().await;
let client = gremlin_test_client("./tests/fixtures/minimal.yml").await;
read_node_with_matching_props_on_rel(client).await;
}
#[allow(clippy::cognitive_complexity, dead_code)]
async fn read_node_with_matching_props_on_rel(mut client: Client<AppGlobalCtx, AppRequestCtx>) {
let results0 = client
.create_node(
"Project",
"id",
Some("1234"),
&json!({
"name": "ORION",
"board": {
"props": {
"publicized": false
},
"dst": {
"ScrumBoard": {
"NEW": {
"name": "ORION Board"
}
}
}
}
}),
)
.await
.unwrap();
assert!(results0.is_object());
let results1 = client
.create_node(
"Project",
"id",
Some("1234"),
&json!({
"name": "SPARTAN",
"board": {
"props": {
"publicized": true
},
"dst": {
"ScrumBoard": {
"NEW": {
"name": "SPARTAN Board"
}
}
}
}
}),
)
.await
.unwrap();
assert!(results1.is_object());
let results3 = client
.read_node(
"Project",
"__typename
id
name
board {
__typename
props {
publicized
}
dst {
... on ScrumBoard {
__typename
id
name
}
}
}",
Some("1234"),
Some(&json!({
"board": {
"props": {
"publicized": true
}
}
})),
)
.await
.unwrap();
assert!(results3.is_array());
let projects0 = results3.as_array().unwrap();
assert_eq!(projects0.len(), 1);
let p0 = &projects0[0];
assert!(p0.is_object());
assert_eq!(p0.get("__typename").unwrap(), "Project");
assert_eq!(p0.get("name").unwrap(), "SPARTAN");
let p0_board = p0.get("board").unwrap();
assert_eq!(p0_board.get("__typename").unwrap(), "ProjectBoardRel");
let b0 = p0_board.get("dst").unwrap();
assert_eq!(b0.get("name").unwrap(), "SPARTAN Board");
let results4 = client
.read_node(
"Project",
"__typename
id
name
board {
__typename
dst {
... on ScrumBoard {
__typename
id
name
}
}
}",
Some("1234"),
Some(&json!({
"board": {
"props": {
"publicized": false
}
}
})),
)
.await
.unwrap();
assert!(results4.is_array());
let projects1 = results4.as_array().unwrap();
assert_eq!(projects1.len(), 1);
let p1 = &projects1[0];
assert!(p1.is_object());
assert_eq!(p1.get("__typename").unwrap(), "Project");
assert_eq!(p1.get("name").unwrap(), "ORION");
let p1_board = p1.get("board").unwrap();
assert_eq!(p1_board.get("__typename").unwrap(), "ProjectBoardRel");
let b1 = p1_board.get("dst").unwrap();
assert_eq!(b1.get("name").unwrap(), "ORION Board");
}
#[cfg(feature = "neo4j")]
#[tokio::test]
async fn read_node_with_matching_props_on_rel_dst_node_neo4j() {
init();
clear_db().await;
let client = neo4j_test_client("./tests/fixtures/minimal.yml").await;
read_node_with_matching_props_on_rel_dst_node(client).await;
}
#[cfg(feature = "cosmos")]
#[tokio::test]
async fn read_node_with_matching_props_on_rel_dst_node_cosmos() {
init();
clear_db().await;
let client = cosmos_test_client("./tests/fixtures/minimal.yml").await;
read_node_with_matching_props_on_rel_dst_node(client).await;
}
#[cfg(feature = "gremlin")]
#[tokio::test]
async fn read_node_with_matching_props_on_rel_dst_node_gremlin() {
init();
clear_db().await;
let client = gremlin_test_client("./tests/fixtures/minimal.yml").await;
read_node_with_matching_props_on_rel_dst_node(client).await;
}
#[allow(clippy::cognitive_complexity, dead_code)]
async fn read_node_with_matching_props_on_rel_dst_node(
mut client: Client<AppGlobalCtx, AppRequestCtx>,
) {
let _results0 = client
.create_node(
"Project",
"id",
Some("1234"),
&json!({
"name": "ORION",
"board": {
"props": {
"publicized": false
},
"dst": {
"ScrumBoard": {
"NEW": {
"name": "ORION Board"
}
}
}
}
}),
)
.await
.unwrap();
let _results1 = client
.create_node(
"Project",
"id",
Some("1234"),
&json!({
"name": "SPARTAN",
"board": {
"props": {
"publicized": false
},
"dst": {
"ScrumBoard": {
"NEW": {
"name": "SPARTAN Board"
}
}
}
}
}),
)
.await
.unwrap();
let results2 = client
.read_node(
"Project",
"__typename
id
name
board {
__typename
dst {
... on ScrumBoard {
__typename
id
name
}
... on KanbanBoard {
__typename
id
name
}
}
}
",
Some("1234"),
Some(&json!({
"board": {
"dst": {
"ScrumBoard": {
"name": "SPARTAN Board"
}
}
}
})),
)
.await
.unwrap();
assert!(results2.is_array());
let projects = results2.as_array().unwrap();
assert_eq!(projects.len(), 1);
let p0 = &projects[0];
assert!(p0.is_object());
assert_eq!(p0.get("__typename").unwrap(), "Project");
assert_eq!(p0.get("name").unwrap(), "SPARTAN");
}
#[cfg(feature = "neo4j")]
#[tokio::test]
async fn update_existing_node_with_rel_to_new_node_neo4j() {
init();
clear_db().await;
let client = neo4j_test_client("./tests/fixtures/minimal.yml").await;
update_existing_node_with_rel_to_new_node(client).await;
}
#[cfg(feature = "cosmos")]
#[tokio::test]
async fn update_existing_node_with_rel_to_new_node_cosmos() {
init();
clear_db().await;
let client = cosmos_test_client("./tests/fixtures/minimal.yml").await;
update_existing_node_with_rel_to_new_node(client).await;
}
#[cfg(feature = "gremlin")]
#[tokio::test]
async fn update_existing_node_with_rel_to_new_node_gremlin() {
init();
clear_db().await;
let client = gremlin_test_client("./tests/fixtures/minimal.yml").await;
update_existing_node_with_rel_to_new_node(client).await;
}
#[allow(clippy::cognitive_complexity, dead_code)]
async fn update_existing_node_with_rel_to_new_node(
mut client: Client<AppGlobalCtx, AppRequestCtx>,
) {
let _results0 = client
.create_node(
"Project",
"id",
Some("1234"),
&json!({
"name": "ORION",
}),
)
.await
.unwrap();
let _results1 = client
.update_node(
"Project",
"__typename
id
name
board {
dst {
... on ScrumBoard {
__typename
id
name
}
}
}
",
Some("1234"),
Some(&json!({
"name": "ORION"
})),
&json!({
"board": {
"ADD": {
"dst": {
"KanbanBoard": {
"NEW": {
"name": "ORION Board"
}
}
}
}
}
}),
)
.await
.unwrap();
let results2 = client
.read_node(
"Project",
"__typename
id
name
board {
__typename
dst {
... on ScrumBoard {
id
name
}
... on KanbanBoard {
id
name
}
}
}
",
Some("1234"),
None,
)
.await
.unwrap();
assert!(results2.is_array());
let projects = results2.as_array().unwrap();
assert_eq!(projects.len(), 1);
let p0 = &projects[0];
assert!(p0.is_object());
assert_eq!(p0.get("__typename").unwrap(), "Project");
assert_eq!(p0.get("name").unwrap(), "ORION");
let p0_board = p0.get("board").unwrap();
assert_eq!(p0_board.get("__typename").unwrap(), "ProjectBoardRel");
assert_eq!(
p0_board.get("dst").unwrap().get("name").unwrap(),
"ORION Board"
);
}
#[cfg(feature = "neo4j")]
#[tokio::test]
async fn update_existing_node_with_rel_to_existing_node_neo4j() {
init();
clear_db().await;
let client = neo4j_test_client("./tests/fixtures/minimal.yml").await;
update_existing_node_with_rel_to_existing_node(client).await;
}
#[cfg(feature = "cosmos")]
#[tokio::test]
async fn update_existing_node_with_rel_to_existing_node_cosmos() {
init();
clear_db().await;
let client = cosmos_test_client("./tests/fixtures/minimal.yml").await;
update_existing_node_with_rel_to_existing_node(client).await;
}
#[cfg(feature = "gremlin")]
#[tokio::test]
async fn update_existing_node_with_rel_to_existing_node_gremlin() {
init();
clear_db().await;
let client = gremlin_test_client("./tests/fixtures/minimal.yml").await;
update_existing_node_with_rel_to_existing_node(client).await;
}
#[allow(clippy::cognitive_complexity, dead_code)]
async fn update_existing_node_with_rel_to_existing_node(
mut client: Client<AppGlobalCtx, AppRequestCtx>,
) {
let _results0 = client
.create_node(
"Project",
"id",
Some("1234"),
&json!({
"name": "ORION",
}),
)
.await
.unwrap();
let _results1 = client
.create_node(
"ScrumBoard",
"id",
Some("1234"),
&json!({
"name": "ORION Board"
}),
)
.await;
let _results2 = client
.update_node(
"Project",
"__typename
id
name
",
Some("1234"),
Some(&json!({
"name": "ORION"
})),
&json!({
"board": {
"ADD": {
"dst": {
"ScrumBoard": {
"EXISTING": {
"name": "ORION Board"
}
}
}
}
}
}),
)
.await
.unwrap();
let results2 = client
.read_node(
"Project",
"__typename
id
name
board {
__typename
dst {
... on ScrumBoard {
id
name
}
}
}
",
Some("1234"),
None,
)
.await
.unwrap();
assert!(results2.is_array());
let projects = results2.as_array().unwrap();
assert_eq!(projects.len(), 1);
let p0 = &projects[0];
assert!(p0.is_object());
assert_eq!(p0.get("__typename").unwrap(), "Project");
assert_eq!(p0.get("name").unwrap(), "ORION");
let p0_board = p0.get("board").unwrap();
assert_eq!(p0_board.get("__typename").unwrap(), "ProjectBoardRel");
assert_eq!(
p0_board.get("dst").unwrap().get("name").unwrap(),
"ORION Board"
);
}
#[cfg(feature = "neo4j")]
#[tokio::test]
async fn delete_node_with_matching_props_on_rel_dst_node_neo4j() {
init();
clear_db().await;
let client = neo4j_test_client("./tests/fixtures/minimal.yml").await;
delete_node_with_matching_props_on_rel_dst_node(client).await;
}
#[cfg(feature = "cosmos")]
#[tokio::test]
async fn delete_node_with_matching_props_on_rel_dst_node_cosmos() {
init();
clear_db().await;
let client = cosmos_test_client("./tests/fixtures/minimal.yml").await;
delete_node_with_matching_props_on_rel_dst_node(client).await;
}
#[cfg(feature = "gremlin")]
#[tokio::test]
async fn delete_node_with_matching_props_on_rel_dst_node_gremlin() {
init();
clear_db().await;
let client = gremlin_test_client("./tests/fixtures/minimal.yml").await;
delete_node_with_matching_props_on_rel_dst_node(client).await;
}
#[allow(clippy::cognitive_complexity, dead_code)]
async fn delete_node_with_matching_props_on_rel_dst_node(
mut client: Client<AppGlobalCtx, AppRequestCtx>,
) {
let _results0 = client
.create_node(
"Project",
"id",
Some("1234"),
&json!({
"name": "ORION",
}),
)
.await
.unwrap();
let _results1 = client
.create_node(
"Project",
"id",
Some("1234"),
&json!({
"name": "SPARTAN-II",
}),
)
.await
.unwrap();
let _results2 = client
.delete_node(
"Project",
Some("1234"),
Some(&json!({"name": "ORION"})),
None,
)
.await
.unwrap();
let results3 = client
.read_node(
"Project",
"__typename
id
name
",
Some("1234"),
None,
)
.await
.unwrap();
assert!(results3.is_array());
assert_eq!(results3.as_array().unwrap().len(), 1);
assert_eq!(results3[0].get("name").unwrap(), "SPARTAN-II");
}
#[cfg(feature = "neo4j")]
#[tokio::test]
async fn delete_node_neo4j() {
init();
clear_db().await;
let client = neo4j_test_client("./tests/fixtures/minimal.yml").await;
delete_node(client).await;
}
#[cfg(feature = "cosmos")]
#[tokio::test]
async fn delete_node_cosmos() {
init();
clear_db().await;
let client = cosmos_test_client("./tests/fixtures/minimal.yml").await;
delete_node(client).await;
}
#[cfg(feature = "gremlin")]
#[tokio::test]
async fn delete_node_gremlin() {
init();
clear_db().await;
let client = gremlin_test_client("./tests/fixtures/minimal.yml").await;
delete_node(client).await;
}
#[allow(clippy::cognitive_complexity, dead_code)]
async fn delete_node(mut client: Client<AppGlobalCtx, AppRequestCtx>) {
let _results0 = client
.create_node(
"Project",
"id",
Some("1234"),
&json!({
"name": "ORION",
"board": {
"dst": {
"ScrumBoard": {
"NEW": {
"name": "ORION Board"
}
}
}
}
}),
)
.await
.unwrap();
let _results1 = client
.delete_node(
"Project",
Some("1234"),
Some(&json!({"name": "ORION"})),
Some(&json!({})),
)
.await
.unwrap();
let results2 = client
.read_node(
"Project",
"__typename
id
name
",
Some("1234"),
None,
)
.await
.unwrap();
assert!(results2.is_array());
assert_eq!(results2.as_array().unwrap().len(), 0);
let results3 = client
.read_node(
"ScrumBoard",
"__typename
id
name
",
Some("1234"),
None,
)
.await
.unwrap();
assert!(results3.is_array());
assert_eq!(results3.as_array().unwrap().len(), 1);
assert_eq!(results3[0].get("name").unwrap(), "ORION Board");
}