Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 5 additions & 3 deletions src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::{

use crate::tests::util::github::next_gh_id;
use diesel::prelude::*;
use diesel_async::{AsyncPgConnection, RunQueryDsl};

mod account_lock;
mod authentication;
Expand Down Expand Up @@ -111,11 +112,11 @@ fn new_team(login: &str) -> NewTeam<'_> {
.build()
}

pub fn add_team_to_crate(
pub async fn add_team_to_crate(
t: &Team,
krate: &Crate,
u: &User,
conn: &mut PgConnection,
conn: &mut AsyncPgConnection,
) -> QueryResult<()> {
let crate_owner = CrateOwner {
crate_id: krate.id,
Expand All @@ -130,7 +131,8 @@ pub fn add_team_to_crate(
.on_conflict(crate_owners::table.primary_key())
.do_update()
.set(crate_owners::deleted.eq(false))
.execute(conn)?;
.execute(conn)
.await?;

Ok(())
}
Expand Down
15 changes: 12 additions & 3 deletions src/tests/owners.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,14 @@ async fn modify_multiple_owners() {
async fn check_ownership_two_crates() {
let (app, anon, user) = TestApp::init().with_user().await;
let mut conn = app.db_conn();
let mut async_conn = app.async_db_conn().await;
let user = user.as_model();

let team = new_team("team_foo").create_or_update(&mut conn).unwrap();
let krate_owned_by_team = CrateBuilder::new("foo", user.id).expect_build(&mut conn);
add_team_to_crate(&team, &krate_owned_by_team, user, &mut conn).unwrap();
add_team_to_crate(&team, &krate_owned_by_team, user, &mut async_conn)
.await
.unwrap();

let user2 = app.db_new_user("user_bar").await;
let user2 = user2.as_model();
Expand All @@ -310,13 +313,16 @@ async fn check_ownership_two_crates() {
async fn check_ownership_one_crate() {
let (app, anon, user) = TestApp::init().with_user().await;
let mut conn = app.db_conn();
let mut async_conn = app.async_db_conn().await;
let user = user.as_model();

let team = new_team("github:test_org:team_sloth")
.create_or_update(&mut conn)
.unwrap();
let krate = CrateBuilder::new("best_crate", user.id).expect_build(&mut conn);
add_team_to_crate(&team, &krate, user, &mut conn).unwrap();
add_team_to_crate(&team, &krate, user, &mut async_conn)
.await
.unwrap();

let json: TeamResponse = anon
.get("/api/v1/crates/best_crate/owner_team")
Expand All @@ -339,13 +345,16 @@ async fn check_ownership_one_crate() {
async fn add_existing_team() {
let (app, _, user, token) = TestApp::init().with_token().await;
let mut conn = app.db_conn();
let mut async_conn = app.async_db_conn().await;
let user = user.as_model();

let t = new_team("github:test_org:bananas")
.create_or_update(&mut conn)
.unwrap();
let krate = CrateBuilder::new("best_crate", user.id).expect_build(&mut conn);
add_team_to_crate(&t, &krate, user, &mut conn).unwrap();
add_team_to_crate(&t, &krate, user, &mut async_conn)
.await
.unwrap();

let ret = token
.add_named_owner("best_crate", "github:test_org:bananas")
Expand Down
10 changes: 8 additions & 2 deletions src/tests/team.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,13 +419,16 @@ async fn add_owners_as_team_owner() {
async fn crates_by_team_id() {
let (app, anon, user) = TestApp::init().with_user().await;
let mut conn = app.db_conn();
let mut async_conn = app.async_db_conn().await;
let user = user.as_model();

let t = new_team("github:test-org:team")
.create_or_update(&mut conn)
.unwrap();
let krate = CrateBuilder::new("foo", user.id).expect_build(&mut conn);
add_team_to_crate(&t, &krate, user, &mut conn).unwrap();
add_team_to_crate(&t, &krate, user, &mut async_conn)
.await
.unwrap();

let json = anon.search(&format!("team_id={}", t.id)).await;
assert_eq!(json.crates.len(), 1);
Expand All @@ -435,6 +438,7 @@ async fn crates_by_team_id() {
async fn crates_by_team_id_not_including_deleted_owners() {
let (app, anon) = TestApp::init().empty().await;
let mut conn = app.db_conn();
let mut async_conn = app.async_db_conn().await;
let user = app.db_new_user("user-all-teams").await;
let user = user.as_model();

Expand All @@ -447,7 +451,9 @@ async fn crates_by_team_id_not_including_deleted_owners() {
let t = new_team.create_or_update(&mut conn).unwrap();

let krate = CrateBuilder::new("foo", user.id).expect_build(&mut conn);
add_team_to_crate(&t, &krate, user, &mut conn).unwrap();
add_team_to_crate(&t, &krate, user, &mut async_conn)
.await
.unwrap();
krate.owner_remove(&mut conn, &t.login).unwrap();

let json = anon.search(&format!("team_id={}", t.id)).await;
Expand Down
6 changes: 3 additions & 3 deletions src/typosquat/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ mod tests {
async fn top_crates() -> Result<(), Error> {
let test_db = TestDatabase::new();
let mut conn = test_db.connect();
let mut async_conn = test_db.async_connect().await;

// Set up two users.
let user_a = faker::user(&mut conn, "a")?;
Expand All @@ -195,10 +196,9 @@ mod tests {

// Let's set up a team that owns both b and c, but not a.
let not_the_a_team = faker::team(&mut conn, "org", "team")?;
add_team_to_crate(&not_the_a_team, &top_b, &user_b, &mut conn)?;
add_team_to_crate(&not_the_a_team, &not_top_c, &user_b, &mut conn)?;
add_team_to_crate(&not_the_a_team, &top_b, &user_b, &mut async_conn).await?;
add_team_to_crate(&not_the_a_team, &not_top_c, &user_b, &mut async_conn).await?;

let mut async_conn = test_db.async_connect().await;
let top_crates = TopCrates::new(&mut async_conn, 2).await?;

// Let's ensure the top crates include what we expect (which is a and b, since we asked for
Expand Down