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;
39
39
#[ cfg( test) ]
40
40
mod tests {
41
41
mod tests_candidates;
42
+ mod tests_db;
42
43
mod tests_from_diff;
43
44
}
44
45
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 1
1
use crate :: db;
2
2
use crate :: db:: make_client;
3
+ use crate :: db:: notifications:: record_username;
3
4
use std:: future:: Future ;
4
5
use tokio_postgres:: Config ;
5
6
@@ -50,6 +51,16 @@ impl TestContext {
50
51
}
51
52
}
52
53
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
+
53
64
async fn finish ( self ) {
54
65
// Cleanup the test database
55
66
// First, we need to stop using the database
You can’t perform that action at this time.
0 commit comments