]> Untitled Git - lemmy.git/blob - crates/db_schema/src/impls/moderator.rs
Add support for Featured Posts (#2585)
[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::create(pool, "my_domain.tld").await.unwrap();
553
554     let new_mod = PersonInsertForm::builder()
555       .name("the mod".into())
556       .public_key("pubkey".to_string())
557       .instance_id(inserted_instance.id)
558       .build();
559
560     let inserted_mod = Person::create(pool, &new_mod).await.unwrap();
561
562     let new_person = PersonInsertForm::builder()
563       .name("jim2".into())
564       .public_key("pubkey".to_string())
565       .instance_id(inserted_instance.id)
566       .build();
567
568     let inserted_person = Person::create(pool, &new_person).await.unwrap();
569
570     let new_community = CommunityInsertForm::builder()
571       .name("mod_community".to_string())
572       .title("nada".to_owned())
573       .public_key("pubkey".to_string())
574       .instance_id(inserted_instance.id)
575       .build();
576
577     let inserted_community = Community::create(pool, &new_community).await.unwrap();
578
579     let new_post = PostInsertForm::builder()
580       .name("A test post thweep".into())
581       .creator_id(inserted_person.id)
582       .community_id(inserted_community.id)
583       .build();
584
585     let inserted_post = Post::create(pool, &new_post).await.unwrap();
586
587     let comment_form = CommentInsertForm::builder()
588       .content("A test comment".into())
589       .creator_id(inserted_person.id)
590       .post_id(inserted_post.id)
591       .build();
592
593     let inserted_comment = Comment::create(pool, &comment_form, None).await.unwrap();
594
595     // Now the actual tests
596
597     // remove post
598     let mod_remove_post_form = ModRemovePostForm {
599       mod_person_id: inserted_mod.id,
600       post_id: inserted_post.id,
601       reason: None,
602       removed: None,
603     };
604     let inserted_mod_remove_post = ModRemovePost::create(pool, &mod_remove_post_form)
605       .await
606       .unwrap();
607     let read_mod_remove_post = ModRemovePost::read(pool, inserted_mod_remove_post.id)
608       .await
609       .unwrap();
610     let expected_mod_remove_post = ModRemovePost {
611       id: inserted_mod_remove_post.id,
612       post_id: inserted_post.id,
613       mod_person_id: inserted_mod.id,
614       reason: None,
615       removed: Some(true),
616       when_: inserted_mod_remove_post.when_,
617     };
618
619     // lock post
620
621     let mod_lock_post_form = ModLockPostForm {
622       mod_person_id: inserted_mod.id,
623       post_id: inserted_post.id,
624       locked: None,
625     };
626     let inserted_mod_lock_post = ModLockPost::create(pool, &mod_lock_post_form)
627       .await
628       .unwrap();
629     let read_mod_lock_post = ModLockPost::read(pool, inserted_mod_lock_post.id)
630       .await
631       .unwrap();
632     let expected_mod_lock_post = ModLockPost {
633       id: inserted_mod_lock_post.id,
634       post_id: inserted_post.id,
635       mod_person_id: inserted_mod.id,
636       locked: Some(true),
637       when_: inserted_mod_lock_post.when_,
638     };
639
640     // feature post
641
642     let mod_feature_post_form = ModFeaturePostForm {
643       mod_person_id: inserted_mod.id,
644       post_id: inserted_post.id,
645       featured: false,
646       is_featured_community: true,
647     };
648     let inserted_mod_feature_post = ModFeaturePost::create(pool, &mod_feature_post_form)
649       .await
650       .unwrap();
651     let read_mod_feature_post = ModFeaturePost::read(pool, inserted_mod_feature_post.id)
652       .await
653       .unwrap();
654     let expected_mod_feature_post = ModFeaturePost {
655       id: inserted_mod_feature_post.id,
656       post_id: inserted_post.id,
657       mod_person_id: inserted_mod.id,
658       featured: false,
659       is_featured_community: true,
660       when_: inserted_mod_feature_post.when_,
661     };
662
663     // comment
664
665     let mod_remove_comment_form = ModRemoveCommentForm {
666       mod_person_id: inserted_mod.id,
667       comment_id: inserted_comment.id,
668       reason: None,
669       removed: None,
670     };
671     let inserted_mod_remove_comment = ModRemoveComment::create(pool, &mod_remove_comment_form)
672       .await
673       .unwrap();
674     let read_mod_remove_comment = ModRemoveComment::read(pool, inserted_mod_remove_comment.id)
675       .await
676       .unwrap();
677     let expected_mod_remove_comment = ModRemoveComment {
678       id: inserted_mod_remove_comment.id,
679       comment_id: inserted_comment.id,
680       mod_person_id: inserted_mod.id,
681       reason: None,
682       removed: Some(true),
683       when_: inserted_mod_remove_comment.when_,
684     };
685
686     // community
687
688     let mod_remove_community_form = ModRemoveCommunityForm {
689       mod_person_id: inserted_mod.id,
690       community_id: inserted_community.id,
691       reason: None,
692       removed: None,
693       expires: None,
694     };
695     let inserted_mod_remove_community =
696       ModRemoveCommunity::create(pool, &mod_remove_community_form)
697         .await
698         .unwrap();
699     let read_mod_remove_community =
700       ModRemoveCommunity::read(pool, inserted_mod_remove_community.id)
701         .await
702         .unwrap();
703     let expected_mod_remove_community = ModRemoveCommunity {
704       id: inserted_mod_remove_community.id,
705       community_id: inserted_community.id,
706       mod_person_id: inserted_mod.id,
707       reason: None,
708       removed: Some(true),
709       expires: None,
710       when_: inserted_mod_remove_community.when_,
711     };
712
713     // ban from community
714
715     let mod_ban_from_community_form = ModBanFromCommunityForm {
716       mod_person_id: inserted_mod.id,
717       other_person_id: inserted_person.id,
718       community_id: inserted_community.id,
719       reason: None,
720       banned: None,
721       expires: None,
722     };
723     let inserted_mod_ban_from_community =
724       ModBanFromCommunity::create(pool, &mod_ban_from_community_form)
725         .await
726         .unwrap();
727     let read_mod_ban_from_community =
728       ModBanFromCommunity::read(pool, inserted_mod_ban_from_community.id)
729         .await
730         .unwrap();
731     let expected_mod_ban_from_community = ModBanFromCommunity {
732       id: inserted_mod_ban_from_community.id,
733       community_id: inserted_community.id,
734       mod_person_id: inserted_mod.id,
735       other_person_id: inserted_person.id,
736       reason: None,
737       banned: Some(true),
738       expires: None,
739       when_: inserted_mod_ban_from_community.when_,
740     };
741
742     // ban
743
744     let mod_ban_form = ModBanForm {
745       mod_person_id: inserted_mod.id,
746       other_person_id: inserted_person.id,
747       reason: None,
748       banned: None,
749       expires: None,
750     };
751     let inserted_mod_ban = ModBan::create(pool, &mod_ban_form).await.unwrap();
752     let read_mod_ban = ModBan::read(pool, inserted_mod_ban.id).await.unwrap();
753     let expected_mod_ban = ModBan {
754       id: inserted_mod_ban.id,
755       mod_person_id: inserted_mod.id,
756       other_person_id: inserted_person.id,
757       reason: None,
758       banned: Some(true),
759       expires: None,
760       when_: inserted_mod_ban.when_,
761     };
762
763     // mod add community
764
765     let mod_add_community_form = ModAddCommunityForm {
766       mod_person_id: inserted_mod.id,
767       other_person_id: inserted_person.id,
768       community_id: inserted_community.id,
769       removed: None,
770     };
771     let inserted_mod_add_community = ModAddCommunity::create(pool, &mod_add_community_form)
772       .await
773       .unwrap();
774     let read_mod_add_community = ModAddCommunity::read(pool, inserted_mod_add_community.id)
775       .await
776       .unwrap();
777     let expected_mod_add_community = ModAddCommunity {
778       id: inserted_mod_add_community.id,
779       community_id: inserted_community.id,
780       mod_person_id: inserted_mod.id,
781       other_person_id: inserted_person.id,
782       removed: Some(false),
783       when_: inserted_mod_add_community.when_,
784     };
785
786     // mod add
787
788     let mod_add_form = ModAddForm {
789       mod_person_id: inserted_mod.id,
790       other_person_id: inserted_person.id,
791       removed: None,
792     };
793     let inserted_mod_add = ModAdd::create(pool, &mod_add_form).await.unwrap();
794     let read_mod_add = ModAdd::read(pool, inserted_mod_add.id).await.unwrap();
795     let expected_mod_add = ModAdd {
796       id: inserted_mod_add.id,
797       mod_person_id: inserted_mod.id,
798       other_person_id: inserted_person.id,
799       removed: Some(false),
800       when_: inserted_mod_add.when_,
801     };
802
803     Comment::delete(pool, inserted_comment.id).await.unwrap();
804     Post::delete(pool, inserted_post.id).await.unwrap();
805     Community::delete(pool, inserted_community.id)
806       .await
807       .unwrap();
808     Person::delete(pool, inserted_person.id).await.unwrap();
809     Person::delete(pool, inserted_mod.id).await.unwrap();
810     Instance::delete(pool, inserted_instance.id).await.unwrap();
811
812     assert_eq!(expected_mod_remove_post, read_mod_remove_post);
813     assert_eq!(expected_mod_lock_post, read_mod_lock_post);
814     assert_eq!(expected_mod_feature_post, read_mod_feature_post);
815     assert_eq!(expected_mod_remove_comment, read_mod_remove_comment);
816     assert_eq!(expected_mod_remove_community, read_mod_remove_community);
817     assert_eq!(expected_mod_ban_from_community, read_mod_ban_from_community);
818     assert_eq!(expected_mod_ban, read_mod_ban);
819     assert_eq!(expected_mod_add_community, read_mod_add_community);
820     assert_eq!(expected_mod_add, read_mod_add);
821   }
822 }