2023-05-20 21:04:03 +02:00
|
|
|
use chorus::{
|
2023-05-21 15:49:52 +02:00
|
|
|
api::{AuthUsername, RegisterSchema, User},
|
2023-05-20 21:04:03 +02:00
|
|
|
instance::Instance,
|
|
|
|
URLBundle,
|
|
|
|
};
|
|
|
|
|
2023-05-21 15:51:24 +02:00
|
|
|
#[derive(Debug)]
|
2023-05-21 00:47:40 +02:00
|
|
|
struct TestBundle {
|
2023-05-20 12:22:54 +02:00
|
|
|
urls: URLBundle,
|
2023-05-21 00:47:40 +02:00
|
|
|
user: User,
|
2023-05-20 12:22:54 +02:00
|
|
|
}
|
|
|
|
|
2023-05-21 15:51:24 +02:00
|
|
|
// Set up a test by creating an Instance and a User. Reduces Test boilerplate.
|
2023-05-21 00:47:40 +02:00
|
|
|
async fn setup() -> TestBundle {
|
2023-05-20 12:22:54 +02:00
|
|
|
let urls = URLBundle::new(
|
|
|
|
"http://localhost:3001/api".to_string(),
|
|
|
|
"ws://localhost:3001".to_string(),
|
|
|
|
"http://localhost:3001".to_string(),
|
|
|
|
);
|
2023-05-21 00:47:40 +02:00
|
|
|
let mut instance = Instance::new(urls.clone()).await.unwrap();
|
2023-05-20 21:04:03 +02:00
|
|
|
// Requires the existance of the below user.
|
2023-05-21 15:49:52 +02:00
|
|
|
let reg = RegisterSchema::new(
|
|
|
|
AuthUsername::new("integrationtestuser".to_string()).unwrap(),
|
|
|
|
None,
|
|
|
|
true,
|
|
|
|
None,
|
2023-05-20 21:04:03 +02:00
|
|
|
None,
|
|
|
|
None,
|
2023-05-21 15:49:52 +02:00
|
|
|
Some("2000-01-01".to_string()),
|
|
|
|
None,
|
2023-05-20 21:04:03 +02:00
|
|
|
None,
|
|
|
|
None,
|
|
|
|
)
|
|
|
|
.unwrap();
|
2023-05-21 15:49:52 +02:00
|
|
|
let user = instance.register_account(®).await.unwrap();
|
2023-05-20 12:22:54 +02:00
|
|
|
|
2023-05-21 15:49:52 +02:00
|
|
|
TestBundle { urls, user }
|
2023-05-20 12:22:54 +02:00
|
|
|
}
|
2023-05-21 00:47:40 +02:00
|
|
|
|
2023-05-21 15:49:52 +02:00
|
|
|
// Teardown method to clean up after a test.
|
|
|
|
async fn teardown(bundle: TestBundle) {
|
|
|
|
bundle.user.delete().await;
|
|
|
|
}
|
2023-05-21 16:02:54 +02:00
|
|
|
|
|
|
|
mod guild {
|
|
|
|
use chorus::api::{schemas, types};
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn guild_creation_deletion() {
|
|
|
|
let mut bundle = crate::setup().await;
|
|
|
|
|
|
|
|
let guild_create_schema = schemas::GuildCreateSchema {
|
|
|
|
name: Some("test".to_string()),
|
|
|
|
region: None,
|
|
|
|
icon: None,
|
|
|
|
channels: None,
|
|
|
|
guild_template_code: None,
|
|
|
|
system_channel_id: None,
|
|
|
|
rules_channel_id: None,
|
|
|
|
};
|
|
|
|
|
|
|
|
let guild =
|
|
|
|
types::Guild::create(&mut bundle.user, bundle.urls.get_api(), guild_create_schema)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
println!("{}", guild);
|
|
|
|
|
|
|
|
match types::Guild::delete(&mut bundle.user, bundle.urls.get_api(), guild).await {
|
|
|
|
None => assert!(true),
|
|
|
|
Some(_) => assert!(false),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|