+ Ok(ApubCommunityModerators(Vec::new()))
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ #![allow(clippy::unwrap_used)]
+ #![allow(clippy::indexing_slicing)]
+
+ use super::*;
+ use crate::{
+ objects::{
+ community::tests::parse_lemmy_community,
+ person::tests::parse_lemmy_person,
+ tests::init_context,
+ },
+ protocol::tests::file_to_json_object,
+ };
+ use lemmy_db_schema::{
+ source::{
+ community::Community,
+ instance::Instance,
+ person::{Person, PersonInsertForm},
+ site::Site,
+ },
+ traits::Crud,
+ };
+ use serial_test::serial;
+
+ #[tokio::test]
+ #[serial]
+ async fn test_parse_lemmy_community_moderators() {
+ let context = init_context().await;
+ let (new_mod, site) = parse_lemmy_person(&context).await;
+ let community = parse_lemmy_community(&context).await;
+ let community_id = community.id;
+
+ let inserted_instance =
+ Instance::read_or_create(&mut context.pool(), "my_domain.tld".to_string())
+ .await
+ .unwrap();
+
+ let old_mod = PersonInsertForm::builder()
+ .name("holly".into())
+ .public_key("pubkey".to_string())
+ .instance_id(inserted_instance.id)
+ .build();
+
+ let old_mod = Person::create(&mut context.pool(), &old_mod).await.unwrap();
+ let community_moderator_form = CommunityModeratorForm {
+ community_id: community.id,
+ person_id: old_mod.id,
+ };
+
+ CommunityModerator::join(&mut context.pool(), &community_moderator_form)
+ .await
+ .unwrap();
+
+ assert_eq!(site.actor_id.to_string(), "https://enterprise.lemmy.ml/");
+
+ let json: GroupModerators =
+ file_to_json_object("assets/lemmy/collections/group_moderators.json").unwrap();
+ let url = Url::parse("https://enterprise.lemmy.ml/c/tenforward").unwrap();
+ ApubCommunityModerators::verify(&json, &url, &context)
+ .await
+ .unwrap();
+ ApubCommunityModerators::from_json(json, &community, &context)
+ .await
+ .unwrap();
+ assert_eq!(context.request_count(), 0);
+
+ let current_moderators =
+ CommunityModeratorView::for_community(&mut context.pool(), community_id)
+ .await
+ .unwrap();
+
+ assert_eq!(current_moderators.len(), 1);
+ assert_eq!(current_moderators[0].moderator.id, new_mod.id);
+
+ Person::delete(&mut context.pool(), old_mod.id)
+ .await
+ .unwrap();
+ Person::delete(&mut context.pool(), new_mod.id)
+ .await
+ .unwrap();
+ Community::delete(&mut context.pool(), community.id)
+ .await
+ .unwrap();
+ Site::delete(&mut context.pool(), site.id).await.unwrap();
+ Instance::delete(&mut context.pool(), inserted_instance.id)
+ .await
+ .unwrap();