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