2023-06-10 22:26:15 +02:00
|
|
|
use chorus::types::{self, Channel, PermissionFlags, PermissionOverwrite};
|
2023-05-27 22:12:15 +02:00
|
|
|
|
2023-06-11 13:52:31 +02:00
|
|
|
mod common;
|
|
|
|
|
2023-05-27 22:12:15 +02:00
|
|
|
#[tokio::test]
|
|
|
|
async fn get_channel() {
|
|
|
|
let mut bundle = common::setup().await;
|
|
|
|
let bundle_channel = bundle.channel.clone();
|
2023-06-11 13:54:54 +02:00
|
|
|
let bundle_user = &mut bundle.user;
|
2023-05-27 22:12:15 +02:00
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
bundle_channel,
|
2023-06-11 13:54:08 +02:00
|
|
|
Channel::get(bundle_user, &bundle_channel.id.to_string())
|
2023-05-29 23:01:17 +02:00
|
|
|
.await
|
|
|
|
.unwrap()
|
2023-05-27 22:12:15 +02:00
|
|
|
);
|
|
|
|
common::teardown(bundle).await
|
|
|
|
}
|
2023-05-28 23:04:56 +02:00
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn delete_channel() {
|
|
|
|
let mut bundle = common::setup().await;
|
2023-05-29 23:08:52 +02:00
|
|
|
let result = bundle.channel.clone().delete(&mut bundle.user).await;
|
2023-05-28 23:04:56 +02:00
|
|
|
assert!(result.is_none());
|
2023-05-29 18:29:08 +02:00
|
|
|
common::teardown(bundle).await
|
2023-05-28 23:04:56 +02:00
|
|
|
}
|
2023-05-29 18:50:09 +02:00
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn modify_channel() {
|
|
|
|
let mut bundle = common::setup().await;
|
|
|
|
let modify_data: types::ChannelModifySchema = types::ChannelModifySchema {
|
|
|
|
name: Some("beepboop".to_string()),
|
|
|
|
channel_type: None,
|
|
|
|
topic: None,
|
|
|
|
icon: None,
|
|
|
|
bitrate: None,
|
|
|
|
user_limit: None,
|
|
|
|
rate_limit_per_user: None,
|
|
|
|
position: None,
|
|
|
|
permission_overwrites: None,
|
|
|
|
parent_id: None,
|
|
|
|
nsfw: None,
|
|
|
|
rtc_region: None,
|
|
|
|
default_auto_archive_duration: None,
|
|
|
|
default_reaction_emoji: None,
|
|
|
|
flags: None,
|
|
|
|
default_thread_rate_limit_per_user: None,
|
|
|
|
video_quality_mode: None,
|
|
|
|
};
|
|
|
|
let result = Channel::modify(
|
|
|
|
modify_data,
|
|
|
|
&bundle.channel.id.to_string(),
|
2023-05-29 23:11:12 +02:00
|
|
|
&mut bundle.user,
|
2023-05-29 18:50:09 +02:00
|
|
|
)
|
2023-06-11 13:52:53 +02:00
|
|
|
.await
|
|
|
|
.unwrap();
|
2023-05-29 18:50:09 +02:00
|
|
|
assert_eq!(result.name, Some("beepboop".to_string()));
|
2023-06-10 22:26:15 +02:00
|
|
|
|
|
|
|
let permission_override = PermissionFlags::from_vec(Vec::from([
|
|
|
|
PermissionFlags::MANAGE_CHANNELS,
|
|
|
|
PermissionFlags::MANAGE_MESSAGES,
|
|
|
|
]));
|
|
|
|
let permission_override = PermissionOverwrite {
|
|
|
|
id: bundle.user.object.id.to_string(),
|
|
|
|
overwrite_type: "1".to_string(),
|
|
|
|
allow: permission_override,
|
|
|
|
deny: "0".to_string(),
|
|
|
|
};
|
|
|
|
|
|
|
|
Channel::edit_permissions(
|
|
|
|
&mut bundle.user,
|
|
|
|
bundle.channel.id.to_string().as_str(),
|
|
|
|
permission_override.clone(),
|
|
|
|
)
|
2023-06-11 13:52:53 +02:00
|
|
|
.await;
|
2023-06-10 22:26:15 +02:00
|
|
|
|
|
|
|
Channel::delete_permission(
|
|
|
|
&mut bundle.user,
|
|
|
|
bundle.channel.id.to_string().as_str(),
|
|
|
|
&permission_override.id,
|
|
|
|
)
|
2023-06-11 13:52:53 +02:00
|
|
|
.await;
|
2023-06-10 22:26:15 +02:00
|
|
|
|
2023-05-29 18:50:09 +02:00
|
|
|
common::teardown(bundle).await
|
|
|
|
}
|