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