chorus/tests/roles.rs

69 lines
2.2 KiB
Rust
Raw Permalink Normal View History

2023-08-26 16:54:24 +02:00
use chorus::types::{self, RoleCreateModifySchema, RoleObject};
2023-11-20 14:03:06 +01:00
#[cfg(target_arch = "wasm32")]
use wasm_bindgen_test::*;
#[cfg(target_arch = "wasm32")]
wasm_bindgen_test_configure!(run_in_browser);
mod common;
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
#[cfg_attr(not(target_arch = "wasm32"), tokio::test)]
async fn create_and_get_roles() {
let mut bundle = common::setup().await;
2023-06-09 21:35:15 +02:00
let permissions = types::PermissionFlags::CONNECT | types::PermissionFlags::MANAGE_EVENTS;
let permissions = Some(permissions.to_string());
let role_create_schema: types::RoleCreateModifySchema = RoleCreateModifySchema {
name: Some("cool person".to_string()),
2023-06-09 21:35:15 +02:00
permissions,
hoist: Some(true),
icon: None,
unicode_emoji: Some("".to_string()),
mentionable: Some(true),
position: None,
color: None,
};
let guild_id = bundle.guild.read().unwrap().id;
let role = types::RoleObject::create(&mut bundle.user, guild_id, role_create_schema)
.await
.unwrap();
let expected = types::RoleObject::get_all(&mut bundle.user, guild_id)
.await
2023-06-19 10:27:32 +02:00
.unwrap()[2]
.clone();
assert_eq!(role, expected);
common::teardown(bundle).await
}
2023-06-10 19:42:41 +02:00
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
#[cfg_attr(not(target_arch = "wasm32"), tokio::test)]
2023-08-26 16:54:24 +02:00
async fn get_and_delete_role() {
2023-06-10 19:42:41 +02:00
let mut bundle = common::setup().await;
let guild_id = bundle.guild.read().unwrap().id;
let role_id = bundle.role.read().unwrap().id;
let role = bundle.role.read().unwrap().clone();
2023-06-10 19:42:41 +02:00
let same_role = chorus::types::RoleObject::get(&mut bundle.user, guild_id, role_id)
.await
.unwrap();
assert_eq!(role, same_role);
2023-08-26 16:54:24 +02:00
assert_eq!(
chorus::types::RoleObject::get_all(&mut bundle.user, guild_id)
.await
.unwrap()
.len(),
2
);
RoleObject::delete_role(&mut bundle.user, guild_id, role_id, None)
.await
.unwrap();
assert_eq!(
chorus::types::RoleObject::get_all(&mut bundle.user, guild_id)
.await
.unwrap()
.len(),
1
);
2023-06-10 19:42:41 +02:00
common::teardown(bundle).await
}