]> Untitled Git - lemmy.git/commitdiff
fix tests
authorFelix Ableitner <me@nutomic.com>
Tue, 23 Aug 2022 19:38:51 +0000 (21:38 +0200)
committerDessalines <dessalines@users.noreply.github.com>
Fri, 2 Sep 2022 14:49:54 +0000 (10:49 -0400)
crates/db_schema/src/impls/local_user.rs
crates/db_views/src/comment_view.rs
crates/db_views/src/post_view.rs
scripts/test.sh

index 8d5370d0ab854741c7e94b4da29085330468c2b7..d2599f4ff51100fdda5605e7e7f1afe4a74c54e8 100644 (file)
@@ -1,7 +1,10 @@
 use crate::{
   newtypes::LocalUserId,
   schema::local_user::dsl::*,
-  source::local_user::{LocalUser, LocalUserForm},
+  source::{
+    local_user::{LocalUser, LocalUserForm},
+    local_user_language::LocalUserLanguage,
+  },
   traits::Crud,
   utils::naive_now,
 };
@@ -115,9 +118,12 @@ impl Crud for LocalUser {
     diesel::delete(local_user.find(local_user_id)).execute(conn)
   }
   fn create(conn: &PgConnection, form: &LocalUserForm) -> Result<Self, Error> {
-    insert_into(local_user)
+    let local_user_ = insert_into(local_user)
       .values(form)
-      .get_result::<Self>(conn)
+      .get_result::<Self>(conn)?;
+    // initialize with all languages
+    LocalUserLanguage::update_user_languages(conn, None, local_user_.id)?;
+    Ok(local_user_)
   }
   fn update(
     conn: &PgConnection,
index d469b0c5fc7b204afc3991b7d231d1529783bc4e..4730e9b7df73a08cc6bbdb7dc29080dad5ad3b61 100644 (file)
@@ -5,8 +5,18 @@ use lemmy_db_schema::{
   aggregates::structs::CommentAggregates,
   newtypes::{CommentId, CommunityId, DbUrl, LocalUserId, PersonId, PostId},
   schema::{
-    comment, comment_aggregates, comment_like, comment_saved, community, community_block,
-    community_follower, community_person_ban, language, local_user_language, person, person_block,
+    comment,
+    comment_aggregates,
+    comment_like,
+    comment_saved,
+    community,
+    community_block,
+    community_follower,
+    community_person_ban,
+    language,
+    local_user_language,
+    person,
+    person_block,
     post,
   },
   source::{
@@ -19,7 +29,8 @@ use lemmy_db_schema::{
   },
   traits::{ToSafe, ViewToVec},
   utils::{functions::hot_rank, fuzzy_search, limit_and_offset_unlimited},
-  CommentSortType, ListingType,
+  CommentSortType,
+  ListingType,
 };
 use typed_builder::TypedBuilder;
 
@@ -378,8 +389,12 @@ mod tests {
     aggregates::structs::CommentAggregates,
     newtypes::LanguageId,
     source::{
-      comment::*, community::*, local_user::LocalUserForm, person::*,
-      person_block::PersonBlockForm, post::*,
+      comment::*,
+      community::*,
+      local_user::LocalUserForm,
+      person::*,
+      person_block::PersonBlockForm,
+      post::*,
     },
     traits::{Blockable, Crud, Likeable},
     utils::establish_unpooled_connection,
@@ -519,6 +534,15 @@ mod tests {
     };
     assert_eq!(expected_block, inserted_block);
 
+    let comment_like_form = CommentLikeForm {
+      comment_id: inserted_comment_0.id,
+      post_id: inserted_post.id,
+      person_id: inserted_person.id,
+      score: 1,
+    };
+
+    let _inserted_comment_like = CommentLike::like(&conn, &comment_like_form).unwrap();
+
     Data {
       inserted_comment_0,
       inserted_comment_1,
@@ -537,15 +561,6 @@ mod tests {
     let conn = establish_unpooled_connection();
     let data = init_data(&conn);
 
-    let comment_like_form = CommentLikeForm {
-      comment_id: data.inserted_comment_0.id,
-      post_id: data.inserted_post.id,
-      person_id: data.inserted_person.id,
-      score: 1,
-    };
-
-    let _inserted_comment_like = CommentLike::like(&conn, &comment_like_form).unwrap();
-
     let expected_comment_view_no_person = expected_comment_view(&data, &conn);
 
     let mut expected_comment_view_with_person = expected_comment_view_no_person.to_owned();
index 78229891eaa87c96dac5f452688dc477d51d579f..f81194f160017e6694e344dd7cc97c9627260595 100644 (file)
@@ -477,8 +477,6 @@ mod tests {
       ..Default::default()
     };
     let inserted_local_user = LocalUser::create(conn, &local_user_form).unwrap();
-    // update user languages to all
-    LocalUserLanguage::update_user_languages(conn, None, inserted_local_user.id).unwrap();
 
     let new_bot = PersonForm {
       name: "mybot".to_string(),
index 513bc3c65b6eff6e06813d5b84191848eaa8daa0..d6b87a6932155e8f1736cb08ed5bc4676afd9ab4 100755 (executable)
@@ -9,5 +9,5 @@ export LEMMY_DATABASE_URL=postgres://lemmy:password@localhost:5432/lemmy
 # so to load the config we need to traverse to the repo root
 export LEMMY_CONFIG_LOCATION=../../config/config.hjson
 RUST_BACKTRACE=1 \
-  cargo test --workspace --no-fail-fast
+  cargo test -p lemmy_db_views --no-fail-fast --all-features
 # Add this to do printlns: -- --nocapture