]> Untitled Git - lemmy.git/blob - crates/db_schema/src/impls/moderator.rs
Remove federation backwards compatibility with 0.16.x (#2183)
[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     ModHideCommunity,
20     ModHideCommunityForm,
21     ModLockPost,
22     ModLockPostForm,
23     ModRemoveComment,
24     ModRemoveCommentForm,
25     ModRemoveCommunity,
26     ModRemoveCommunityForm,
27     ModRemovePost,
28     ModRemovePostForm,
29     ModStickyPost,
30     ModStickyPostForm,
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 ModStickyPost {
102   type InsertForm = ModStickyPostForm;
103   type UpdateForm = ModStickyPostForm;
104   type IdType = i32;
105   async fn read(pool: &DbPool, from_id: i32) -> Result<Self, Error> {
106     use crate::schema::mod_sticky_post::dsl::mod_sticky_post;
107     let conn = &mut get_conn(pool).await?;
108     mod_sticky_post.find(from_id).first::<Self>(conn).await
109   }
110
111   async fn create(pool: &DbPool, form: &ModStickyPostForm) -> Result<Self, Error> {
112     use crate::schema::mod_sticky_post::dsl::mod_sticky_post;
113     let conn = &mut get_conn(pool).await?;
114     insert_into(mod_sticky_post)
115       .values(form)
116       .get_result::<Self>(conn)
117       .await
118   }
119
120   async fn update(pool: &DbPool, from_id: i32, form: &ModStickyPostForm) -> Result<Self, Error> {
121     use crate::schema::mod_sticky_post::dsl::mod_sticky_post;
122     let conn = &mut get_conn(pool).await?;
123     diesel::update(mod_sticky_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         ModLockPost,
529         ModLockPostForm,
530         ModRemoveComment,
531         ModRemoveCommentForm,
532         ModRemoveCommunity,
533         ModRemoveCommunityForm,
534         ModRemovePost,
535         ModRemovePostForm,
536         ModStickyPost,
537         ModStickyPostForm,
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     // sticky post
641
642     let mod_sticky_post_form = ModStickyPostForm {
643       mod_person_id: inserted_mod.id,
644       post_id: inserted_post.id,
645       stickied: None,
646     };
647     let inserted_mod_sticky_post = ModStickyPost::create(pool, &mod_sticky_post_form)
648       .await
649       .unwrap();
650     let read_mod_sticky_post = ModStickyPost::read(pool, inserted_mod_sticky_post.id)
651       .await
652       .unwrap();
653     let expected_mod_sticky_post = ModStickyPost {
654       id: inserted_mod_sticky_post.id,
655       post_id: inserted_post.id,
656       mod_person_id: inserted_mod.id,
657       stickied: Some(true),
658       when_: inserted_mod_sticky_post.when_,
659     };
660
661     // comment
662
663     let mod_remove_comment_form = ModRemoveCommentForm {
664       mod_person_id: inserted_mod.id,
665       comment_id: inserted_comment.id,
666       reason: None,
667       removed: None,
668     };
669     let inserted_mod_remove_comment = ModRemoveComment::create(pool, &mod_remove_comment_form)
670       .await
671       .unwrap();
672     let read_mod_remove_comment = ModRemoveComment::read(pool, inserted_mod_remove_comment.id)
673       .await
674       .unwrap();
675     let expected_mod_remove_comment = ModRemoveComment {
676       id: inserted_mod_remove_comment.id,
677       comment_id: inserted_comment.id,
678       mod_person_id: inserted_mod.id,
679       reason: None,
680       removed: Some(true),
681       when_: inserted_mod_remove_comment.when_,
682     };
683
684     // community
685
686     let mod_remove_community_form = ModRemoveCommunityForm {
687       mod_person_id: inserted_mod.id,
688       community_id: inserted_community.id,
689       reason: None,
690       removed: None,
691       expires: None,
692     };
693     let inserted_mod_remove_community =
694       ModRemoveCommunity::create(pool, &mod_remove_community_form)
695         .await
696         .unwrap();
697     let read_mod_remove_community =
698       ModRemoveCommunity::read(pool, inserted_mod_remove_community.id)
699         .await
700         .unwrap();
701     let expected_mod_remove_community = ModRemoveCommunity {
702       id: inserted_mod_remove_community.id,
703       community_id: inserted_community.id,
704       mod_person_id: inserted_mod.id,
705       reason: None,
706       removed: Some(true),
707       expires: None,
708       when_: inserted_mod_remove_community.when_,
709     };
710
711     // ban from community
712
713     let mod_ban_from_community_form = ModBanFromCommunityForm {
714       mod_person_id: inserted_mod.id,
715       other_person_id: inserted_person.id,
716       community_id: inserted_community.id,
717       reason: None,
718       banned: None,
719       expires: None,
720     };
721     let inserted_mod_ban_from_community =
722       ModBanFromCommunity::create(pool, &mod_ban_from_community_form)
723         .await
724         .unwrap();
725     let read_mod_ban_from_community =
726       ModBanFromCommunity::read(pool, inserted_mod_ban_from_community.id)
727         .await
728         .unwrap();
729     let expected_mod_ban_from_community = ModBanFromCommunity {
730       id: inserted_mod_ban_from_community.id,
731       community_id: inserted_community.id,
732       mod_person_id: inserted_mod.id,
733       other_person_id: inserted_person.id,
734       reason: None,
735       banned: Some(true),
736       expires: None,
737       when_: inserted_mod_ban_from_community.when_,
738     };
739
740     // ban
741
742     let mod_ban_form = ModBanForm {
743       mod_person_id: inserted_mod.id,
744       other_person_id: inserted_person.id,
745       reason: None,
746       banned: None,
747       expires: None,
748     };
749     let inserted_mod_ban = ModBan::create(pool, &mod_ban_form).await.unwrap();
750     let read_mod_ban = ModBan::read(pool, inserted_mod_ban.id).await.unwrap();
751     let expected_mod_ban = ModBan {
752       id: inserted_mod_ban.id,
753       mod_person_id: inserted_mod.id,
754       other_person_id: inserted_person.id,
755       reason: None,
756       banned: Some(true),
757       expires: None,
758       when_: inserted_mod_ban.when_,
759     };
760
761     // mod add community
762
763     let mod_add_community_form = ModAddCommunityForm {
764       mod_person_id: inserted_mod.id,
765       other_person_id: inserted_person.id,
766       community_id: inserted_community.id,
767       removed: None,
768     };
769     let inserted_mod_add_community = ModAddCommunity::create(pool, &mod_add_community_form)
770       .await
771       .unwrap();
772     let read_mod_add_community = ModAddCommunity::read(pool, inserted_mod_add_community.id)
773       .await
774       .unwrap();
775     let expected_mod_add_community = ModAddCommunity {
776       id: inserted_mod_add_community.id,
777       community_id: inserted_community.id,
778       mod_person_id: inserted_mod.id,
779       other_person_id: inserted_person.id,
780       removed: Some(false),
781       when_: inserted_mod_add_community.when_,
782     };
783
784     // mod add
785
786     let mod_add_form = ModAddForm {
787       mod_person_id: inserted_mod.id,
788       other_person_id: inserted_person.id,
789       removed: None,
790     };
791     let inserted_mod_add = ModAdd::create(pool, &mod_add_form).await.unwrap();
792     let read_mod_add = ModAdd::read(pool, inserted_mod_add.id).await.unwrap();
793     let expected_mod_add = ModAdd {
794       id: inserted_mod_add.id,
795       mod_person_id: inserted_mod.id,
796       other_person_id: inserted_person.id,
797       removed: Some(false),
798       when_: inserted_mod_add.when_,
799     };
800
801     Comment::delete(pool, inserted_comment.id).await.unwrap();
802     Post::delete(pool, inserted_post.id).await.unwrap();
803     Community::delete(pool, inserted_community.id)
804       .await
805       .unwrap();
806     Person::delete(pool, inserted_person.id).await.unwrap();
807     Person::delete(pool, inserted_mod.id).await.unwrap();
808     Instance::delete(pool, inserted_instance.id).await.unwrap();
809
810     assert_eq!(expected_mod_remove_post, read_mod_remove_post);
811     assert_eq!(expected_mod_lock_post, read_mod_lock_post);
812     assert_eq!(expected_mod_sticky_post, read_mod_sticky_post);
813     assert_eq!(expected_mod_remove_comment, read_mod_remove_comment);
814     assert_eq!(expected_mod_remove_community, read_mod_remove_community);
815     assert_eq!(expected_mod_ban_from_community, read_mod_ban_from_community);
816     assert_eq!(expected_mod_ban, read_mod_ban);
817     assert_eq!(expected_mod_add_community, read_mod_add_community);
818     assert_eq!(expected_mod_add, read_mod_add);
819   }
820 }