Skip to content

Commit 45a2136

Browse files
authored
fix(api): duplicate results in types (#46)
* fix(api): duplicate results in types * fix: tests
1 parent 24162e1 commit 45a2136

File tree

2 files changed

+8
-129
lines changed

2 files changed

+8
-129
lines changed

grc20-core/src/mapping/entity/find_many.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl QueryStream<EntityNode> for FindManyQuery<EntityNode> {
121121
) -> Result<impl Stream<Item = Result<EntityNode, DatabaseError>>, DatabaseError> {
122122
let neo4j = self.neo4j.clone();
123123

124-
let query = self.subquery().r#return("e");
124+
let query = self.subquery().r#return("DISTINCT e");
125125

126126
if cfg!(debug_assertions) || cfg!(test) {
127127
tracing::info!(

grc20-core/src/mapping/triple.rs

Lines changed: 7 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -713,35 +713,10 @@ impl Query<()> for DeleteManyQuery {
713713
mod tests {
714714
use super::*;
715715

716-
use testcontainers::{
717-
core::{IntoContainerPort, WaitFor},
718-
runners::AsyncRunner,
719-
GenericImage, ImageExt,
720-
};
721-
722-
const BOLT_PORT: u16 = 7687;
723-
const HTTP_PORT: u16 = 7474;
724-
725716
#[tokio::test]
726717
async fn test_find_one() {
727718
// Setup a local Neo 4J container for testing. NOTE: docker service must be running.
728-
let container = GenericImage::new("neo4j", "2025.01.0-community")
729-
.with_wait_for(WaitFor::Duration {
730-
length: std::time::Duration::from_secs(5),
731-
})
732-
.with_exposed_port(BOLT_PORT.tcp())
733-
.with_exposed_port(HTTP_PORT.tcp())
734-
.with_env_var("NEO4J_AUTH", "none")
735-
.start()
736-
.await
737-
.expect("Failed to start Neo 4J container");
738-
739-
let port = container.get_host_port_ipv4(BOLT_PORT).await.unwrap();
740-
let host = container.get_host().await.unwrap().to_string();
741-
742-
let neo4j = neo4rs::Graph::new(format!("neo4j://{host}:{port}"), "user", "password")
743-
.await
744-
.unwrap();
719+
let (_container, neo4j) = crate::test_utils::setup_neo4j().await;
745720

746721
neo4j.run(
747722
neo4rs::query(r#"CREATE (:Entity {id: "abc"}) -[:ATTRIBUTE {space_id: "ROOT", min_version: 0}]-> (:Attribute {id: "name", value: "Alice", value_type: "TEXT"})"#)
@@ -767,23 +742,7 @@ mod tests {
767742
#[tokio::test]
768743
async fn test_insert_find_one() {
769744
// Setup a local Neo 4J container for testing. NOTE: docker service must be running.
770-
let container = GenericImage::new("neo4j", "2025.01.0-community")
771-
.with_wait_for(WaitFor::Duration {
772-
length: std::time::Duration::from_secs(5),
773-
})
774-
.with_exposed_port(BOLT_PORT.tcp())
775-
.with_exposed_port(HTTP_PORT.tcp())
776-
.with_env_var("NEO4J_AUTH", "none")
777-
.start()
778-
.await
779-
.expect("Failed to start Neo 4J container");
780-
781-
let port = container.get_host_port_ipv4(BOLT_PORT).await.unwrap();
782-
let host = container.get_host().await.unwrap().to_string();
783-
784-
let neo4j = neo4rs::Graph::new(format!("neo4j://{host}:{port}"), "user", "password")
785-
.await
786-
.unwrap();
745+
let (_container, neo4j) = crate::test_utils::setup_neo4j().await;
787746

788747
let triple = Triple {
789748
entity: "abc".to_string(),
@@ -810,23 +769,7 @@ mod tests {
810769
#[tokio::test]
811770
pub async fn test_insert_many() {
812771
// Setup a local Neo 4J container for testing. NOTE: docker service must be running.
813-
let container = GenericImage::new("neo4j", "2025.01.0-community")
814-
.with_wait_for(WaitFor::Duration {
815-
length: std::time::Duration::from_secs(5),
816-
})
817-
.with_exposed_port(BOLT_PORT.tcp())
818-
.with_exposed_port(HTTP_PORT.tcp())
819-
.with_env_var("NEO4J_AUTH", "none")
820-
.start()
821-
.await
822-
.expect("Failed to start Neo 4J container");
823-
824-
let port = container.get_host_port_ipv4(BOLT_PORT).await.unwrap();
825-
let host = container.get_host().await.unwrap().to_string();
826-
827-
let neo4j = neo4rs::Graph::new(format!("neo4j://{host}:{port}"), "user", "password")
828-
.await
829-
.unwrap();
772+
let (_container, neo4j) = crate::test_utils::setup_neo4j().await;
830773

831774
let triple = Triple {
832775
entity: "abc".to_string(),
@@ -866,23 +809,7 @@ mod tests {
866809
#[tokio::test]
867810
pub async fn test_insert_find_many() {
868811
// Setup a local Neo 4J container for testing. NOTE: docker service must be running.
869-
let container = GenericImage::new("neo4j", "2025.01.0-community")
870-
.with_wait_for(WaitFor::Duration {
871-
length: std::time::Duration::from_secs(5),
872-
})
873-
.with_exposed_port(BOLT_PORT.tcp())
874-
.with_exposed_port(HTTP_PORT.tcp())
875-
.with_env_var("NEO4J_AUTH", "none")
876-
.start()
877-
.await
878-
.expect("Failed to start Neo 4J container");
879-
880-
let port = container.get_host_port_ipv4(BOLT_PORT).await.unwrap();
881-
let host = container.get_host().await.unwrap().to_string();
882-
883-
let neo4j = neo4rs::Graph::new(format!("neo4j://{host}:{port}"), "user", "password")
884-
.await
885-
.unwrap();
812+
let (_container, neo4j) = crate::test_utils::setup_neo4j().await;
886813

887814
let triple = Triple {
888815
entity: "abc".to_string(),
@@ -930,23 +857,7 @@ mod tests {
930857
#[tokio::test]
931858
async fn test_versioning() {
932859
// Setup a local Neo 4J container for testing. NOTE: docker service must be running.
933-
let container = GenericImage::new("neo4j", "2025.01.0-community")
934-
.with_wait_for(WaitFor::Duration {
935-
length: std::time::Duration::from_secs(5),
936-
})
937-
.with_exposed_port(BOLT_PORT.tcp())
938-
.with_exposed_port(HTTP_PORT.tcp())
939-
.with_env_var("NEO4J_AUTH", "none")
940-
.start()
941-
.await
942-
.expect("Failed to start Neo 4J container");
943-
944-
let port = container.get_host_port_ipv4(BOLT_PORT).await.unwrap();
945-
let host = container.get_host().await.unwrap().to_string();
946-
947-
let neo4j = neo4rs::Graph::new(format!("neo4j://{host}:{port}"), "user", "password")
948-
.await
949-
.unwrap();
860+
let (_container, neo4j) = crate::test_utils::setup_neo4j().await;
950861

951862
let triple_v1 = Triple {
952863
entity: "abc".to_string(),
@@ -1008,23 +919,7 @@ mod tests {
1008919
#[tokio::test]
1009920
async fn test_update_no_versioning() {
1010921
// Setup a local Neo 4J container for testing. NOTE: docker service must be running.
1011-
let container = GenericImage::new("neo4j", "2025.01.0-community")
1012-
.with_wait_for(WaitFor::Duration {
1013-
length: std::time::Duration::from_secs(5),
1014-
})
1015-
.with_exposed_port(BOLT_PORT.tcp())
1016-
.with_exposed_port(HTTP_PORT.tcp())
1017-
.with_env_var("NEO4J_AUTH", "none")
1018-
.start()
1019-
.await
1020-
.expect("Failed to start Neo 4J container");
1021-
1022-
let port = container.get_host_port_ipv4(BOLT_PORT).await.unwrap();
1023-
let host = container.get_host().await.unwrap().to_string();
1024-
1025-
let neo4j = neo4rs::Graph::new(format!("neo4j://{host}:{port}"), "user", "password")
1026-
.await
1027-
.unwrap();
922+
let (_container, neo4j) = crate::test_utils::setup_neo4j().await;
1028923

1029924
let triple_v1 = Triple {
1030925
entity: "abc".to_string(),
@@ -1085,23 +980,7 @@ mod tests {
1085980
#[tokio::test]
1086981
async fn test_delete() {
1087982
// Setup a local Neo 4J container for testing. NOTE: docker service must be running.
1088-
let container = GenericImage::new("neo4j", "2025.01.0-community")
1089-
.with_wait_for(WaitFor::Duration {
1090-
length: std::time::Duration::from_secs(5),
1091-
})
1092-
.with_exposed_port(BOLT_PORT.tcp())
1093-
.with_exposed_port(HTTP_PORT.tcp())
1094-
.with_env_var("NEO4J_AUTH", "none")
1095-
.start()
1096-
.await
1097-
.expect("Failed to start Neo 4J container");
1098-
1099-
let port = container.get_host_port_ipv4(BOLT_PORT).await.unwrap();
1100-
let host = container.get_host().await.unwrap().to_string();
1101-
1102-
let neo4j = neo4rs::Graph::new(format!("neo4j://{host}:{port}"), "user", "password")
1103-
.await
1104-
.unwrap();
983+
let (_container, neo4j) = crate::test_utils::setup_neo4j().await;
1105984

1106985
let triple = Triple {
1107986
entity: "abc".to_string(),

0 commit comments

Comments
 (0)