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