2020-12-18 16:17:21 +00:00
|
|
|
use crate::Crud;
|
2020-05-16 14:04:08 +00:00
|
|
|
use diesel::{dsl::*, result::Error, *};
|
2020-12-21 13:38:34 +00:00
|
|
|
use lemmy_db_schema::source::moderator::*;
|
2019-04-15 23:12:06 +00:00
|
|
|
|
|
|
|
impl Crud<ModRemovePostForm> for ModRemovePost {
|
|
|
|
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
|
2020-12-18 16:17:21 +00:00
|
|
|
use lemmy_db_schema::schema::mod_remove_post::dsl::*;
|
2019-09-07 15:35:05 +00:00
|
|
|
mod_remove_post.find(from_id).first::<Self>(conn)
|
2019-04-15 23:12:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn create(conn: &PgConnection, form: &ModRemovePostForm) -> Result<Self, Error> {
|
2020-12-18 16:17:21 +00:00
|
|
|
use lemmy_db_schema::schema::mod_remove_post::dsl::*;
|
2019-09-07 15:35:05 +00:00
|
|
|
insert_into(mod_remove_post)
|
|
|
|
.values(form)
|
|
|
|
.get_result::<Self>(conn)
|
2019-04-15 23:12:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn update(conn: &PgConnection, from_id: i32, form: &ModRemovePostForm) -> Result<Self, Error> {
|
2020-12-18 16:17:21 +00:00
|
|
|
use lemmy_db_schema::schema::mod_remove_post::dsl::*;
|
2019-04-15 23:12:06 +00:00
|
|
|
diesel::update(mod_remove_post.find(from_id))
|
|
|
|
.set(form)
|
|
|
|
.get_result::<Self>(conn)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Crud<ModLockPostForm> for ModLockPost {
|
|
|
|
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
|
2020-12-18 16:17:21 +00:00
|
|
|
use lemmy_db_schema::schema::mod_lock_post::dsl::*;
|
2019-09-07 15:35:05 +00:00
|
|
|
mod_lock_post.find(from_id).first::<Self>(conn)
|
2019-04-15 23:12:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn create(conn: &PgConnection, form: &ModLockPostForm) -> Result<Self, Error> {
|
2020-12-18 16:17:21 +00:00
|
|
|
use lemmy_db_schema::schema::mod_lock_post::dsl::*;
|
2019-09-07 15:35:05 +00:00
|
|
|
insert_into(mod_lock_post)
|
|
|
|
.values(form)
|
|
|
|
.get_result::<Self>(conn)
|
2019-04-15 23:12:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn update(conn: &PgConnection, from_id: i32, form: &ModLockPostForm) -> Result<Self, Error> {
|
2020-12-18 16:17:21 +00:00
|
|
|
use lemmy_db_schema::schema::mod_lock_post::dsl::*;
|
2019-04-15 23:12:06 +00:00
|
|
|
diesel::update(mod_lock_post.find(from_id))
|
|
|
|
.set(form)
|
|
|
|
.get_result::<Self>(conn)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-09 06:14:13 +00:00
|
|
|
impl Crud<ModStickyPostForm> for ModStickyPost {
|
|
|
|
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
|
2020-12-18 16:17:21 +00:00
|
|
|
use lemmy_db_schema::schema::mod_sticky_post::dsl::*;
|
2019-09-09 06:14:13 +00:00
|
|
|
mod_sticky_post.find(from_id).first::<Self>(conn)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn create(conn: &PgConnection, form: &ModStickyPostForm) -> Result<Self, Error> {
|
2020-12-18 16:17:21 +00:00
|
|
|
use lemmy_db_schema::schema::mod_sticky_post::dsl::*;
|
2019-09-09 06:14:13 +00:00
|
|
|
insert_into(mod_sticky_post)
|
|
|
|
.values(form)
|
|
|
|
.get_result::<Self>(conn)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn update(conn: &PgConnection, from_id: i32, form: &ModStickyPostForm) -> Result<Self, Error> {
|
2020-12-18 16:17:21 +00:00
|
|
|
use lemmy_db_schema::schema::mod_sticky_post::dsl::*;
|
2019-09-09 06:14:13 +00:00
|
|
|
diesel::update(mod_sticky_post.find(from_id))
|
|
|
|
.set(form)
|
|
|
|
.get_result::<Self>(conn)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-15 23:12:06 +00:00
|
|
|
impl Crud<ModRemoveCommentForm> for ModRemoveComment {
|
|
|
|
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
|
2020-12-18 16:17:21 +00:00
|
|
|
use lemmy_db_schema::schema::mod_remove_comment::dsl::*;
|
2019-09-07 15:35:05 +00:00
|
|
|
mod_remove_comment.find(from_id).first::<Self>(conn)
|
2019-04-15 23:12:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn create(conn: &PgConnection, form: &ModRemoveCommentForm) -> Result<Self, Error> {
|
2020-12-18 16:17:21 +00:00
|
|
|
use lemmy_db_schema::schema::mod_remove_comment::dsl::*;
|
2019-09-07 15:35:05 +00:00
|
|
|
insert_into(mod_remove_comment)
|
|
|
|
.values(form)
|
|
|
|
.get_result::<Self>(conn)
|
2019-04-15 23:12:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn update(conn: &PgConnection, from_id: i32, form: &ModRemoveCommentForm) -> Result<Self, Error> {
|
2020-12-18 16:17:21 +00:00
|
|
|
use lemmy_db_schema::schema::mod_remove_comment::dsl::*;
|
2019-04-15 23:12:06 +00:00
|
|
|
diesel::update(mod_remove_comment.find(from_id))
|
|
|
|
.set(form)
|
|
|
|
.get_result::<Self>(conn)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Crud<ModRemoveCommunityForm> for ModRemoveCommunity {
|
|
|
|
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
|
2020-12-18 16:17:21 +00:00
|
|
|
use lemmy_db_schema::schema::mod_remove_community::dsl::*;
|
2019-09-07 15:35:05 +00:00
|
|
|
mod_remove_community.find(from_id).first::<Self>(conn)
|
2019-04-15 23:12:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn create(conn: &PgConnection, form: &ModRemoveCommunityForm) -> Result<Self, Error> {
|
2020-12-18 16:17:21 +00:00
|
|
|
use lemmy_db_schema::schema::mod_remove_community::dsl::*;
|
2019-09-07 15:35:05 +00:00
|
|
|
insert_into(mod_remove_community)
|
|
|
|
.values(form)
|
|
|
|
.get_result::<Self>(conn)
|
2019-04-15 23:12:06 +00:00
|
|
|
}
|
|
|
|
|
2019-09-07 15:35:05 +00:00
|
|
|
fn update(
|
|
|
|
conn: &PgConnection,
|
|
|
|
from_id: i32,
|
|
|
|
form: &ModRemoveCommunityForm,
|
|
|
|
) -> Result<Self, Error> {
|
2020-12-18 16:17:21 +00:00
|
|
|
use lemmy_db_schema::schema::mod_remove_community::dsl::*;
|
2019-04-15 23:12:06 +00:00
|
|
|
diesel::update(mod_remove_community.find(from_id))
|
|
|
|
.set(form)
|
|
|
|
.get_result::<Self>(conn)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Crud<ModBanFromCommunityForm> for ModBanFromCommunity {
|
|
|
|
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
|
2020-12-18 16:17:21 +00:00
|
|
|
use lemmy_db_schema::schema::mod_ban_from_community::dsl::*;
|
2019-09-07 15:35:05 +00:00
|
|
|
mod_ban_from_community.find(from_id).first::<Self>(conn)
|
2019-04-15 23:12:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn create(conn: &PgConnection, form: &ModBanFromCommunityForm) -> Result<Self, Error> {
|
2020-12-18 16:17:21 +00:00
|
|
|
use lemmy_db_schema::schema::mod_ban_from_community::dsl::*;
|
2019-09-07 15:35:05 +00:00
|
|
|
insert_into(mod_ban_from_community)
|
|
|
|
.values(form)
|
|
|
|
.get_result::<Self>(conn)
|
2019-04-15 23:12:06 +00:00
|
|
|
}
|
|
|
|
|
2019-09-07 15:35:05 +00:00
|
|
|
fn update(
|
|
|
|
conn: &PgConnection,
|
|
|
|
from_id: i32,
|
|
|
|
form: &ModBanFromCommunityForm,
|
|
|
|
) -> Result<Self, Error> {
|
2020-12-18 16:17:21 +00:00
|
|
|
use lemmy_db_schema::schema::mod_ban_from_community::dsl::*;
|
2019-04-15 23:12:06 +00:00
|
|
|
diesel::update(mod_ban_from_community.find(from_id))
|
|
|
|
.set(form)
|
|
|
|
.get_result::<Self>(conn)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Crud<ModBanForm> for ModBan {
|
|
|
|
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
|
2020-12-18 16:17:21 +00:00
|
|
|
use lemmy_db_schema::schema::mod_ban::dsl::*;
|
2019-09-07 15:35:05 +00:00
|
|
|
mod_ban.find(from_id).first::<Self>(conn)
|
2019-04-15 23:12:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn create(conn: &PgConnection, form: &ModBanForm) -> Result<Self, Error> {
|
2020-12-18 16:17:21 +00:00
|
|
|
use lemmy_db_schema::schema::mod_ban::dsl::*;
|
2019-09-07 15:35:05 +00:00
|
|
|
insert_into(mod_ban).values(form).get_result::<Self>(conn)
|
2019-04-15 23:12:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn update(conn: &PgConnection, from_id: i32, form: &ModBanForm) -> Result<Self, Error> {
|
2020-12-18 16:17:21 +00:00
|
|
|
use lemmy_db_schema::schema::mod_ban::dsl::*;
|
2019-04-15 23:12:06 +00:00
|
|
|
diesel::update(mod_ban.find(from_id))
|
|
|
|
.set(form)
|
|
|
|
.get_result::<Self>(conn)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Crud<ModAddCommunityForm> for ModAddCommunity {
|
|
|
|
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
|
2020-12-18 16:17:21 +00:00
|
|
|
use lemmy_db_schema::schema::mod_add_community::dsl::*;
|
2019-09-07 15:35:05 +00:00
|
|
|
mod_add_community.find(from_id).first::<Self>(conn)
|
2019-04-15 23:12:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn create(conn: &PgConnection, form: &ModAddCommunityForm) -> Result<Self, Error> {
|
2020-12-18 16:17:21 +00:00
|
|
|
use lemmy_db_schema::schema::mod_add_community::dsl::*;
|
2019-09-07 15:35:05 +00:00
|
|
|
insert_into(mod_add_community)
|
|
|
|
.values(form)
|
|
|
|
.get_result::<Self>(conn)
|
2019-04-15 23:12:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn update(conn: &PgConnection, from_id: i32, form: &ModAddCommunityForm) -> Result<Self, Error> {
|
2020-12-18 16:17:21 +00:00
|
|
|
use lemmy_db_schema::schema::mod_add_community::dsl::*;
|
2019-04-15 23:12:06 +00:00
|
|
|
diesel::update(mod_add_community.find(from_id))
|
|
|
|
.set(form)
|
|
|
|
.get_result::<Self>(conn)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Crud<ModAddForm> for ModAdd {
|
|
|
|
fn read(conn: &PgConnection, from_id: i32) -> Result<Self, Error> {
|
2020-12-18 16:17:21 +00:00
|
|
|
use lemmy_db_schema::schema::mod_add::dsl::*;
|
2019-09-07 15:35:05 +00:00
|
|
|
mod_add.find(from_id).first::<Self>(conn)
|
2019-04-15 23:12:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn create(conn: &PgConnection, form: &ModAddForm) -> Result<Self, Error> {
|
2020-12-18 16:17:21 +00:00
|
|
|
use lemmy_db_schema::schema::mod_add::dsl::*;
|
2019-09-07 15:35:05 +00:00
|
|
|
insert_into(mod_add).values(form).get_result::<Self>(conn)
|
2019-04-15 23:12:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn update(conn: &PgConnection, from_id: i32, form: &ModAddForm) -> Result<Self, Error> {
|
2020-12-18 16:17:21 +00:00
|
|
|
use lemmy_db_schema::schema::mod_add::dsl::*;
|
2019-04-15 23:12:06 +00:00
|
|
|
diesel::update(mod_add.find(from_id))
|
|
|
|
.set(form)
|
|
|
|
.get_result::<Self>(conn)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
2020-12-21 16:30:34 +00:00
|
|
|
use crate::{establish_unpooled_connection, Crud, ListingType, SortType};
|
2021-02-26 13:49:58 +00:00
|
|
|
use lemmy_db_schema::source::{comment::*, community::*, moderator::*, post::*, person::*};
|
2020-05-16 14:04:08 +00:00
|
|
|
|
2019-04-15 23:12:06 +00:00
|
|
|
// use Crud;
|
2019-09-07 15:35:05 +00:00
|
|
|
#[test]
|
2019-04-15 23:12:06 +00:00
|
|
|
fn test_crud() {
|
2020-01-12 15:31:51 +00:00
|
|
|
let conn = establish_unpooled_connection();
|
2019-04-15 23:12:06 +00:00
|
|
|
|
2021-02-26 13:49:58 +00:00
|
|
|
let new_mod = PersonForm {
|
2019-04-15 23:12:06 +00:00
|
|
|
name: "the mod".into(),
|
|
|
|
preferred_username: None,
|
2019-12-29 20:39:48 +00:00
|
|
|
avatar: None,
|
2020-08-05 16:03:46 +00:00
|
|
|
banner: None,
|
2020-11-10 16:11:08 +00:00
|
|
|
banned: Some(false),
|
2021-02-26 13:49:58 +00:00
|
|
|
deleted: false,
|
2020-09-18 11:04:12 +00:00
|
|
|
published: None,
|
2019-08-14 03:15:52 +00:00
|
|
|
updated: None,
|
2020-08-31 13:48:02 +00:00
|
|
|
actor_id: None,
|
2020-04-03 04:12:05 +00:00
|
|
|
bio: None,
|
|
|
|
local: true,
|
|
|
|
private_key: None,
|
|
|
|
public_key: None,
|
|
|
|
last_refreshed_at: None,
|
2021-02-04 16:34:58 +00:00
|
|
|
inbox_url: None,
|
|
|
|
shared_inbox_url: None,
|
2019-04-15 23:12:06 +00:00
|
|
|
};
|
|
|
|
|
2021-02-26 13:49:58 +00:00
|
|
|
let inserted_mod = Person::create(&conn, &new_mod).unwrap();
|
2019-04-15 23:12:06 +00:00
|
|
|
|
2021-02-26 13:49:58 +00:00
|
|
|
let new_person = PersonForm {
|
2019-04-15 23:12:06 +00:00
|
|
|
name: "jim2".into(),
|
|
|
|
preferred_username: None,
|
2019-12-29 20:39:48 +00:00
|
|
|
avatar: None,
|
2020-08-05 16:03:46 +00:00
|
|
|
banner: None,
|
2020-11-10 16:11:08 +00:00
|
|
|
banned: Some(false),
|
2021-02-26 13:49:58 +00:00
|
|
|
deleted: false,
|
2020-09-18 11:04:12 +00:00
|
|
|
published: None,
|
2019-08-14 03:15:52 +00:00
|
|
|
updated: None,
|
2020-08-31 13:48:02 +00:00
|
|
|
actor_id: None,
|
2020-04-03 04:12:05 +00:00
|
|
|
bio: None,
|
|
|
|
local: true,
|
|
|
|
private_key: None,
|
|
|
|
public_key: None,
|
|
|
|
last_refreshed_at: None,
|
2021-02-04 16:34:58 +00:00
|
|
|
inbox_url: None,
|
|
|
|
shared_inbox_url: None,
|
2019-04-15 23:12:06 +00:00
|
|
|
};
|
|
|
|
|
2021-02-26 13:49:58 +00:00
|
|
|
let inserted_person = Person::create(&conn, &new_person).unwrap();
|
2019-04-15 23:12:06 +00:00
|
|
|
|
|
|
|
let new_community = CommunityForm {
|
|
|
|
name: "mod_community".to_string(),
|
|
|
|
title: "nada".to_owned(),
|
|
|
|
description: None,
|
2021-02-26 13:49:58 +00:00
|
|
|
creator_id: inserted_person.id,
|
2019-04-15 23:12:06 +00:00
|
|
|
removed: None,
|
2019-04-29 19:14:54 +00:00
|
|
|
deleted: None,
|
2019-08-14 03:15:52 +00:00
|
|
|
updated: None,
|
|
|
|
nsfw: false,
|
2020-08-31 13:48:02 +00:00
|
|
|
actor_id: None,
|
2020-04-03 04:12:05 +00:00
|
|
|
local: true,
|
|
|
|
private_key: None,
|
|
|
|
public_key: None,
|
|
|
|
last_refreshed_at: None,
|
2020-04-07 16:47:19 +00:00
|
|
|
published: None,
|
2020-08-05 16:03:46 +00:00
|
|
|
icon: None,
|
|
|
|
banner: None,
|
2021-02-04 16:34:58 +00:00
|
|
|
followers_url: None,
|
|
|
|
inbox_url: None,
|
|
|
|
shared_inbox_url: None,
|
2019-04-15 23:12:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
let inserted_community = Community::create(&conn, &new_community).unwrap();
|
2019-09-07 15:35:05 +00:00
|
|
|
|
2019-04-15 23:12:06 +00:00
|
|
|
let new_post = PostForm {
|
|
|
|
name: "A test post thweep".into(),
|
|
|
|
url: None,
|
|
|
|
body: None,
|
2021-02-26 13:49:58 +00:00
|
|
|
creator_id: inserted_person.id,
|
2019-04-15 23:12:06 +00:00
|
|
|
community_id: inserted_community.id,
|
|
|
|
removed: None,
|
2019-04-29 19:14:54 +00:00
|
|
|
deleted: None,
|
2019-04-15 23:12:06 +00:00
|
|
|
locked: None,
|
2019-09-09 06:14:13 +00:00
|
|
|
stickied: None,
|
2019-08-14 03:15:52 +00:00
|
|
|
updated: None,
|
|
|
|
nsfw: false,
|
2020-03-07 23:31:13 +00:00
|
|
|
embed_title: None,
|
|
|
|
embed_description: None,
|
|
|
|
embed_html: None,
|
|
|
|
thumbnail_url: None,
|
2020-08-31 13:48:02 +00:00
|
|
|
ap_id: None,
|
2020-04-04 00:04:57 +00:00
|
|
|
local: true,
|
2020-04-07 16:47:19 +00:00
|
|
|
published: None,
|
2019-04-15 23:12:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
let inserted_post = Post::create(&conn, &new_post).unwrap();
|
|
|
|
|
|
|
|
let comment_form = CommentForm {
|
|
|
|
content: "A test comment".into(),
|
2021-02-26 13:49:58 +00:00
|
|
|
creator_id: inserted_person.id,
|
2019-04-15 23:12:06 +00:00
|
|
|
post_id: inserted_post.id,
|
|
|
|
removed: None,
|
2019-04-29 19:14:54 +00:00
|
|
|
deleted: None,
|
2019-04-20 23:47:23 +00:00
|
|
|
read: None,
|
2019-04-15 23:12:06 +00:00
|
|
|
parent_id: None,
|
2020-04-27 16:57:00 +00:00
|
|
|
published: None,
|
2019-09-07 15:35:05 +00:00
|
|
|
updated: None,
|
2020-08-31 13:48:02 +00:00
|
|
|
ap_id: None,
|
2020-04-04 00:04:57 +00:00
|
|
|
local: true,
|
2019-04-15 23:12:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
let inserted_comment = Comment::create(&conn, &comment_form).unwrap();
|
|
|
|
|
|
|
|
// Now the actual tests
|
|
|
|
|
|
|
|
// remove post
|
|
|
|
let mod_remove_post_form = ModRemovePostForm {
|
2021-02-26 13:49:58 +00:00
|
|
|
mod_person_id: inserted_mod.id,
|
2019-04-15 23:12:06 +00:00
|
|
|
post_id: inserted_post.id,
|
|
|
|
reason: None,
|
|
|
|
removed: None,
|
|
|
|
};
|
|
|
|
let inserted_mod_remove_post = ModRemovePost::create(&conn, &mod_remove_post_form).unwrap();
|
2019-09-09 06:14:13 +00:00
|
|
|
let read_mod_remove_post = ModRemovePost::read(&conn, inserted_mod_remove_post.id).unwrap();
|
|
|
|
let expected_mod_remove_post = ModRemovePost {
|
2019-04-15 23:12:06 +00:00
|
|
|
id: inserted_mod_remove_post.id,
|
|
|
|
post_id: inserted_post.id,
|
2021-02-26 13:49:58 +00:00
|
|
|
mod_person_id: inserted_mod.id,
|
2019-04-15 23:12:06 +00:00
|
|
|
reason: None,
|
|
|
|
removed: Some(true),
|
|
|
|
when_: inserted_mod_remove_post.when_,
|
|
|
|
};
|
|
|
|
|
|
|
|
// lock post
|
|
|
|
|
|
|
|
let mod_lock_post_form = ModLockPostForm {
|
2021-02-26 13:49:58 +00:00
|
|
|
mod_person_id: inserted_mod.id,
|
2019-04-15 23:12:06 +00:00
|
|
|
post_id: inserted_post.id,
|
|
|
|
locked: None,
|
|
|
|
};
|
|
|
|
let inserted_mod_lock_post = ModLockPost::create(&conn, &mod_lock_post_form).unwrap();
|
2019-09-09 06:14:13 +00:00
|
|
|
let read_mod_lock_post = ModLockPost::read(&conn, inserted_mod_lock_post.id).unwrap();
|
|
|
|
let expected_mod_lock_post = ModLockPost {
|
2019-04-15 23:12:06 +00:00
|
|
|
id: inserted_mod_lock_post.id,
|
|
|
|
post_id: inserted_post.id,
|
2021-02-26 13:49:58 +00:00
|
|
|
mod_person_id: inserted_mod.id,
|
2019-04-15 23:12:06 +00:00
|
|
|
locked: Some(true),
|
|
|
|
when_: inserted_mod_lock_post.when_,
|
|
|
|
};
|
|
|
|
|
2019-09-09 06:14:13 +00:00
|
|
|
// sticky post
|
|
|
|
|
|
|
|
let mod_sticky_post_form = ModStickyPostForm {
|
2021-02-26 13:49:58 +00:00
|
|
|
mod_person_id: inserted_mod.id,
|
2019-09-09 06:14:13 +00:00
|
|
|
post_id: inserted_post.id,
|
|
|
|
stickied: None,
|
|
|
|
};
|
|
|
|
let inserted_mod_sticky_post = ModStickyPost::create(&conn, &mod_sticky_post_form).unwrap();
|
|
|
|
let read_mod_sticky_post = ModStickyPost::read(&conn, inserted_mod_sticky_post.id).unwrap();
|
|
|
|
let expected_mod_sticky_post = ModStickyPost {
|
|
|
|
id: inserted_mod_sticky_post.id,
|
|
|
|
post_id: inserted_post.id,
|
2021-02-26 13:49:58 +00:00
|
|
|
mod_person_id: inserted_mod.id,
|
2019-09-09 06:14:13 +00:00
|
|
|
stickied: Some(true),
|
|
|
|
when_: inserted_mod_sticky_post.when_,
|
|
|
|
};
|
|
|
|
|
2019-04-15 23:12:06 +00:00
|
|
|
// comment
|
|
|
|
|
|
|
|
let mod_remove_comment_form = ModRemoveCommentForm {
|
2021-02-26 13:49:58 +00:00
|
|
|
mod_person_id: inserted_mod.id,
|
2019-04-15 23:12:06 +00:00
|
|
|
comment_id: inserted_comment.id,
|
|
|
|
reason: None,
|
|
|
|
removed: None,
|
|
|
|
};
|
2019-09-07 15:35:05 +00:00
|
|
|
let inserted_mod_remove_comment =
|
|
|
|
ModRemoveComment::create(&conn, &mod_remove_comment_form).unwrap();
|
2019-09-09 06:14:13 +00:00
|
|
|
let read_mod_remove_comment =
|
2019-09-07 15:35:05 +00:00
|
|
|
ModRemoveComment::read(&conn, inserted_mod_remove_comment.id).unwrap();
|
2019-09-09 06:14:13 +00:00
|
|
|
let expected_mod_remove_comment = ModRemoveComment {
|
2019-04-15 23:12:06 +00:00
|
|
|
id: inserted_mod_remove_comment.id,
|
|
|
|
comment_id: inserted_comment.id,
|
2021-02-26 13:49:58 +00:00
|
|
|
mod_person_id: inserted_mod.id,
|
2019-04-15 23:12:06 +00:00
|
|
|
reason: None,
|
|
|
|
removed: Some(true),
|
|
|
|
when_: inserted_mod_remove_comment.when_,
|
|
|
|
};
|
|
|
|
|
|
|
|
// community
|
|
|
|
|
|
|
|
let mod_remove_community_form = ModRemoveCommunityForm {
|
2021-02-26 13:49:58 +00:00
|
|
|
mod_person_id: inserted_mod.id,
|
2019-04-15 23:12:06 +00:00
|
|
|
community_id: inserted_community.id,
|
|
|
|
reason: None,
|
|
|
|
removed: None,
|
|
|
|
expires: None,
|
|
|
|
};
|
2019-09-07 15:35:05 +00:00
|
|
|
let inserted_mod_remove_community =
|
|
|
|
ModRemoveCommunity::create(&conn, &mod_remove_community_form).unwrap();
|
2019-09-09 06:14:13 +00:00
|
|
|
let read_mod_remove_community =
|
2019-09-07 15:35:05 +00:00
|
|
|
ModRemoveCommunity::read(&conn, inserted_mod_remove_community.id).unwrap();
|
2019-09-09 06:14:13 +00:00
|
|
|
let expected_mod_remove_community = ModRemoveCommunity {
|
2019-04-15 23:12:06 +00:00
|
|
|
id: inserted_mod_remove_community.id,
|
|
|
|
community_id: inserted_community.id,
|
2021-02-26 13:49:58 +00:00
|
|
|
mod_person_id: inserted_mod.id,
|
2019-04-15 23:12:06 +00:00
|
|
|
reason: None,
|
|
|
|
removed: Some(true),
|
|
|
|
expires: None,
|
|
|
|
when_: inserted_mod_remove_community.when_,
|
|
|
|
};
|
|
|
|
|
|
|
|
// ban from community
|
|
|
|
|
|
|
|
let mod_ban_from_community_form = ModBanFromCommunityForm {
|
2021-02-26 13:49:58 +00:00
|
|
|
mod_person_id: inserted_mod.id,
|
|
|
|
other_person_id: inserted_person.id,
|
2019-04-15 23:12:06 +00:00
|
|
|
community_id: inserted_community.id,
|
|
|
|
reason: None,
|
|
|
|
banned: None,
|
|
|
|
expires: None,
|
|
|
|
};
|
2019-09-07 15:35:05 +00:00
|
|
|
let inserted_mod_ban_from_community =
|
|
|
|
ModBanFromCommunity::create(&conn, &mod_ban_from_community_form).unwrap();
|
2019-09-09 06:14:13 +00:00
|
|
|
let read_mod_ban_from_community =
|
2019-09-07 15:35:05 +00:00
|
|
|
ModBanFromCommunity::read(&conn, inserted_mod_ban_from_community.id).unwrap();
|
2019-09-09 06:14:13 +00:00
|
|
|
let expected_mod_ban_from_community = ModBanFromCommunity {
|
2019-04-15 23:12:06 +00:00
|
|
|
id: inserted_mod_ban_from_community.id,
|
|
|
|
community_id: inserted_community.id,
|
2021-02-26 13:49:58 +00:00
|
|
|
mod_person_id: inserted_mod.id,
|
|
|
|
other_person_id: inserted_person.id,
|
2019-04-15 23:12:06 +00:00
|
|
|
reason: None,
|
|
|
|
banned: Some(true),
|
|
|
|
expires: None,
|
|
|
|
when_: inserted_mod_ban_from_community.when_,
|
|
|
|
};
|
|
|
|
|
|
|
|
// ban
|
|
|
|
|
|
|
|
let mod_ban_form = ModBanForm {
|
2021-02-26 13:49:58 +00:00
|
|
|
mod_person_id: inserted_mod.id,
|
|
|
|
other_person_id: inserted_person.id,
|
2019-04-15 23:12:06 +00:00
|
|
|
reason: None,
|
|
|
|
banned: None,
|
|
|
|
expires: None,
|
|
|
|
};
|
|
|
|
let inserted_mod_ban = ModBan::create(&conn, &mod_ban_form).unwrap();
|
2019-09-09 06:14:13 +00:00
|
|
|
let read_mod_ban = ModBan::read(&conn, inserted_mod_ban.id).unwrap();
|
|
|
|
let expected_mod_ban = ModBan {
|
2019-04-15 23:12:06 +00:00
|
|
|
id: inserted_mod_ban.id,
|
2021-02-26 13:49:58 +00:00
|
|
|
mod_person_id: inserted_mod.id,
|
|
|
|
other_person_id: inserted_person.id,
|
2019-04-15 23:12:06 +00:00
|
|
|
reason: None,
|
|
|
|
banned: Some(true),
|
|
|
|
expires: None,
|
|
|
|
when_: inserted_mod_ban.when_,
|
|
|
|
};
|
|
|
|
|
|
|
|
// mod add community
|
|
|
|
|
|
|
|
let mod_add_community_form = ModAddCommunityForm {
|
2021-02-26 13:49:58 +00:00
|
|
|
mod_person_id: inserted_mod.id,
|
|
|
|
other_person_id: inserted_person.id,
|
2019-04-15 23:12:06 +00:00
|
|
|
community_id: inserted_community.id,
|
|
|
|
removed: None,
|
|
|
|
};
|
2019-09-07 15:35:05 +00:00
|
|
|
let inserted_mod_add_community =
|
|
|
|
ModAddCommunity::create(&conn, &mod_add_community_form).unwrap();
|
2019-09-09 06:14:13 +00:00
|
|
|
let read_mod_add_community =
|
2019-09-07 15:35:05 +00:00
|
|
|
ModAddCommunity::read(&conn, inserted_mod_add_community.id).unwrap();
|
2019-09-09 06:14:13 +00:00
|
|
|
let expected_mod_add_community = ModAddCommunity {
|
2019-04-15 23:12:06 +00:00
|
|
|
id: inserted_mod_add_community.id,
|
|
|
|
community_id: inserted_community.id,
|
2021-02-26 13:49:58 +00:00
|
|
|
mod_person_id: inserted_mod.id,
|
|
|
|
other_person_id: inserted_person.id,
|
2019-04-15 23:12:06 +00:00
|
|
|
removed: Some(false),
|
|
|
|
when_: inserted_mod_add_community.when_,
|
|
|
|
};
|
|
|
|
|
|
|
|
// mod add
|
|
|
|
|
|
|
|
let mod_add_form = ModAddForm {
|
2021-02-26 13:49:58 +00:00
|
|
|
mod_person_id: inserted_mod.id,
|
|
|
|
other_person_id: inserted_person.id,
|
2019-04-15 23:12:06 +00:00
|
|
|
removed: None,
|
|
|
|
};
|
|
|
|
let inserted_mod_add = ModAdd::create(&conn, &mod_add_form).unwrap();
|
2019-09-09 06:14:13 +00:00
|
|
|
let read_mod_add = ModAdd::read(&conn, inserted_mod_add.id).unwrap();
|
|
|
|
let expected_mod_add = ModAdd {
|
2019-04-15 23:12:06 +00:00
|
|
|
id: inserted_mod_add.id,
|
2021-02-26 13:49:58 +00:00
|
|
|
mod_person_id: inserted_mod.id,
|
|
|
|
other_person_id: inserted_person.id,
|
2019-04-15 23:12:06 +00:00
|
|
|
removed: Some(false),
|
|
|
|
when_: inserted_mod_add.when_,
|
|
|
|
};
|
|
|
|
|
|
|
|
Comment::delete(&conn, inserted_comment.id).unwrap();
|
|
|
|
Post::delete(&conn, inserted_post.id).unwrap();
|
|
|
|
Community::delete(&conn, inserted_community.id).unwrap();
|
2021-02-26 13:49:58 +00:00
|
|
|
Person::delete(&conn, inserted_person.id).unwrap();
|
|
|
|
Person::delete(&conn, inserted_mod.id).unwrap();
|
2019-04-15 23:12:06 +00:00
|
|
|
|
2019-09-09 06:14:13 +00:00
|
|
|
assert_eq!(expected_mod_remove_post, read_mod_remove_post);
|
|
|
|
assert_eq!(expected_mod_lock_post, read_mod_lock_post);
|
|
|
|
assert_eq!(expected_mod_sticky_post, read_mod_sticky_post);
|
|
|
|
assert_eq!(expected_mod_remove_comment, read_mod_remove_comment);
|
|
|
|
assert_eq!(expected_mod_remove_community, read_mod_remove_community);
|
|
|
|
assert_eq!(expected_mod_ban_from_community, read_mod_ban_from_community);
|
|
|
|
assert_eq!(expected_mod_ban, read_mod_ban);
|
|
|
|
assert_eq!(expected_mod_add_community, read_mod_add_community);
|
|
|
|
assert_eq!(expected_mod_add, read_mod_add);
|
2019-04-15 23:12:06 +00:00
|
|
|
}
|
|
|
|
}
|