Skip to content

Commit f0e1254

Browse files
committed
Add test for parsing node properties that are a struct
1 parent a56e2d2 commit f0e1254

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

lib/src/bolt/structs/node.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,10 @@ mod tests {
188188
use serde_test::{assert_de_tokens, Token};
189189
use test_case::{test_case, test_matrix};
190190

191-
use crate::packstream::{bolt, from_bytes_ref, BoltBytesBuilder, Data};
191+
use crate::{
192+
bolt::LegacyDateTime,
193+
packstream::{bolt, from_bytes_ref, BoltBytesBuilder, Data},
194+
};
192195

193196
use super::*;
194197

@@ -335,4 +338,33 @@ mod tests {
335338
.tiny_string("Alice")
336339
.build()
337340
}
341+
342+
fn deserialize_properties_with_structs() {
343+
let mut data = Data::new(
344+
bolt()
345+
.structure(3, 0x4E)
346+
.tiny_int(42)
347+
.tiny_list(1)
348+
.tiny_string("Label")
349+
.tiny_map(1)
350+
.tiny_string("p")
351+
.structure(3, b'F')
352+
.int32(42)
353+
.tiny_int(0)
354+
.tiny_int(0)
355+
.build(),
356+
);
357+
let mut node: NodeRef = from_bytes_ref(&mut data).unwrap();
358+
359+
assert_eq!(node.id(), 42);
360+
assert_eq!(node.labels(), &["Label"]);
361+
assert_eq!(node.element_id(), None);
362+
363+
assert_eq!(node.keys(), &["p"]);
364+
365+
let p = node.get::<LegacyDateTime>("p").unwrap().unwrap();
366+
assert_eq!(p.seconds_since_epoch(), 42);
367+
assert_eq!(p.nanoseconds(), 0);
368+
assert_eq!(p.timezone_offset_seconds(), 0);
369+
}
338370
}

lib/tests/node_property_parsing.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
use chrono::{DateTime, FixedOffset};
2+
use neo4rs::{query, Node};
3+
4+
mod container;
5+
6+
#[tokio::test]
7+
async fn node_property_parsing() {
8+
let neo4j = container::Neo4jContainer::new().await;
9+
let graph = neo4j.graph();
10+
11+
graph
12+
.run(query("CREATE (:A {p1:DATETIME('2024-12-31T08:10:35')})"))
13+
.await
14+
.unwrap();
15+
16+
let mut result = graph.execute(query("MATCH (p:A) RETURN p")).await.unwrap();
17+
18+
while let Ok(Some(row)) = result.next().await {
19+
let node: Node = row.get("p").unwrap();
20+
let p1 = node.get::<DateTime<FixedOffset>>("p1").unwrap();
21+
assert_eq!(p1.timestamp(), 1735632635);
22+
}
23+
}

0 commit comments

Comments
 (0)