diff --git a/crates/api/src/lib.rs b/crates/api/src/lib.rs index 8c7eab9c6..4fdece0b4 100644 --- a/crates/api/src/lib.rs +++ b/crates/api/src/lib.rs @@ -178,12 +178,14 @@ pub(crate) fn captcha_as_wav_base64(captcha: &Captcha) -> String { #[cfg(test)] mod tests { - use language_tags::LanguageTag; use lemmy_api_common::check_validator_time; use lemmy_db_queries::{establish_unpooled_connection, source::local_user::LocalUser_, Crud}; - use lemmy_db_schema::source::{ - local_user::{LocalUser, LocalUserForm}, - person::{Person, PersonForm}, + use lemmy_db_schema::{ + source::{ + local_user::{LocalUser, LocalUserForm}, + person::{Person, PersonForm}, + }, + PrimaryLanguageTag, }; use lemmy_utils::claims::Claims; @@ -201,7 +203,7 @@ mod tests { let local_user_form = LocalUserForm { person_id: inserted_person.id, password_encrypted: "123456".to_string(), - discussion_languages: Some(vec![LanguageTag::parse("en").unwrap().into()]), + discussion_languages: Some(vec![PrimaryLanguageTag("en".to_string())]), ..LocalUserForm::default() }; diff --git a/crates/db_queries/src/aggregates/comment_aggregates.rs b/crates/db_queries/src/aggregates/comment_aggregates.rs index 9184eaf19..7a753d006 100644 --- a/crates/db_queries/src/aggregates/comment_aggregates.rs +++ b/crates/db_queries/src/aggregates/comment_aggregates.rs @@ -29,12 +29,14 @@ mod tests { Crud, Likeable, }; - use language_tags::LanguageTag; - use lemmy_db_schema::source::{ - comment::{Comment, CommentForm, CommentLike, CommentLikeForm}, - community::{Community, CommunityForm}, - person::{Person, PersonForm}, - post::{Post, PostForm}, + use lemmy_db_schema::{ + source::{ + comment::{Comment, CommentForm, CommentLike, CommentLikeForm}, + community::{Community, CommunityForm}, + person::{Person, PersonForm}, + post::{Post, PostForm}, + }, + PrimaryLanguageTag, }; use serial_test::serial; @@ -69,7 +71,7 @@ mod tests { name: "A test post".into(), creator_id: inserted_person.id, community_id: inserted_community.id, - language: Some(LanguageTag::parse("en").unwrap().into()), + language: Some(PrimaryLanguageTag("en".to_string())), ..PostForm::default() }; @@ -79,7 +81,7 @@ mod tests { content: "A test comment".into(), creator_id: inserted_person.id, post_id: inserted_post.id, - language: Some(LanguageTag::parse("en").unwrap().into()), + language: Some(PrimaryLanguageTag("en".to_string())), ..CommentForm::default() }; @@ -90,7 +92,7 @@ mod tests { creator_id: inserted_person.id, post_id: inserted_post.id, parent_id: Some(inserted_comment.id), - language: Some(LanguageTag::parse("en").unwrap().into()), + language: Some(PrimaryLanguageTag("en".to_string())), ..CommentForm::default() }; diff --git a/crates/db_queries/src/aggregates/community_aggregates.rs b/crates/db_queries/src/aggregates/community_aggregates.rs index c82caf665..4daa2945a 100644 --- a/crates/db_queries/src/aggregates/community_aggregates.rs +++ b/crates/db_queries/src/aggregates/community_aggregates.rs @@ -33,12 +33,14 @@ mod tests { Crud, Followable, }; - use language_tags::LanguageTag; - use lemmy_db_schema::source::{ - comment::{Comment, CommentForm}, - community::{Community, CommunityFollower, CommunityFollowerForm, CommunityForm}, - person::{Person, PersonForm}, - post::{Post, PostForm}, + use lemmy_db_schema::{ + source::{ + comment::{Comment, CommentForm}, + community::{Community, CommunityFollower, CommunityFollowerForm, CommunityForm}, + person::{Person, PersonForm}, + post::{Post, PostForm}, + }, + PrimaryLanguageTag, }; use serial_test::serial; @@ -105,7 +107,7 @@ mod tests { name: "A test post".into(), creator_id: inserted_person.id, community_id: inserted_community.id, - language: Some(LanguageTag::parse("en").unwrap().into()), + language: Some(PrimaryLanguageTag("en".to_string())), ..PostForm::default() }; @@ -115,7 +117,7 @@ mod tests { content: "A test comment".into(), creator_id: inserted_person.id, post_id: inserted_post.id, - language: Some(LanguageTag::parse("en").unwrap().into()), + language: Some(PrimaryLanguageTag("en".to_string())), ..CommentForm::default() }; @@ -126,7 +128,7 @@ mod tests { creator_id: inserted_person.id, post_id: inserted_post.id, parent_id: Some(inserted_comment.id), - language: Some(LanguageTag::parse("en").unwrap().into()), + language: Some(PrimaryLanguageTag("en".to_string())), ..CommentForm::default() }; diff --git a/crates/db_queries/src/aggregates/person_aggregates.rs b/crates/db_queries/src/aggregates/person_aggregates.rs index 0e0eea5ac..62c04de74 100644 --- a/crates/db_queries/src/aggregates/person_aggregates.rs +++ b/crates/db_queries/src/aggregates/person_aggregates.rs @@ -29,12 +29,14 @@ mod tests { Crud, Likeable, }; - use language_tags::LanguageTag; - use lemmy_db_schema::source::{ - comment::{Comment, CommentForm, CommentLike, CommentLikeForm}, - community::{Community, CommunityForm}, - person::{Person, PersonForm}, - post::{Post, PostForm, PostLike, PostLikeForm}, + use lemmy_db_schema::{ + source::{ + comment::{Comment, CommentForm, CommentLike, CommentLikeForm}, + community::{Community, CommunityForm}, + person::{Person, PersonForm}, + post::{Post, PostForm, PostLike, PostLikeForm}, + }, + PrimaryLanguageTag, }; use serial_test::serial; @@ -69,7 +71,7 @@ mod tests { name: "A test post".into(), creator_id: inserted_person.id, community_id: inserted_community.id, - language: Some(LanguageTag::parse("en").unwrap().into()), + language: Some(PrimaryLanguageTag("en".to_string())), ..PostForm::default() }; @@ -87,7 +89,7 @@ mod tests { content: "A test comment".into(), creator_id: inserted_person.id, post_id: inserted_post.id, - language: Some(LanguageTag::parse("en").unwrap().into()), + language: Some(PrimaryLanguageTag("en".to_string())), ..CommentForm::default() }; @@ -107,7 +109,7 @@ mod tests { creator_id: inserted_person.id, post_id: inserted_post.id, parent_id: Some(inserted_comment.id), - language: Some(LanguageTag::parse("en").unwrap().into()), + language: Some(PrimaryLanguageTag("en".to_string())), ..CommentForm::default() }; diff --git a/crates/db_queries/src/aggregates/post_aggregates.rs b/crates/db_queries/src/aggregates/post_aggregates.rs index 24f224a34..5025735df 100644 --- a/crates/db_queries/src/aggregates/post_aggregates.rs +++ b/crates/db_queries/src/aggregates/post_aggregates.rs @@ -33,12 +33,14 @@ mod tests { Crud, Likeable, }; - use language_tags::LanguageTag; - use lemmy_db_schema::source::{ - comment::{Comment, CommentForm}, - community::{Community, CommunityForm}, - person::{Person, PersonForm}, - post::{Post, PostForm, PostLike, PostLikeForm}, + use lemmy_db_schema::{ + source::{ + comment::{Comment, CommentForm}, + community::{Community, CommunityForm}, + person::{Person, PersonForm}, + post::{Post, PostForm, PostLike, PostLikeForm}, + }, + PrimaryLanguageTag, }; use serial_test::serial; @@ -73,7 +75,7 @@ mod tests { name: "A test post".into(), creator_id: inserted_person.id, community_id: inserted_community.id, - language: Some(LanguageTag::parse("en").unwrap().into()), + language: Some(PrimaryLanguageTag("en".to_string())), ..PostForm::default() }; @@ -83,7 +85,7 @@ mod tests { content: "A test comment".into(), creator_id: inserted_person.id, post_id: inserted_post.id, - language: Some(LanguageTag::parse("en").unwrap().into()), + language: Some(PrimaryLanguageTag("en".to_string())), ..CommentForm::default() }; @@ -94,7 +96,7 @@ mod tests { creator_id: inserted_person.id, post_id: inserted_post.id, parent_id: Some(inserted_comment.id), - language: Some(LanguageTag::parse("en").unwrap().into()), + language: Some(PrimaryLanguageTag("en".to_string())), ..CommentForm::default() }; diff --git a/crates/db_queries/src/aggregates/site_aggregates.rs b/crates/db_queries/src/aggregates/site_aggregates.rs index d724af9e9..c7110fb63 100644 --- a/crates/db_queries/src/aggregates/site_aggregates.rs +++ b/crates/db_queries/src/aggregates/site_aggregates.rs @@ -26,13 +26,15 @@ impl SiteAggregates { #[cfg(test)] mod tests { use crate::{aggregates::site_aggregates::SiteAggregates, establish_unpooled_connection, Crud}; - use language_tags::LanguageTag; - use lemmy_db_schema::source::{ - comment::{Comment, CommentForm}, - community::{Community, CommunityForm}, - person::{Person, PersonForm}, - post::{Post, PostForm}, - site::{Site, SiteForm}, + use lemmy_db_schema::{ + source::{ + comment::{Comment, CommentForm}, + community::{Community, CommunityForm}, + person::{Person, PersonForm}, + post::{Post, PostForm}, + site::{Site, SiteForm}, + }, + PrimaryLanguageTag, }; use serial_test::serial; @@ -75,7 +77,7 @@ mod tests { name: "A test post".into(), creator_id: inserted_person.id, community_id: inserted_community.id, - language: Some(LanguageTag::parse("en").unwrap().into()), + language: Some(PrimaryLanguageTag("en".to_string())), ..PostForm::default() }; @@ -87,7 +89,7 @@ mod tests { content: "A test comment".into(), creator_id: inserted_person.id, post_id: inserted_post.id, - language: Some(LanguageTag::parse("en").unwrap().into()), + language: Some(PrimaryLanguageTag("en".to_string())), ..CommentForm::default() }; @@ -99,7 +101,7 @@ mod tests { creator_id: inserted_person.id, post_id: inserted_post.id, parent_id: Some(inserted_comment.id), - language: Some(LanguageTag::parse("en").unwrap().into()), + language: Some(PrimaryLanguageTag("en".to_string())), ..CommentForm::default() }; diff --git a/crates/db_queries/src/source/comment.rs b/crates/db_queries/src/source/comment.rs index 30f5c014a..9360cc16a 100644 --- a/crates/db_queries/src/source/comment.rs +++ b/crates/db_queries/src/source/comment.rs @@ -231,12 +231,14 @@ impl Saveable for CommentSaved { #[cfg(test)] mod tests { use crate::{establish_unpooled_connection, Crud, Likeable, Saveable}; - use language_tags::LanguageTag; - use lemmy_db_schema::source::{ - comment::*, - community::{Community, CommunityForm}, - person::{Person, PersonForm}, - post::*, + use lemmy_db_schema::{ + source::{ + comment::*, + community::{Community, CommunityForm}, + person::{Person, PersonForm}, + post::*, + }, + PrimaryLanguageTag, }; use serial_test::serial; @@ -264,7 +266,7 @@ mod tests { name: "A test post".into(), creator_id: inserted_person.id, community_id: inserted_community.id, - language: Some(LanguageTag::parse("en").unwrap().into()), + language: Some(PrimaryLanguageTag("en".to_string())), ..PostForm::default() }; @@ -274,7 +276,7 @@ mod tests { content: "A test comment".into(), creator_id: inserted_person.id, post_id: inserted_post.id, - language: Some(LanguageTag::parse("en").unwrap().into()), + language: Some(PrimaryLanguageTag("en".to_string())), ..CommentForm::default() }; @@ -293,7 +295,7 @@ mod tests { updated: None, ap_id: inserted_comment.ap_id.to_owned(), local: true, - language: LanguageTag::parse("en").unwrap().into(), + language: PrimaryLanguageTag("en".to_string()), }; let child_comment_form = CommentForm { @@ -301,7 +303,7 @@ mod tests { creator_id: inserted_person.id, post_id: inserted_post.id, parent_id: Some(inserted_comment.id), - language: Some(LanguageTag::parse("en").unwrap().into()), + language: Some(PrimaryLanguageTag("en".to_string())), ..CommentForm::default() }; diff --git a/crates/db_queries/src/source/moderator.rs b/crates/db_queries/src/source/moderator.rs index ce8357297..019bbe426 100644 --- a/crates/db_queries/src/source/moderator.rs +++ b/crates/db_queries/src/source/moderator.rs @@ -198,8 +198,10 @@ impl Crud for ModAdd { #[cfg(test)] mod tests { use crate::{establish_unpooled_connection, Crud}; - use language_tags::LanguageTag; - use lemmy_db_schema::source::{comment::*, community::*, moderator::*, person::*, post::*}; + use lemmy_db_schema::{ + source::{comment::*, community::*, moderator::*, person::*, post::*}, + PrimaryLanguageTag, + }; use serial_test::serial; // use Crud; @@ -234,7 +236,7 @@ mod tests { name: "A test post thweep".into(), creator_id: inserted_person.id, community_id: inserted_community.id, - language: Some(LanguageTag::parse("en").unwrap().into()), + language: Some(PrimaryLanguageTag("en".to_string())), ..PostForm::default() }; @@ -244,7 +246,7 @@ mod tests { content: "A test comment".into(), creator_id: inserted_person.id, post_id: inserted_post.id, - language: Some(LanguageTag::parse("en").unwrap().into()), + language: Some(PrimaryLanguageTag("en".to_string())), ..CommentForm::default() }; diff --git a/crates/db_queries/src/source/password_reset_request.rs b/crates/db_queries/src/source/password_reset_request.rs index c5c58a8e1..122087b41 100644 --- a/crates/db_queries/src/source/password_reset_request.rs +++ b/crates/db_queries/src/source/password_reset_request.rs @@ -81,11 +81,13 @@ mod tests { source::password_reset_request::PasswordResetRequest_, Crud, }; - use language_tags::LanguageTag; - use lemmy_db_schema::source::{ - local_user::{LocalUser, LocalUserForm}, - password_reset_request::PasswordResetRequest, - person::*, + use lemmy_db_schema::{ + source::{ + local_user::{LocalUser, LocalUserForm}, + password_reset_request::PasswordResetRequest, + person::*, + }, + PrimaryLanguageTag, }; use serial_test::serial; @@ -104,7 +106,7 @@ mod tests { let new_local_user = LocalUserForm { person_id: inserted_person.id, password_encrypted: "pass".to_string(), - discussion_languages: Some(vec![LanguageTag::parse("en").unwrap().into()]), + discussion_languages: Some(vec![PrimaryLanguageTag("en".to_string())]), ..LocalUserForm::default() }; diff --git a/crates/db_queries/src/source/person_mention.rs b/crates/db_queries/src/source/person_mention.rs index 2af3e6253..cc614dfa4 100644 --- a/crates/db_queries/src/source/person_mention.rs +++ b/crates/db_queries/src/source/person_mention.rs @@ -74,13 +74,15 @@ impl PersonMention_ for PersonMention { #[cfg(test)] mod tests { use crate::{establish_unpooled_connection, Crud}; - use language_tags::LanguageTag; - use lemmy_db_schema::source::{ - comment::*, - community::{Community, CommunityForm}, - person::*, - person_mention::*, - post::*, + use lemmy_db_schema::{ + source::{ + comment::*, + community::{Community, CommunityForm}, + person::*, + person_mention::*, + post::*, + }, + PrimaryLanguageTag, }; use serial_test::serial; @@ -115,7 +117,7 @@ mod tests { name: "A test post".into(), creator_id: inserted_person.id, community_id: inserted_community.id, - language: Some(LanguageTag::parse("en").unwrap().into()), + language: Some(PrimaryLanguageTag("en".to_string())), ..PostForm::default() }; @@ -125,7 +127,7 @@ mod tests { content: "A test comment".into(), creator_id: inserted_person.id, post_id: inserted_post.id, - language: Some(LanguageTag::parse("en").unwrap().into()), + language: Some(PrimaryLanguageTag("en".to_string())), ..CommentForm::default() }; diff --git a/crates/db_queries/src/source/post.rs b/crates/db_queries/src/source/post.rs index f52b8c7e8..435b725cb 100644 --- a/crates/db_queries/src/source/post.rs +++ b/crates/db_queries/src/source/post.rs @@ -260,10 +260,12 @@ impl Readable for PostRead { #[cfg(test)] mod tests { use crate::{establish_unpooled_connection, source::post::*}; - use language_tags::LanguageTag; - use lemmy_db_schema::source::{ - community::{Community, CommunityForm}, - person::*, + use lemmy_db_schema::{ + source::{ + community::{Community, CommunityForm}, + person::*, + }, + PrimaryLanguageTag, }; use serial_test::serial; @@ -291,7 +293,7 @@ mod tests { name: "A test post".into(), creator_id: inserted_person.id, community_id: inserted_community.id, - language: Some(LanguageTag::parse("en").unwrap().into()), + language: Some(PrimaryLanguageTag("en".to_string())), ..PostForm::default() }; @@ -317,7 +319,7 @@ mod tests { thumbnail_url: None, ap_id: inserted_post.ap_id.to_owned(), local: true, - language: LanguageTag::parse("en").unwrap().into(), + language: PrimaryLanguageTag("en".to_string()), }; // Post Like diff --git a/crates/db_queries/src/source/private_message.rs b/crates/db_queries/src/source/private_message.rs index 93073d32b..9e5129f90 100644 --- a/crates/db_queries/src/source/private_message.rs +++ b/crates/db_queries/src/source/private_message.rs @@ -140,8 +140,10 @@ impl PrivateMessage_ for PrivateMessage { #[cfg(test)] mod tests { use crate::{establish_unpooled_connection, source::private_message::PrivateMessage_, Crud}; - use language_tags::LanguageTag; - use lemmy_db_schema::source::{person::*, private_message::*}; + use lemmy_db_schema::{ + source::{person::*, private_message::*}, + PrimaryLanguageTag, + }; use serial_test::serial; #[test] @@ -167,7 +169,7 @@ mod tests { content: "A test private message".into(), creator_id: inserted_creator.id, recipient_id: inserted_recipient.id, - language: Some(LanguageTag::parse("en").unwrap().into()), + language: Some(PrimaryLanguageTag("en".to_string())), ..PrivateMessageForm::default() }; @@ -184,7 +186,7 @@ mod tests { published: inserted_private_message.published, ap_id: inserted_private_message.ap_id.to_owned(), local: true, - language: LanguageTag::parse("en").unwrap().into(), + language: PrimaryLanguageTag("en".to_string()), }; let read_private_message = PrivateMessage::read(&conn, inserted_private_message.id).unwrap(); diff --git a/crates/db_schema/src/lib.rs b/crates/db_schema/src/lib.rs index f353584bb..954169ab3 100644 --- a/crates/db_schema/src/lib.rs +++ b/crates/db_schema/src/lib.rs @@ -124,7 +124,7 @@ pub fn naive_now() -> NaiveDateTime { #[repr(transparent)] #[derive(Debug, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, DieselNewType)] -pub struct PrimaryLanguageTag(String); +pub struct PrimaryLanguageTag(pub String); impl TryFrom for PrimaryLanguageTag { type Error = ValidationError; diff --git a/crates/db_views/src/comment_view.rs b/crates/db_views/src/comment_view.rs index 946298482..61a697239 100644 --- a/crates/db_views/src/comment_view.rs +++ b/crates/db_views/src/comment_view.rs @@ -438,14 +438,16 @@ impl ViewToVec for CommentView { #[cfg(test)] mod tests { use crate::comment_view::*; - use language_tags::LanguageTag; use lemmy_db_queries::{ aggregates::comment_aggregates::CommentAggregates, establish_unpooled_connection, Crud, Likeable, }; - use lemmy_db_schema::source::{comment::*, community::*, person::*, post::*}; + use lemmy_db_schema::{ + source::{comment::*, community::*, person::*, post::*}, + PrimaryLanguageTag, + }; use serial_test::serial; #[test] @@ -472,7 +474,7 @@ mod tests { name: "A test post 2".into(), creator_id: inserted_person.id, community_id: inserted_community.id, - language: Some(LanguageTag::parse("en").unwrap().into()), + language: Some(PrimaryLanguageTag("en".to_string())), ..PostForm::default() }; @@ -482,7 +484,7 @@ mod tests { content: "A test comment 32".into(), creator_id: inserted_person.id, post_id: inserted_post.id, - language: Some(LanguageTag::parse("en").unwrap().into()), + language: Some(PrimaryLanguageTag("en".to_string())), ..CommentForm::default() }; @@ -517,7 +519,7 @@ mod tests { ap_id: inserted_comment.ap_id, updated: None, local: true, - language: LanguageTag::parse("en").unwrap().into(), + language: PrimaryLanguageTag("en".to_string()), }, creator: PersonSafe { id: inserted_person.id, @@ -558,7 +560,7 @@ mod tests { thumbnail_url: None, ap_id: inserted_post.ap_id.to_owned(), local: true, - language: LanguageTag::parse("en").unwrap().into(), + language: PrimaryLanguageTag("en".to_string()), }, community: CommunitySafe { id: inserted_community.id, diff --git a/crates/db_views/src/post_view.rs b/crates/db_views/src/post_view.rs index bb9683874..3591a277e 100644 --- a/crates/db_views/src/post_view.rs +++ b/crates/db_views/src/post_view.rs @@ -444,7 +444,6 @@ impl ViewToVec for PostView { #[cfg(test)] mod tests { use crate::post_view::{PostQueryBuilder, PostView}; - use language_tags::LanguageTag; use lemmy_db_queries::{ aggregates::post_aggregates::PostAggregates, establish_unpooled_connection, @@ -453,7 +452,10 @@ mod tests { ListingType, SortType, }; - use lemmy_db_schema::source::{community::*, person::*, post::*}; + use lemmy_db_schema::{ + source::{community::*, person::*, post::*}, + PrimaryLanguageTag, + }; use serial_test::serial; #[test] @@ -484,7 +486,7 @@ mod tests { name: post_name.to_owned(), creator_id: inserted_person.id, community_id: inserted_community.id, - language: Some(LanguageTag::parse("en").unwrap().into()), + language: Some(PrimaryLanguageTag("en".to_string())), ..PostForm::default() }; @@ -549,7 +551,7 @@ mod tests { thumbnail_url: None, ap_id: inserted_post.ap_id.to_owned(), local: true, - language: LanguageTag::parse("en").unwrap().into(), + language: PrimaryLanguageTag("en".to_string()), }, my_vote: None, creator: PersonSafe {