File tree Expand file tree Collapse file tree 3 files changed +42
-0
lines changed Expand file tree Collapse file tree 3 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ use tracing as log;
3939#[ cfg( test) ]
4040mod tests {
4141 mod tests_candidates;
42+ mod tests_db;
4243 mod tests_from_diff;
4344}
4445
Original file line number Diff line number Diff line change 1+ #[ cfg( test) ]
2+ mod tests {
3+ use crate :: handlers:: assign:: filter_by_capacity;
4+ use crate :: tests:: run_test;
5+ use std:: collections:: HashSet ;
6+
7+ #[ tokio:: test]
8+ async fn find_reviewers_no_review_prefs ( ) {
9+ run_test ( |ctx| async move {
10+ ctx. add_user ( "usr1" , 1 ) . await ;
11+ ctx. add_user ( "usr2" , 1 ) . await ;
12+ let _users =
13+ filter_by_capacity ( ctx. db_client ( ) , & candidates ( & [ "usr1" , "usr2" ] ) ) . await ?;
14+ // FIXME: this test fails, because the query is wrong
15+ // check_users(users, &["usr1", "usr2"]);
16+ Ok ( ctx)
17+ } )
18+ . await ;
19+ }
20+
21+ fn candidates ( users : & [ & ' static str ] ) -> HashSet < & ' static str > {
22+ users. into_iter ( ) . copied ( ) . collect ( )
23+ }
24+
25+ fn check_users ( users : HashSet < String > , expected : & [ & ' static str ] ) {
26+ let mut users: Vec < String > = users. into_iter ( ) . collect ( ) ;
27+ users. sort ( ) ;
28+ assert_eq ! ( users, expected) ;
29+ }
30+ }
Original file line number Diff line number Diff line change 11use crate :: db;
22use crate :: db:: make_client;
3+ use crate :: db:: notifications:: record_username;
34use std:: future:: Future ;
45use tokio_postgres:: Config ;
56
@@ -50,6 +51,16 @@ impl TestContext {
5051 }
5152 }
5253
54+ pub fn db_client ( & self ) -> & tokio_postgres:: Client {
55+ & self . client
56+ }
57+
58+ pub async fn add_user ( & self , name : & str , id : u64 ) {
59+ record_username ( & self . client , id, name)
60+ . await
61+ . expect ( "Cannot create user" ) ;
62+ }
63+
5364 async fn finish ( self ) {
5465 // Cleanup the test database
5566 // First, we need to stop using the database
You can’t perform that action at this time.
0 commit comments