diff --git a/docker/db-graph/mocks/hot-tags.cypher b/docker/db-graph/mocks/hot-tags.cypher index 782f99c3..d5ac9453 100644 --- a/docker/db-graph/mocks/hot-tags.cypher +++ b/docker/db-graph/mocks/hot-tags.cypher @@ -19,10 +19,6 @@ :param tag3 => 'tag3'; -:param day => 24 * 60 * 60 * 1000; - -:param month => 30 * 24 * 60 * 60 * 1000; - // Create the posts MERGE (p:Post { id: $post1 }) SET p.content = "This is a test post", p.kind = "short", p.indexed_at = 1733380839000; @@ -57,39 +53,39 @@ MATCH (u:User { id: $user5 }), (p:Post {id: $post1}) MERGE (u)-[:TAGGED { label: $tag2, id: "0032GZS4DWEGM", indexed_at: today_millis }]->(p); // This month -WITH datetime().epochMillis - (2 * $day) AS this_month_millis +WITH datetime({ year: datetime().year, month: datetime().month, day: 1 }).epochMillis AS this_month_millis MATCH (u:User { id: $user1 }), (p:Post {id: $post2}) MERGE (u)-[:TAGGED { label:$tag1, id: "0032GZR6TQTSG", indexed_at: this_month_millis }]->(p); -WITH datetime().epochMillis - (2 * $day) AS this_month_millis +WITH datetime({ year: datetime().year, month: datetime().month, day: 1 }).epochMillis AS this_month_millis MATCH (u:User { id: $user1 }), (p:Post {id: $post2}) MERGE (u)-[:TAGGED { label:$tag2, id: "0032GZRVBRC3M", indexed_at: this_month_millis }]->(p); -WITH datetime().epochMillis - (2 * $day) AS this_month_millis +WITH datetime({ year: datetime().year, month: datetime().month, day: 1 }).epochMillis AS this_month_millis MATCH (u:User { id: $user3 }), (p:Post {id: $post2}) MERGE (u)-[:TAGGED { label: $tag3, id: "0032GZR6TQTT6", indexed_at: this_month_millis }]->(p); -WITH datetime().epochMillis - (2 * $day) AS this_month_millis +WITH datetime({ year: datetime().year, month: datetime().month, day: 1 }).epochMillis AS this_month_millis MATCH (u:User { id: $user4 }), (p:Post {id: $post2}) MERGE (u)-[:TAGGED { label: $tag3, id: "0032GZR6TQV4P", indexed_at: this_month_millis }]->(p); -WITH datetime().epochMillis - (2 * $day) AS this_month_millis +WITH datetime({ year: datetime().year, month: datetime().month, day: 1 }).epochMillis AS this_month_millis MATCH (u:User { id: $user5 }), (p:Post {id: $post2}) MERGE (u)-[:TAGGED { label: $tag3, id: "0032GZS4DWF62", indexed_at: this_month_millis }]->(p); // All time (outside this month period) -WITH datetime().epochMillis - (7 * $day + $month) AS all_time_millis +WITH (datetime({ year: datetime().year, month: datetime().month, day: 1 }) - Duration({days: 1})).epochMillis AS all_time_millis MATCH (u:User { id: $user1 }), (p:Post {id: $post2}) MERGE (u)-[:TAGGED { label:$tag3, id: "0032GZRG46YPY", indexed_at: all_time_millis }]->(p); -WITH datetime().epochMillis - (7 * $day + $month) AS all_time_millis +WITH (datetime({ year: datetime().year, month: datetime().month, day: 1 }) - Duration({days: 1})).epochMillis AS all_time_millis MATCH (u:User { id: $user3 }), (p:Post {id: $post2}) MERGE (u)-[:TAGGED { label: $tag2, id: "0032GZRG46ZH0", indexed_at: all_time_millis }]->(p); -WITH datetime().epochMillis - (7 * $day + $month) AS all_time_millis +WITH (datetime({ year: datetime().year, month: datetime().month, day: 1 }) - Duration({days: 1})).epochMillis AS all_time_millis MATCH (u:User { id: $user4 }), (p:Post {id: $post2}) MERGE (u)-[:TAGGED { label: $tag1, id: "0032GZRG46ZH6", indexed_at: all_time_millis }]->(p); -WITH datetime().epochMillis - (7 * $day + $month) AS all_time_millis +WITH (datetime({ year: datetime().year, month: datetime().month, day: 1 }) - Duration({days: 1})).epochMillis AS all_time_millis MATCH (u:User { id: $user5 }), (p:Post {id: $post2}) MERGE (u)-[:TAGGED { label: $tag1, id: "0032GZRG46ZH6", indexed_at: all_time_millis }]->(p); diff --git a/tests/service/tags/hot.rs b/tests/service/tags/hot.rs index bf76b167..5ee7159d 100644 --- a/tests/service/tags/hot.rs +++ b/tests/service/tags/hot.rs @@ -1,4 +1,5 @@ use anyhow::Result; +use chrono::{Datelike, Utc}; use reqwest::StatusCode; use serde_json::Value; @@ -83,8 +84,12 @@ async fn test_global_hot_tags_with_today_timeframe() -> Result<()> { // Validate that the posts belong to the specified user's bookmarks analyse_hot_tags_structure(tags); - // Analyse the tag that is in the 4th index - let hot_tag = StreamTagMockup::new(String::from("tag2"), 2, 1, 2); + // Analyse the first tag + // if the test is run at the first day of the month the tags from thisMonth timeframe overlap with today + let hot_tag = match Utc::now().day() { + 1 => StreamTagMockup::new(String::from("tag2"), 3, 2, 3), + _ => StreamTagMockup::new(String::from("tag2"), 2, 1, 2), + }; compare_unit_hot_tag(&tags[0], hot_tag); Ok(()) @@ -101,7 +106,7 @@ async fn test_global_hot_tags_with_this_month_timeframe() -> Result<()> { // Validate that the posts belong to the specified user's bookmarks analyse_hot_tags_structure(tags); - // Analyse the tag that is in the 4th index + // Analyse the first tag let hot_tag = StreamTagMockup::new(String::from("tag2"), 3, 2, 3); compare_unit_hot_tag(&tags[0], hot_tag); @@ -122,7 +127,7 @@ async fn test_global_hot_tags_skip_limit() -> Result<()> { // assert limit assert_eq!(tags.len(), 5); - // Analyse the tag that is in the 4th index + // Analyse the first tag let hot_tag = StreamTagMockup::new(String::from("ha"), 9, 16, 9); compare_unit_hot_tag(&tags[0], hot_tag);