Skip to content

Commit

Permalink
fix hot tags tests failing based on time of the month (#275)
Browse files Browse the repository at this point in the history
* fix hot tags tests failing based on time of the month

* remove unused params in mock query
  • Loading branch information
amirRamirfatahi authored Jan 13, 2025
1 parent 950be28 commit de24c37
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
22 changes: 9 additions & 13 deletions docker/db-graph/mocks/hot-tags.cypher
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
13 changes: 9 additions & 4 deletions tests/service/tags/hot.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use anyhow::Result;
use chrono::{Datelike, Utc};
use reqwest::StatusCode;
use serde_json::Value;

Expand Down Expand Up @@ -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(())
Expand All @@ -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);

Expand All @@ -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);

Expand Down

0 comments on commit de24c37

Please sign in to comment.