Skip to content

Commit 3e09d59

Browse files
authored
tests/owners: Migrate to diesel-async queries (#9991)
1 parent db62001 commit 3e09d59

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

src/tests/owners.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use crate::{
1515
use crate::schema::users;
1616
use chrono::{Duration, Utc};
1717
use diesel::prelude::*;
18+
use diesel_async::RunQueryDsl;
1819
use http::StatusCode;
1920
use insta::assert_snapshot;
2021
use serde_json::json;
@@ -128,7 +129,7 @@ impl MockAnonymousUser {
128129
#[tokio::test(flavor = "multi_thread")]
129130
async fn new_crate_owner() {
130131
let (app, _, _, token) = TestApp::full().with_token().await;
131-
let mut conn = app.db_conn();
132+
let mut conn = app.async_db_conn().await;
132133

133134
// Create a crate under one user
134135
let crate_to_publish = PublishBuilder::new("foo_owner", "1.0.0");
@@ -141,7 +142,7 @@ async fn new_crate_owner() {
141142
assert_snapshot!(app.emails_snapshot().await);
142143

143144
// accept invitation for user to be added as owner
144-
let krate: Crate = Crate::by_name("foo_owner").first(&mut conn).unwrap();
145+
let krate: Crate = Crate::by_name("foo_owner").first(&mut conn).await.unwrap();
145146
user2
146147
.accept_ownership_invitation("foo_owner", krate.id)
147148
.await;
@@ -465,7 +466,7 @@ async fn invitations_list_does_not_include_expired_invites_v1() {
465466
.good();
466467

467468
// Simulate one of the invitations expiring
468-
expire_invitation(&app, krate1.id);
469+
expire_invitation(&app, krate1.id).await;
469470

470471
let invitations = user.list_invitations().await;
471472
assert_eq!(
@@ -588,10 +589,10 @@ async fn test_accept_invitation_by_mail() {
588589

589590
/// Hacky way to simulate the expiration of an ownership invitation. Instead of letting a month
590591
/// pass, the creation date of the invite is moved back a month.
591-
pub fn expire_invitation(app: &TestApp, crate_id: i32) {
592+
pub async fn expire_invitation(app: &TestApp, crate_id: i32) {
592593
use crate::schema::crate_owner_invitations;
593594

594-
let mut conn = app.db_conn();
595+
let mut conn = app.async_db_conn().await;
595596

596597
let expiration = app.as_inner().config.ownership_invitations_expiration_days as i64;
597598
let created_at = (Utc::now() - Duration::days(expiration)).naive_utc();
@@ -600,6 +601,7 @@ pub fn expire_invitation(app: &TestApp, crate_id: i32) {
600601
.set(crate_owner_invitations::created_at.eq(created_at))
601602
.filter(crate_owner_invitations::crate_id.eq(crate_id))
602603
.execute(&mut conn)
604+
.await
603605
.expect("failed to override the creation time");
604606
}
605607

@@ -619,7 +621,7 @@ async fn test_accept_expired_invitation() {
619621
.good();
620622

621623
// Manually update the creation time to simulate the invite expiring
622-
expire_invitation(&app, krate.id);
624+
expire_invitation(&app, krate.id).await;
623625

624626
// New owner tries to accept the invitation but it fails
625627
let resp = invited_user
@@ -659,7 +661,7 @@ async fn test_decline_expired_invitation() {
659661
.good();
660662

661663
// Manually update the creation time to simulate the invite expiring
662-
expire_invitation(&app, krate.id);
664+
expire_invitation(&app, krate.id).await;
663665

664666
// New owner declines the invitation and it succeeds, even though the invitation expired.
665667
invited_user
@@ -687,7 +689,7 @@ async fn test_accept_expired_invitation_by_mail() {
687689
.good();
688690

689691
// Manually update the creation time to simulate the invite expiring
690-
expire_invitation(&app, krate.id);
692+
expire_invitation(&app, krate.id).await;
691693

692694
// Retrieve the ownership invitation
693695
let invite_token = extract_token_from_invite_email(&app.emails().await);
@@ -719,7 +721,7 @@ async fn inactive_users_dont_get_invitations() {
719721
use crate::models::NewUser;
720722

721723
let (app, _, owner, owner_token) = TestApp::init().with_token().await;
722-
let mut conn = app.db_conn();
724+
let mut conn = app.async_db_conn().await;
723725
let owner = owner.as_model();
724726

725727
// An inactive user with gh_id -1 and an active user with a non-negative gh_id both exist
@@ -737,8 +739,10 @@ async fn inactive_users_dont_get_invitations() {
737739
diesel::insert_into(users::table)
738740
.values(user)
739741
.execute(&mut conn)
742+
.await
740743
.unwrap();
741744

745+
let mut conn = app.db_conn();
742746
CrateBuilder::new(krate_name, owner.id).expect_build(&mut conn);
743747

744748
let invited_user = app.db_new_user(invited_gh_login).await;

src/tests/routes/crates/owners/add.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ async fn invite_with_existing_expired_invite() {
249249
assert_eq!(app.emails().await.len(), 1);
250250

251251
// Simulate the previous invite expiring
252-
expire_invitation(&app, krate.id);
252+
expire_invitation(&app, krate.id).await;
253253

254254
// Then invite the user a second time, a new invite is created as the old one expired
255255
let response = owner.add_named_owner("crate_name", "invited_user").await;

src/tests/routes/private/crate_owner_invitations.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ async fn invitations_list_does_not_include_expired_invites() {
182182
.good();
183183

184184
// Simulate one of the invitations expiring
185-
crate::tests::owners::expire_invitation(&app, crate1.id);
185+
crate::tests::owners::expire_invitation(&app, crate1.id).await;
186186

187187
// user1 has an invite just for crate 2
188188
let invitations = get_invitations(&user, &format!("invitee_id={}", user.as_model().id)).await;

0 commit comments

Comments
 (0)