From f3b837514d4613be7d00e68800cdedf84e6309dc Mon Sep 17 00:00:00 2001 From: Wyatt Verchere Date: Fri, 3 Nov 2023 10:26:33 -0700 Subject: [PATCH] fixed nightly failure --- src/routes/v3/organizations.rs | 14 +++--- src/routes/v3/users.rs | 80 +++++++++++++++++----------------- tests/common/database.rs | 2 +- tests/feed.rs | 5 +-- 4 files changed, 51 insertions(+), 50 deletions(-) diff --git a/src/routes/v3/organizations.rs b/src/routes/v3/organizations.rs index e2093f57..5fe23809 100644 --- a/src/routes/v3/organizations.rs +++ b/src/routes/v3/organizations.rs @@ -53,11 +53,15 @@ pub async fn organization_follow( .insert(&**pool) .await .map_err(|e| match e { - DatabaseError::Database(e) - if e.as_database_error() - .is_some_and(|e| e.is_unique_violation()) => - { - ApiError::InvalidInput("You are already following this organization!".to_string()) + DatabaseError::Database(e) => { + if let Some(db_err) = e.as_database_error() { + if db_err.is_unique_violation() { + return ApiError::InvalidInput( + "You are already following this organization!".to_string(), + ); + } + } + e.into() } e => e.into(), })?; diff --git a/src/routes/v3/users.rs b/src/routes/v3/users.rs index fa2155ea..80f422ea 100644 --- a/src/routes/v3/users.rs +++ b/src/routes/v3/users.rs @@ -72,11 +72,15 @@ pub async fn user_follow( .insert(&**pool) .await .map_err(|e| match e { - DatabaseError::Database(e) - if e.as_database_error() - .is_some_and(|e| e.is_unique_violation()) => - { - ApiError::InvalidInput("You are already following this user!".to_string()) + DatabaseError::Database(e) => { + if let Some(db_err) = e.as_database_error() { + if db_err.is_unique_violation() { + return ApiError::InvalidInput( + "You are already following this user!".to_string(), + ); + } + } + e.into() } e => e.into(), })?; @@ -143,10 +147,7 @@ pub async fn current_user_feed( // - Projects created by organizations you follow // - Versions created by users you follow // - Versions created by organizations you follow - let event_types = [ - EventType::ProjectPublished, - EventType::VersionCreated, - ]; + let event_types = [EventType::ProjectPublished, EventType::VersionCreated]; let selectors = followed_users .into_iter() .flat_map(|follow| { @@ -186,39 +187,38 @@ pub async fn current_user_feed( .await?; for event in events { - let body = - match event.event_data { - EventData::ProjectPublished { - project_id, - creator_id, - } => authorized_projects.get(&project_id.into()).map(|p| { - FeedItemBody::ProjectPublished { - project_id: project_id.into(), + let body = match event.event_data { + EventData::ProjectPublished { + project_id, + creator_id, + } => authorized_projects.get(&project_id.into()).map(|p| { + FeedItemBody::ProjectPublished { + project_id: project_id.into(), + creator_id: creator_id.into(), + project_title: p.title.clone(), + } + }), + EventData::VersionCreated { + version_id, + creator_id, + } => { + let authorized_version = authorized_versions.get(&version_id.into()); + let authorized_project = + authorized_version.and_then(|v| authorized_projects.get(&v.project_id)); + if let (Some(authorized_version), Some(authorized_project)) = + (authorized_version, authorized_project) + { + Some(FeedItemBody::VersionCreated { + project_id: authorized_project.id, + version_id: authorized_version.id, creator_id: creator_id.into(), - project_title: p.title.clone(), - } - }), - EventData::VersionCreated { - version_id, - creator_id, - } => { - let authorized_version = authorized_versions.get(&version_id.into()); - let authorized_project = - authorized_version.and_then(|v| authorized_projects.get(&v.project_id)); - if let (Some(authorized_version), Some(authorized_project)) = - (authorized_version, authorized_project) - { - Some(FeedItemBody::VersionCreated { - project_id: authorized_project.id, - version_id: authorized_version.id, - creator_id: creator_id.into(), - project_title: authorized_project.title.clone(), - }) - } else { - None - } + project_title: authorized_project.title.clone(), + }) + } else { + None } - }; + } + }; if let Some(body) = body { let feed_item = FeedItem { diff --git a/tests/common/database.rs b/tests/common/database.rs index 988cc028..38bf6585 100644 --- a/tests/common/database.rs +++ b/tests/common/database.rs @@ -146,7 +146,7 @@ impl TemporaryDatabase { .fetch_optional(&pool) .await .unwrap(); - let needs_update = !dummy_data_update.is_some_and(|d| d == DUMMY_DATA_UPDATE); + let needs_update = !matches!(dummy_data_update, Some(DUMMY_DATA_UPDATE)); if needs_update { println!("Dummy data updated, so template DB tables will be dropped and re-created"); // Drop all tables in the database so they can be re-created and later filled with updated dummy data diff --git a/tests/feed.rs b/tests/feed.rs index 09efe51c..46324c43 100644 --- a/tests/feed.rs +++ b/tests/feed.rs @@ -1,8 +1,5 @@ use crate::common::{ - asserts::{ - assert_feed_contains_project_created, - assert_feed_contains_version_created, - }, + asserts::{assert_feed_contains_project_created, assert_feed_contains_version_created}, dummy_data::DummyProjectAlpha, }; use assert_matches::assert_matches;