Skip to content

Commit

Permalink
test(webserver): add unit test to cover query all users for anual act… (
Browse files Browse the repository at this point in the history
TabbyML#1838)

* test(webserver): add unit test to cover query all users for anual activites

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
wsxiaoys and autofix-ci[bot] authored Apr 12, 2024
1 parent 9520ec4 commit 6472fe4
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions ee/tabby-webserver/src/service/analytic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,6 @@ mod tests {
.await
.unwrap();

let svc = new_analytic_service(db.clone());
let activity = svc
.daily_stats_in_past_year(vec![user_id.as_id()])
.await
.unwrap();

assert_eq!(1, activity.len());
assert_eq!(1, activity[0].completions);
assert_eq!(1, activity[0].selects);

let user_id2 = db
.create_user("[email protected]".into(), Some("pass".into()), false)
.await
Expand All @@ -139,6 +129,18 @@ mod tests {
.await
.unwrap();

// Query user 1 should return 1 completion and 1 select.
let svc = new_analytic_service(db.clone());
let activity = svc
.daily_stats_in_past_year(vec![user_id.as_id()])
.await
.unwrap();

assert_eq!(1, activity.len());
assert_eq!(1, activity[0].completions);
assert_eq!(1, activity[0].selects);

// Query user 1 + user 2 should return 2 completions and 1 select.
let activity2 = svc
.daily_stats_in_past_year(vec![user_id.as_id(), user_id2.as_id()])
.await
Expand All @@ -147,6 +149,13 @@ mod tests {
assert_eq!(1, activity2.len());
assert_eq!(2, activity2[0].completions);
assert_eq!(1, activity2[0].selects);

// Query all users should return 2 completions and 1 select.
let activity3 = svc.daily_stats_in_past_year(vec![]).await.unwrap();

assert_eq!(1, activity3.len());
assert_eq!(2, activity3[0].completions);
assert_eq!(1, activity3[0].selects);
}

#[tokio::test]
Expand Down

0 comments on commit 6472fe4

Please sign in to comment.