Skip to content

Commit 0889466

Browse files
committed
Add DB test for finding reviewers without review preferences
1 parent 702e727 commit 0889466

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

src/handlers/assign.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ use tracing as log;
3939
#[cfg(test)]
4040
mod tests {
4141
mod tests_candidates;
42+
mod tests_db;
4243
mod tests_from_diff;
4344
}
4445

src/handlers/assign/tests/tests_db.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
}

src/tests.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::db;
22
use crate::db::make_client;
3+
use crate::db::notifications::record_username;
34
use std::future::Future;
45
use 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

0 commit comments

Comments
 (0)