2024-01-30 17:19:34 +01:00
|
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
2023-08-20 23:24:06 +02:00
|
|
|
use chorus::types::{
|
|
|
|
CreateChannelInviteSchema, Guild, GuildBanCreateSchema, GuildCreateSchema, GuildModifySchema,
|
|
|
|
};
|
2023-05-27 22:11:35 +02:00
|
|
|
|
2023-06-11 13:52:31 +02:00
|
|
|
mod common;
|
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);
|
|
|
|
|
2023-11-22 14:39:32 +01:00
|
|
|
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
|
|
|
|
#[cfg_attr(not(target_arch = "wasm32"), tokio::test)]
|
2023-05-27 22:11:35 +02:00
|
|
|
async fn guild_creation_deletion() {
|
|
|
|
let mut bundle = common::setup().await;
|
|
|
|
|
|
|
|
let guild_create_schema = GuildCreateSchema {
|
|
|
|
name: Some("test".to_string()),
|
|
|
|
region: None,
|
|
|
|
icon: None,
|
|
|
|
channels: None,
|
|
|
|
guild_template_code: None,
|
|
|
|
system_channel_id: None,
|
|
|
|
rules_channel_id: None,
|
|
|
|
};
|
|
|
|
|
2023-05-29 23:16:43 +02:00
|
|
|
let guild = Guild::create(&mut bundle.user, guild_create_schema)
|
2023-05-27 22:11:35 +02:00
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
2023-06-22 13:14:07 +02:00
|
|
|
assert!(Guild::delete(&mut bundle.user, guild.id).await.is_ok());
|
2023-05-27 22:11:35 +02:00
|
|
|
common::teardown(bundle).await
|
|
|
|
}
|
2023-05-29 16:51:28 +02:00
|
|
|
|
2023-11-22 14:39:32 +01:00
|
|
|
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
|
|
|
|
#[cfg_attr(not(target_arch = "wasm32"), tokio::test)]
|
2023-05-29 16:51:28 +02:00
|
|
|
async fn get_channels() {
|
|
|
|
let mut bundle = common::setup().await;
|
2023-08-13 15:54:07 +02:00
|
|
|
let guild = bundle.guild.read().unwrap().clone();
|
|
|
|
println!("{:?}", guild.channels(&mut bundle.user).await.unwrap());
|
2023-05-29 16:51:28 +02:00
|
|
|
common::teardown(bundle).await;
|
|
|
|
}
|
2023-08-20 18:55:47 +02:00
|
|
|
|
2023-11-22 14:39:32 +01:00
|
|
|
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
|
|
|
|
#[cfg_attr(not(target_arch = "wasm32"), tokio::test)]
|
2023-08-20 18:55:47 +02:00
|
|
|
async fn guild_create_ban() {
|
|
|
|
// TODO: When routes exist to check if user x is on guild y, add this as an assertion to check
|
|
|
|
// if Spacebar actually bans the user.
|
|
|
|
let mut bundle = common::setup().await;
|
|
|
|
let channel = bundle.channel.read().unwrap().clone();
|
|
|
|
let mut other_user = bundle.create_user("testuser1312").await;
|
|
|
|
let user = &mut bundle.user;
|
|
|
|
let create_channel_invite_schema = CreateChannelInviteSchema::default();
|
|
|
|
let guild = bundle.guild.read().unwrap().clone();
|
|
|
|
let invite = user
|
|
|
|
.create_channel_invite(create_channel_invite_schema, channel.id)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
other_user.accept_invite(&invite.code, None).await.unwrap();
|
2024-07-05 18:15:24 +02:00
|
|
|
let other_user_id = other_user.object.as_ref().unwrap()
|
|
|
|
.read().unwrap().id;
|
2023-08-20 18:55:47 +02:00
|
|
|
Guild::create_ban(
|
|
|
|
guild.id,
|
|
|
|
other_user_id,
|
2023-08-25 17:26:01 +02:00
|
|
|
None,
|
2023-08-20 18:55:47 +02:00
|
|
|
GuildBanCreateSchema::default(),
|
|
|
|
&mut bundle.user,
|
|
|
|
)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
common::teardown(bundle).await
|
|
|
|
}
|
2023-08-20 23:24:06 +02:00
|
|
|
|
2023-11-22 14:39:32 +01:00
|
|
|
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
|
|
|
|
#[cfg_attr(not(target_arch = "wasm32"), tokio::test)]
|
2023-08-20 23:24:06 +02:00
|
|
|
async fn modify_guild() {
|
|
|
|
let mut bundle = common::setup().await;
|
|
|
|
let schema = GuildModifySchema {
|
|
|
|
name: Some("Mycoolguild".to_string()),
|
|
|
|
..Default::default()
|
|
|
|
};
|
|
|
|
let guild_id = bundle.guild.read().unwrap().id;
|
|
|
|
let result = Guild::modify(guild_id, schema, &mut bundle.user)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
assert_eq!(result.name.unwrap(), "Mycoolguild".to_string());
|
|
|
|
common::teardown(bundle).await
|
|
|
|
}
|
2023-08-26 16:22:47 +02:00
|
|
|
|
2023-11-22 14:39:32 +01:00
|
|
|
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
|
|
|
|
#[cfg_attr(not(target_arch = "wasm32"), tokio::test)]
|
2023-08-26 16:22:47 +02:00
|
|
|
async fn guild_remove_member() {
|
|
|
|
let mut bundle = common::setup().await;
|
|
|
|
let channel = bundle.channel.read().unwrap().clone();
|
|
|
|
let mut other_user = bundle.create_user("testuser1312").await;
|
|
|
|
let user = &mut bundle.user;
|
|
|
|
let create_channel_invite_schema = CreateChannelInviteSchema::default();
|
|
|
|
let guild = bundle.guild.read().unwrap().clone();
|
|
|
|
let invite = user
|
|
|
|
.create_channel_invite(create_channel_invite_schema, channel.id)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
other_user.accept_invite(&invite.code, None).await.unwrap();
|
2024-07-05 18:15:24 +02:00
|
|
|
let other_user_id = other_user.object
|
|
|
|
.as_ref().unwrap()
|
|
|
|
.read().unwrap().id;
|
2023-08-26 16:22:47 +02:00
|
|
|
Guild::remove_member(guild.id, other_user_id, None, &mut bundle.user)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
assert!(
|
|
|
|
Guild::remove_member(guild.id, other_user_id, None, &mut bundle.user,)
|
|
|
|
.await
|
|
|
|
.is_err()
|
|
|
|
);
|
|
|
|
common::teardown(bundle).await
|
|
|
|
}
|