use nexus_sdk::{NexusClient, Value};
use std::collections::HashMap;
#[tokio::test]
#[ignore]
async fn test_health_check() {
let client = NexusClient::new("http://localhost:15474").unwrap();
let healthy = client.health_check().await.unwrap();
assert!(healthy);
}
#[tokio::test]
#[ignore]
async fn test_get_stats() {
let client = NexusClient::new("http://localhost:15474").unwrap();
let stats = client.get_stats().await.unwrap();
let _ = stats.catalog.node_count;
let _ = stats.catalog.rel_count;
}
#[tokio::test]
#[ignore]
async fn test_execute_cypher() {
let client = NexusClient::new("http://localhost:15474").unwrap();
let result = client
.execute_cypher("RETURN 1 as test", None)
.await
.unwrap();
assert_eq!(result.columns.len(), 1);
assert_eq!(result.columns[0], "test");
assert_eq!(result.rows.len(), 1);
if let Some(serde_json::Value::Array(row_values)) = result.rows.first() {
assert_eq!(row_values.len(), 1);
} else {
panic!("Expected row to be an array");
}
}
#[tokio::test]
#[ignore]
async fn test_create_node_with_external_id_round_trip() {
let client = NexusClient::new("http://localhost:15474").unwrap();
let ext_id = "uuid:99999999-9999-9999-9999-999999999999";
let mut props = HashMap::new();
props.insert(
"imported_from".to_string(),
Value::String("phase9_test".to_string()),
);
let create = client
.create_node_with_external_id(
vec!["ExtIdTest".to_string()],
props,
ext_id,
Some("match"),
)
.await
.unwrap();
if create.error.is_none() {
let got = client.get_node_by_external_id(ext_id).await.unwrap();
assert!(got.error.is_none(), "lookup error: {:?}", got.error);
let node = got.node.expect("node should resolve from external id");
assert_eq!(node.id, create.node_id);
}
}
#[tokio::test]
#[ignore]
async fn test_create_and_get_node() {
let client = NexusClient::new("http://localhost:15474").unwrap();
let mut properties = HashMap::new();
properties.insert("name".to_string(), Value::String("Test Node".to_string()));
properties.insert("age".to_string(), Value::Int(25));
let create_response = client
.create_node(vec!["TestLabel".to_string()], properties)
.await
.unwrap();
if create_response.error.is_none() {
assert!(create_response.node_id > 0);
let get_response = client.get_node(create_response.node_id).await.unwrap();
if let Some(node) = get_response.node {
assert_eq!(node.id, create_response.node_id);
assert!(node.labels.contains(&"TestLabel".to_string()));
}
}
}
#[tokio::test]
#[ignore]
async fn test_create_label() {
let client = NexusClient::new("http://localhost:15474").unwrap();
let response = client.create_label("TestLabel".to_string()).await.unwrap();
let _ = response.label_id;
}
#[tokio::test]
#[ignore]
async fn test_list_labels() {
let client = NexusClient::new("http://localhost:15474").unwrap();
let response = client.list_labels().await.unwrap();
let _ = response.labels.len();
}
#[tokio::test]
#[ignore]
async fn test_create_rel_type() {
let client = NexusClient::new("http://localhost:15474").unwrap();
let response = client
.create_rel_type("TEST_REL".to_string())
.await
.unwrap();
let _ = response.type_id;
}
#[tokio::test]
#[ignore]
async fn test_list_rel_types() {
let client = NexusClient::new("http://localhost:15474").unwrap();
let response = client.list_rel_types().await.unwrap();
let _ = response.types.len();
}
#[tokio::test]
#[ignore]
async fn test_create_relationship() {
let client = NexusClient::new("http://localhost:15474").unwrap();
let mut properties1 = HashMap::new();
properties1.insert("name".to_string(), Value::String("Source".to_string()));
let node1 = client
.create_node(vec!["Person".to_string()], properties1)
.await
.unwrap();
let mut properties2 = HashMap::new();
properties2.insert("name".to_string(), Value::String("Target".to_string()));
let node2 = client
.create_node(vec!["Person".to_string()], properties2)
.await
.unwrap();
let rel_properties = HashMap::new();
let rel_response = client
.create_relationship(
node1.node_id,
node2.node_id,
"KNOWS".to_string(),
rel_properties,
)
.await
.unwrap();
if rel_response.error.is_none() {
assert!(rel_response.rel_id > 0);
}
}
#[tokio::test]
#[ignore]
async fn test_update_relationship() {
let client = NexusClient::new("http://localhost:15474").unwrap();
let mut source_props = HashMap::new();
source_props.insert(
"name".to_string(),
Value::String("UpdateSource".to_string()),
);
let source = client
.create_node(vec!["UpdateSource".to_string()], source_props)
.await
.unwrap();
let mut target_props = HashMap::new();
target_props.insert(
"name".to_string(),
Value::String("UpdateTarget".to_string()),
);
let target = client
.create_node(vec!["UpdateTarget".to_string()], target_props)
.await
.unwrap();
let rel = client
.create_relationship(
source.node_id,
target.node_id,
"UPDATE_TEST".to_string(),
HashMap::new(),
)
.await
.unwrap();
let mut update_props = HashMap::new();
update_props.insert("weight".to_string(), Value::Float(2.0));
let update_response = client
.update_relationship(rel.rel_id, update_props)
.await
.unwrap();
assert!(update_response.error.is_none());
}
#[tokio::test]
#[ignore]
async fn test_delete_relationship() {
let client = NexusClient::new("http://localhost:15474").unwrap();
let mut source_props = HashMap::new();
source_props.insert(
"name".to_string(),
Value::String("DeleteSource".to_string()),
);
let source_response = client
.create_node(vec!["DeleteSource".to_string()], source_props)
.await
.unwrap();
let mut target_props = HashMap::new();
target_props.insert(
"name".to_string(),
Value::String("DeleteTarget".to_string()),
);
let target_response = client
.create_node(vec!["DeleteTarget".to_string()], target_props)
.await
.unwrap();
if source_response.error.is_none() && target_response.error.is_none() {
let rel = client
.create_relationship(
source_response.node_id,
target_response.node_id,
"DELETE_TEST".to_string(),
HashMap::new(),
)
.await
.unwrap();
if rel.error.is_none() {
let delete_response = client.delete_relationship(rel.rel_id).await.unwrap();
let _ = delete_response.error;
}
}
}