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