Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix hot tags tests failing based on time of the month #275

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions docker/db-graph/mocks/hot-tags.cypher
Original file line number Diff line number Diff line change
Expand Up @@ -57,39 +57,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
Loading