]> Untitled Git - lemmy.git/blob - crates/db_schema/src/impls/moderator.rs
Default imprementations for read and delete in Crud trait (#3707)
[lemmy.git] / crates / db_schema / src / impls / moderator.rs
1 use crate::{
2   source::moderator::{
3     AdminPurgeComment,
4     AdminPurgeCommentForm,
5     AdminPurgeCommunity,
6     AdminPurgeCommunityForm,
7     AdminPurgePerson,
8     AdminPurgePersonForm,
9     AdminPurgePost,
10     AdminPurgePostForm,
11     ModAdd,
12     ModAddCommunity,
13     ModAddCommunityForm,
14     ModAddForm,
15     ModBan,
16     ModBanForm,
17     ModBanFromCommunity,
18     ModBanFromCommunityForm,
19     ModFeaturePost,
20     ModFeaturePostForm,
21     ModHideCommunity,
22     ModHideCommunityForm,
23     ModLockPost,
24     ModLockPostForm,
25     ModRemoveComment,
26     ModRemoveCommentForm,
27     ModRemoveCommunity,
28     ModRemoveCommunityForm,
29     ModRemovePost,
30     ModRemovePostForm,
31     ModTransferCommunity,
32     ModTransferCommunityForm,
33   },
34   traits::Crud,
35   utils::{get_conn, DbPool},
36 };
37 use diesel::{dsl::insert_into, result::Error, QueryDsl};
38 use diesel_async::RunQueryDsl;
39
40 #[async_trait]
41 impl Crud for ModRemovePost {
42   type InsertForm = ModRemovePostForm;
43   type UpdateForm = ModRemovePostForm;
44   type IdType = i32;
45
46   async fn create(pool: &mut DbPool<'_>, form: &ModRemovePostForm) -> Result<Self, Error> {
47     use crate::schema::mod_remove_post::dsl::mod_remove_post;
48     let conn = &mut get_conn(pool).await?;
49     insert_into(mod_remove_post)
50       .values(form)
51       .get_result::<Self>(conn)
52       .await
53   }
54
55   async fn update(
56     pool: &mut DbPool<'_>,
57     from_id: i32,
58     form: &ModRemovePostForm,
59   ) -> Result<Self, Error> {
60     use crate::schema::mod_remove_post::dsl::mod_remove_post;
61     let conn = &mut get_conn(pool).await?;
62     diesel::update(mod_remove_post.find(from_id))
63       .set(form)
64       .get_result::<Self>(conn)
65       .await
66   }
67 }
68
69 #[async_trait]
70 impl Crud for ModLockPost {
71   type InsertForm = ModLockPostForm;
72   type UpdateForm = ModLockPostForm;
73   type IdType = i32;
74
75   async fn create(pool: &mut DbPool<'_>, form: &ModLockPostForm) -> Result<Self, Error> {
76     use crate::schema::mod_lock_post::dsl::mod_lock_post;
77     let conn = &mut get_conn(pool).await?;
78     insert_into(mod_lock_post)
79       .values(form)
80       .get_result::<Self>(conn)
81       .await
82   }
83
84   async fn update(
85     pool: &mut DbPool<'_>,
86     from_id: i32,
87     form: &ModLockPostForm,
88   ) -> Result<Self, Error> {
89     use crate::schema::mod_lock_post::dsl::mod_lock_post;
90     let conn = &mut get_conn(pool).await?;
91     diesel::update(mod_lock_post.find(from_id))
92       .set(form)
93       .get_result::<Self>(conn)
94       .await
95   }
96 }
97
98 #[async_trait]
99 impl Crud for ModFeaturePost {
100   type InsertForm = ModFeaturePostForm;
101   type UpdateForm = ModFeaturePostForm;
102   type IdType = i32;
103
104   async fn create(pool: &mut DbPool<'_>, form: &ModFeaturePostForm) -> Result<Self, Error> {
105     use crate::schema::mod_feature_post::dsl::mod_feature_post;
106     let conn = &mut get_conn(pool).await?;
107     insert_into(mod_feature_post)
108       .values(form)
109       .get_result::<Self>(conn)
110       .await
111   }
112
113   async fn update(
114     pool: &mut DbPool<'_>,
115     from_id: i32,
116     form: &ModFeaturePostForm,
117   ) -> Result<Self, Error> {
118     use crate::schema::mod_feature_post::dsl::mod_feature_post;
119     let conn = &mut get_conn(pool).await?;
120     diesel::update(mod_feature_post.find(from_id))
121       .set(form)
122       .get_result::<Self>(conn)
123       .await
124   }
125 }
126
127 #[async_trait]
128 impl Crud for ModRemoveComment {
129   type InsertForm = ModRemoveCommentForm;
130   type UpdateForm = ModRemoveCommentForm;
131   type IdType = i32;
132
133   async fn create(pool: &mut DbPool<'_>, form: &ModRemoveCommentForm) -> Result<Self, Error> {
134     use crate::schema::mod_remove_comment::dsl::mod_remove_comment;
135     let conn = &mut get_conn(pool).await?;
136     insert_into(mod_remove_comment)
137       .values(form)
138       .get_result::<Self>(conn)
139       .await
140   }
141
142   async fn update(
143     pool: &mut DbPool<'_>,
144     from_id: i32,
145     form: &ModRemoveCommentForm,
146   ) -> Result<Self, Error> {
147     use crate::schema::mod_remove_comment::dsl::mod_remove_comment;
148     let conn = &mut get_conn(pool).await?;
149     diesel::update(mod_remove_comment.find(from_id))
150       .set(form)
151       .get_result::<Self>(conn)
152       .await
153   }
154 }
155
156 #[async_trait]
157 impl Crud for ModRemoveCommunity {
158   type InsertForm = ModRemoveCommunityForm;
159   type UpdateForm = ModRemoveCommunityForm;
160   type IdType = i32;
161
162   async fn create(pool: &mut DbPool<'_>, form: &ModRemoveCommunityForm) -> Result<Self, Error> {
163     use crate::schema::mod_remove_community::dsl::mod_remove_community;
164     let conn = &mut get_conn(pool).await?;
165     insert_into(mod_remove_community)
166       .values(form)
167       .get_result::<Self>(conn)
168       .await
169   }
170
171   async fn update(
172     pool: &mut DbPool<'_>,
173     from_id: i32,
174     form: &ModRemoveCommunityForm,
175   ) -> Result<Self, Error> {
176     use crate::schema::mod_remove_community::dsl::mod_remove_community;
177     let conn = &mut get_conn(pool).await?;
178     diesel::update(mod_remove_community.find(from_id))
179       .set(form)
180       .get_result::<Self>(conn)
181       .await
182   }
183 }
184
185 #[async_trait]
186 impl Crud for ModBanFromCommunity {
187   type InsertForm = ModBanFromCommunityForm;
188   type UpdateForm = ModBanFromCommunityForm;
189   type IdType = i32;
190
191   async fn create(pool: &mut DbPool<'_>, form: &ModBanFromCommunityForm) -> Result<Self, Error> {
192     use crate::schema::mod_ban_from_community::dsl::mod_ban_from_community;
193     let conn = &mut get_conn(pool).await?;
194     insert_into(mod_ban_from_community)
195       .values(form)
196       .get_result::<Self>(conn)
197       .await
198   }
199
200   async fn update(
201     pool: &mut DbPool<'_>,
202     from_id: i32,
203     form: &ModBanFromCommunityForm,
204   ) -> Result<Self, Error> {
205     use crate::schema::mod_ban_from_community::dsl::mod_ban_from_community;
206     let conn = &mut get_conn(pool).await?;
207     diesel::update(mod_ban_from_community.find(from_id))
208       .set(form)
209       .get_result::<Self>(conn)
210       .await
211   }
212 }
213
214 #[async_trait]
215 impl Crud for ModBan {
216   type InsertForm = ModBanForm;
217   type UpdateForm = ModBanForm;
218   type IdType = i32;
219
220   async fn create(pool: &mut DbPool<'_>, form: &ModBanForm) -> Result<Self, Error> {
221     use crate::schema::mod_ban::dsl::mod_ban;
222     let conn = &mut get_conn(pool).await?;
223     insert_into(mod_ban)
224       .values(form)
225       .get_result::<Self>(conn)
226       .await
227   }
228
229   async fn update(pool: &mut DbPool<'_>, from_id: i32, form: &ModBanForm) -> Result<Self, Error> {
230     use crate::schema::mod_ban::dsl::mod_ban;
231     let conn = &mut get_conn(pool).await?;
232     diesel::update(mod_ban.find(from_id))
233       .set(form)
234       .get_result::<Self>(conn)
235       .await
236   }
237 }
238
239 #[async_trait]
240 impl Crud for ModHideCommunity {
241   type InsertForm = ModHideCommunityForm;
242   type UpdateForm = ModHideCommunityForm;
243   type IdType = i32;
244
245   async fn create(pool: &mut DbPool<'_>, form: &ModHideCommunityForm) -> Result<Self, Error> {
246     use crate::schema::mod_hide_community::dsl::mod_hide_community;
247     let conn = &mut get_conn(pool).await?;
248     insert_into(mod_hide_community)
249       .values(form)
250       .get_result::<Self>(conn)
251       .await
252   }
253
254   async fn update(
255     pool: &mut DbPool<'_>,
256     from_id: i32,
257     form: &ModHideCommunityForm,
258   ) -> Result<Self, Error> {
259     use crate::schema::mod_hide_community::dsl::mod_hide_community;
260     let conn = &mut get_conn(pool).await?;
261     diesel::update(mod_hide_community.find(from_id))
262       .set(form)
263       .get_result::<Self>(conn)
264       .await
265   }
266 }
267
268 #[async_trait]
269 impl Crud for ModAddCommunity {
270   type InsertForm = ModAddCommunityForm;
271   type UpdateForm = ModAddCommunityForm;
272   type IdType = i32;
273
274   async fn create(pool: &mut DbPool<'_>, form: &ModAddCommunityForm) -> Result<Self, Error> {
275     use crate::schema::mod_add_community::dsl::mod_add_community;
276     let conn = &mut get_conn(pool).await?;
277     insert_into(mod_add_community)
278       .values(form)
279       .get_result::<Self>(conn)
280       .await
281   }
282
283   async fn update(
284     pool: &mut DbPool<'_>,
285     from_id: i32,
286     form: &ModAddCommunityForm,
287   ) -> Result<Self, Error> {
288     use crate::schema::mod_add_community::dsl::mod_add_community;
289     let conn = &mut get_conn(pool).await?;
290     diesel::update(mod_add_community.find(from_id))
291       .set(form)
292       .get_result::<Self>(conn)
293       .await
294   }
295 }
296
297 #[async_trait]
298 impl Crud for ModTransferCommunity {
299   type InsertForm = ModTransferCommunityForm;
300   type UpdateForm = ModTransferCommunityForm;
301   type IdType = i32;
302
303   async fn create(pool: &mut DbPool<'_>, form: &ModTransferCommunityForm) -> Result<Self, Error> {
304     use crate::schema::mod_transfer_community::dsl::mod_transfer_community;
305     let conn = &mut get_conn(pool).await?;
306     insert_into(mod_transfer_community)
307       .values(form)
308       .get_result::<Self>(conn)
309       .await
310   }
311
312   async fn update(
313     pool: &mut DbPool<'_>,
314     from_id: i32,
315     form: &ModTransferCommunityForm,
316   ) -> Result<Self, Error> {
317     use crate::schema::mod_transfer_community::dsl::mod_transfer_community;
318     let conn = &mut get_conn(pool).await?;
319     diesel::update(mod_transfer_community.find(from_id))
320       .set(form)
321       .get_result::<Self>(conn)
322       .await
323   }
324 }
325
326 #[async_trait]
327 impl Crud for ModAdd {
328   type InsertForm = ModAddForm;
329   type UpdateForm = ModAddForm;
330   type IdType = i32;
331
332   async fn create(pool: &mut DbPool<'_>, form: &ModAddForm) -> Result<Self, Error> {
333     use crate::schema::mod_add::dsl::mod_add;
334     let conn = &mut get_conn(pool).await?;
335     insert_into(mod_add)
336       .values(form)
337       .get_result::<Self>(conn)
338       .await
339   }
340
341   async fn update(pool: &mut DbPool<'_>, from_id: i32, form: &ModAddForm) -> Result<Self, Error> {
342     use crate::schema::mod_add::dsl::mod_add;
343     let conn = &mut get_conn(pool).await?;
344     diesel::update(mod_add.find(from_id))
345       .set(form)
346       .get_result::<Self>(conn)
347       .await
348   }
349 }
350
351 #[async_trait]
352 impl Crud for AdminPurgePerson {
353   type InsertForm = AdminPurgePersonForm;
354   type UpdateForm = AdminPurgePersonForm;
355   type IdType = i32;
356
357   async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result<Self, Error> {
358     use crate::schema::admin_purge_person::dsl::admin_purge_person;
359     let conn = &mut get_conn(pool).await?;
360     insert_into(admin_purge_person)
361       .values(form)
362       .get_result::<Self>(conn)
363       .await
364   }
365
366   async fn update(
367     pool: &mut DbPool<'_>,
368     from_id: i32,
369     form: &Self::InsertForm,
370   ) -> Result<Self, Error> {
371     use crate::schema::admin_purge_person::dsl::admin_purge_person;
372     let conn = &mut get_conn(pool).await?;
373     diesel::update(admin_purge_person.find(from_id))
374       .set(form)
375       .get_result::<Self>(conn)
376       .await
377   }
378 }
379
380 #[async_trait]
381 impl Crud for AdminPurgeCommunity {
382   type InsertForm = AdminPurgeCommunityForm;
383   type UpdateForm = AdminPurgeCommunityForm;
384   type IdType = i32;
385
386   async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result<Self, Error> {
387     use crate::schema::admin_purge_community::dsl::admin_purge_community;
388     let conn = &mut get_conn(pool).await?;
389     insert_into(admin_purge_community)
390       .values(form)
391       .get_result::<Self>(conn)
392       .await
393   }
394
395   async fn update(
396     pool: &mut DbPool<'_>,
397     from_id: i32,
398     form: &Self::InsertForm,
399   ) -> Result<Self, Error> {
400     use crate::schema::admin_purge_community::dsl::admin_purge_community;
401     let conn = &mut get_conn(pool).await?;
402     diesel::update(admin_purge_community.find(from_id))
403       .set(form)
404       .get_result::<Self>(conn)
405       .await
406   }
407 }
408
409 #[async_trait]
410 impl Crud for AdminPurgePost {
411   type InsertForm = AdminPurgePostForm;
412   type UpdateForm = AdminPurgePostForm;
413   type IdType = i32;
414
415   async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result<Self, Error> {
416     use crate::schema::admin_purge_post::dsl::admin_purge_post;
417     let conn = &mut get_conn(pool).await?;
418     insert_into(admin_purge_post)
419       .values(form)
420       .get_result::<Self>(conn)
421       .await
422   }
423
424   async fn update(
425     pool: &mut DbPool<'_>,
426     from_id: i32,
427     form: &Self::InsertForm,
428   ) -> Result<Self, Error> {
429     use crate::schema::admin_purge_post::dsl::admin_purge_post;
430     let conn = &mut get_conn(pool).await?;
431     diesel::update(admin_purge_post.find(from_id))
432       .set(form)
433       .get_result::<Self>(conn)
434       .await
435   }
436 }
437
438 #[async_trait]
439 impl Crud for AdminPurgeComment {
440   type InsertForm = AdminPurgeCommentForm;
441   type UpdateForm = AdminPurgeCommentForm;
442   type IdType = i32;
443
444   async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result<Self, Error> {
445     use crate::schema::admin_purge_comment::dsl::admin_purge_comment;
446     let conn = &mut get_conn(pool).await?;
447     insert_into(admin_purge_comment)
448       .values(form)
449       .get_result::<Self>(conn)
450       .await
451   }
452
453   async fn update(
454     pool: &mut DbPool<'_>,
455     from_id: i32,
456     form: &Self::InsertForm,
457   ) -> Result<Self, Error> {
458     use crate::schema::admin_purge_comment::dsl::admin_purge_comment;
459     let conn = &mut get_conn(pool).await?;
460     diesel::update(admin_purge_comment.find(from_id))
461       .set(form)
462       .get_result::<Self>(conn)
463       .await
464   }
465 }
466
467 #[cfg(test)]
468 mod tests {
469   #![allow(clippy::unwrap_used)]
470   #![allow(clippy::indexing_slicing)]
471
472   use crate::{
473     source::{
474       comment::{Comment, CommentInsertForm},
475       community::{Community, CommunityInsertForm},
476       instance::Instance,
477       moderator::{
478         ModAdd,
479         ModAddCommunity,
480         ModAddCommunityForm,
481         ModAddForm,
482         ModBan,
483         ModBanForm,
484         ModBanFromCommunity,
485         ModBanFromCommunityForm,
486         ModFeaturePost,
487         ModFeaturePostForm,
488         ModLockPost,
489         ModLockPostForm,
490         ModRemoveComment,
491         ModRemoveCommentForm,
492         ModRemoveCommunity,
493         ModRemoveCommunityForm,
494         ModRemovePost,
495         ModRemovePostForm,
496       },
497       person::{Person, PersonInsertForm},
498       post::{Post, PostInsertForm},
499     },
500     traits::Crud,
501     utils::build_db_pool_for_tests,
502   };
503   use serial_test::serial;
504
505   #[tokio::test]
506   #[serial]
507   async fn test_crud() {
508     let pool = &build_db_pool_for_tests().await;
509     let pool = &mut pool.into();
510
511     let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
512       .await
513       .unwrap();
514
515     let new_mod = PersonInsertForm::builder()
516       .name("the mod".into())
517       .public_key("pubkey".to_string())
518       .instance_id(inserted_instance.id)
519       .build();
520
521     let inserted_mod = Person::create(pool, &new_mod).await.unwrap();
522
523     let new_person = PersonInsertForm::builder()
524       .name("jim2".into())
525       .public_key("pubkey".to_string())
526       .instance_id(inserted_instance.id)
527       .build();
528
529     let inserted_person = Person::create(pool, &new_person).await.unwrap();
530
531     let new_community = CommunityInsertForm::builder()
532       .name("mod_community".to_string())
533       .title("nada".to_owned())
534       .public_key("pubkey".to_string())
535       .instance_id(inserted_instance.id)
536       .build();
537
538     let inserted_community = Community::create(pool, &new_community).await.unwrap();
539
540     let new_post = PostInsertForm::builder()
541       .name("A test post thweep".into())
542       .creator_id(inserted_person.id)
543       .community_id(inserted_community.id)
544       .build();
545
546     let inserted_post = Post::create(pool, &new_post).await.unwrap();
547
548     let comment_form = CommentInsertForm::builder()
549       .content("A test comment".into())
550       .creator_id(inserted_person.id)
551       .post_id(inserted_post.id)
552       .build();
553
554     let inserted_comment = Comment::create(pool, &comment_form, None).await.unwrap();
555
556     // Now the actual tests
557
558     // remove post
559     let mod_remove_post_form = ModRemovePostForm {
560       mod_person_id: inserted_mod.id,
561       post_id: inserted_post.id,
562       reason: None,
563       removed: None,
564     };
565     let inserted_mod_remove_post = ModRemovePost::create(pool, &mod_remove_post_form)
566       .await
567       .unwrap();
568     let read_mod_remove_post = ModRemovePost::read(pool, inserted_mod_remove_post.id)
569       .await
570       .unwrap();
571     let expected_mod_remove_post = ModRemovePost {
572       id: inserted_mod_remove_post.id,
573       post_id: inserted_post.id,
574       mod_person_id: inserted_mod.id,
575       reason: None,
576       removed: true,
577       when_: inserted_mod_remove_post.when_,
578     };
579
580     // lock post
581
582     let mod_lock_post_form = ModLockPostForm {
583       mod_person_id: inserted_mod.id,
584       post_id: inserted_post.id,
585       locked: None,
586     };
587     let inserted_mod_lock_post = ModLockPost::create(pool, &mod_lock_post_form)
588       .await
589       .unwrap();
590     let read_mod_lock_post = ModLockPost::read(pool, inserted_mod_lock_post.id)
591       .await
592       .unwrap();
593     let expected_mod_lock_post = ModLockPost {
594       id: inserted_mod_lock_post.id,
595       post_id: inserted_post.id,
596       mod_person_id: inserted_mod.id,
597       locked: true,
598       when_: inserted_mod_lock_post.when_,
599     };
600
601     // feature post
602
603     let mod_feature_post_form = ModFeaturePostForm {
604       mod_person_id: inserted_mod.id,
605       post_id: inserted_post.id,
606       featured: false,
607       is_featured_community: true,
608     };
609     let inserted_mod_feature_post = ModFeaturePost::create(pool, &mod_feature_post_form)
610       .await
611       .unwrap();
612     let read_mod_feature_post = ModFeaturePost::read(pool, inserted_mod_feature_post.id)
613       .await
614       .unwrap();
615     let expected_mod_feature_post = ModFeaturePost {
616       id: inserted_mod_feature_post.id,
617       post_id: inserted_post.id,
618       mod_person_id: inserted_mod.id,
619       featured: false,
620       is_featured_community: true,
621       when_: inserted_mod_feature_post.when_,
622     };
623
624     // comment
625
626     let mod_remove_comment_form = ModRemoveCommentForm {
627       mod_person_id: inserted_mod.id,
628       comment_id: inserted_comment.id,
629       reason: None,
630       removed: None,
631     };
632     let inserted_mod_remove_comment = ModRemoveComment::create(pool, &mod_remove_comment_form)
633       .await
634       .unwrap();
635     let read_mod_remove_comment = ModRemoveComment::read(pool, inserted_mod_remove_comment.id)
636       .await
637       .unwrap();
638     let expected_mod_remove_comment = ModRemoveComment {
639       id: inserted_mod_remove_comment.id,
640       comment_id: inserted_comment.id,
641       mod_person_id: inserted_mod.id,
642       reason: None,
643       removed: true,
644       when_: inserted_mod_remove_comment.when_,
645     };
646
647     // community
648
649     let mod_remove_community_form = ModRemoveCommunityForm {
650       mod_person_id: inserted_mod.id,
651       community_id: inserted_community.id,
652       reason: None,
653       removed: None,
654       expires: None,
655     };
656     let inserted_mod_remove_community =
657       ModRemoveCommunity::create(pool, &mod_remove_community_form)
658         .await
659         .unwrap();
660     let read_mod_remove_community =
661       ModRemoveCommunity::read(pool, inserted_mod_remove_community.id)
662         .await
663         .unwrap();
664     let expected_mod_remove_community = ModRemoveCommunity {
665       id: inserted_mod_remove_community.id,
666       community_id: inserted_community.id,
667       mod_person_id: inserted_mod.id,
668       reason: None,
669       removed: true,
670       expires: None,
671       when_: inserted_mod_remove_community.when_,
672     };
673
674     // ban from community
675
676     let mod_ban_from_community_form = ModBanFromCommunityForm {
677       mod_person_id: inserted_mod.id,
678       other_person_id: inserted_person.id,
679       community_id: inserted_community.id,
680       reason: None,
681       banned: None,
682       expires: None,
683     };
684     let inserted_mod_ban_from_community =
685       ModBanFromCommunity::create(pool, &mod_ban_from_community_form)
686         .await
687         .unwrap();
688     let read_mod_ban_from_community =
689       ModBanFromCommunity::read(pool, inserted_mod_ban_from_community.id)
690         .await
691         .unwrap();
692     let expected_mod_ban_from_community = ModBanFromCommunity {
693       id: inserted_mod_ban_from_community.id,
694       community_id: inserted_community.id,
695       mod_person_id: inserted_mod.id,
696       other_person_id: inserted_person.id,
697       reason: None,
698       banned: true,
699       expires: None,
700       when_: inserted_mod_ban_from_community.when_,
701     };
702
703     // ban
704
705     let mod_ban_form = ModBanForm {
706       mod_person_id: inserted_mod.id,
707       other_person_id: inserted_person.id,
708       reason: None,
709       banned: None,
710       expires: None,
711     };
712     let inserted_mod_ban = ModBan::create(pool, &mod_ban_form).await.unwrap();
713     let read_mod_ban = ModBan::read(pool, inserted_mod_ban.id).await.unwrap();
714     let expected_mod_ban = ModBan {
715       id: inserted_mod_ban.id,
716       mod_person_id: inserted_mod.id,
717       other_person_id: inserted_person.id,
718       reason: None,
719       banned: true,
720       expires: None,
721       when_: inserted_mod_ban.when_,
722     };
723
724     // mod add community
725
726     let mod_add_community_form = ModAddCommunityForm {
727       mod_person_id: inserted_mod.id,
728       other_person_id: inserted_person.id,
729       community_id: inserted_community.id,
730       removed: None,
731     };
732     let inserted_mod_add_community = ModAddCommunity::create(pool, &mod_add_community_form)
733       .await
734       .unwrap();
735     let read_mod_add_community = ModAddCommunity::read(pool, inserted_mod_add_community.id)
736       .await
737       .unwrap();
738     let expected_mod_add_community = ModAddCommunity {
739       id: inserted_mod_add_community.id,
740       community_id: inserted_community.id,
741       mod_person_id: inserted_mod.id,
742       other_person_id: inserted_person.id,
743       removed: false,
744       when_: inserted_mod_add_community.when_,
745     };
746
747     // mod add
748
749     let mod_add_form = ModAddForm {
750       mod_person_id: inserted_mod.id,
751       other_person_id: inserted_person.id,
752       removed: None,
753     };
754     let inserted_mod_add = ModAdd::create(pool, &mod_add_form).await.unwrap();
755     let read_mod_add = ModAdd::read(pool, inserted_mod_add.id).await.unwrap();
756     let expected_mod_add = ModAdd {
757       id: inserted_mod_add.id,
758       mod_person_id: inserted_mod.id,
759       other_person_id: inserted_person.id,
760       removed: false,
761       when_: inserted_mod_add.when_,
762     };
763
764     Comment::delete(pool, inserted_comment.id).await.unwrap();
765     Post::delete(pool, inserted_post.id).await.unwrap();
766     Community::delete(pool, inserted_community.id)
767       .await
768       .unwrap();
769     Person::delete(pool, inserted_person.id).await.unwrap();
770     Person::delete(pool, inserted_mod.id).await.unwrap();
771     Instance::delete(pool, inserted_instance.id).await.unwrap();
772
773     assert_eq!(expected_mod_remove_post, read_mod_remove_post);
774     assert_eq!(expected_mod_lock_post, read_mod_lock_post);
775     assert_eq!(expected_mod_feature_post, read_mod_feature_post);
776     assert_eq!(expected_mod_remove_comment, read_mod_remove_comment);
777     assert_eq!(expected_mod_remove_community, read_mod_remove_community);
778     assert_eq!(expected_mod_ban_from_community, read_mod_ban_from_community);
779     assert_eq!(expected_mod_ban, read_mod_ban);
780     assert_eq!(expected_mod_add_community, read_mod_add_community);
781     assert_eq!(expected_mod_add, read_mod_add);
782   }
783 }