diff --git a/src/api/auth/login.rs b/src/api/auth/login.rs index 8589b39..7ecc4de 100644 --- a/src/api/auth/login.rs +++ b/src/api/auth/login.rs @@ -70,54 +70,3 @@ pub mod login { } } } - -/*#[cfg(test)] -mod test { - use crate::api::schemas::schemas::{ - AuthEmail, AuthPassword, AuthUsername, LoginSchema, RegisterSchema, - }; - use crate::instance::Instance; - use crate::limit::LimitedRequester; - use crate::URLBundle; - - #[tokio::test] - async fn test_login() { - let urls = URLBundle::new( - "http://localhost:3001/api".to_string(), - "http://localhost:3001".to_string(), - "http://localhost:3001".to_string(), - ); - let limited_requester = LimitedRequester::new(urls.get_api().to_string()).await; - let mut test_instance = Instance::new(urls.clone(), limited_requester) - .await - .unwrap(); - let reg = RegisterSchema::new( - AuthUsername::new("TestAccount".to_string()).unwrap(), - Some(AuthPassword::new("transrights".to_string()).unwrap()), - true, - Some(AuthEmail::new("apiauthlogin1@testlogin.xyz".to_string()).unwrap()), - None, - None, - Some("2000-01-01".to_string()), - None, - None, - None, - ) - .unwrap(); - test_instance.register_account(®).await.unwrap().token; - - let login_schema = LoginSchema::new( - AuthUsername::new("apiauthlogin1@testlogin.xyz".to_string()).unwrap(), - "transrights".to_string(), - Some(false), - None, - None, - None, - ); - - let login_result = test_instance - .login_account(&login_schema.unwrap()) - .await - .unwrap(); - } -}*/ diff --git a/src/api/auth/register.rs b/src/api/auth/register.rs index dc5bf61..d318916 100644 --- a/src/api/auth/register.rs +++ b/src/api/auth/register.rs @@ -78,36 +78,3 @@ pub mod register { } } } - -#[cfg(test)] -mod test { - use crate::instance::Instance; - use crate::limit::LimitedRequester; - use crate::types::RegisterSchema; - use crate::URLBundle; - - #[tokio::test] - async fn test_registration() { - let urls = URLBundle::new( - "http://localhost:3001/api".to_string(), - "http://localhost:3001".to_string(), - "http://localhost:3001".to_string(), - ); - let _limited_requester = LimitedRequester::new().await; - let mut test_instance = Instance::new(urls.clone()).await.unwrap(); - let reg = RegisterSchema::new( - "Hiiii".to_string(), - None, - true, - None, - None, - None, - Some("2000-01-01".to_string()), - None, - None, - None, - ) - .unwrap(); - let _ = test_instance.register_account(®).await.unwrap().token; - } -} diff --git a/src/api/channels/messages.rs b/src/api/channels/messages.rs index 9a68eaa..91e148a 100644 --- a/src/api/channels/messages.rs +++ b/src/api/channels/messages.rs @@ -114,137 +114,3 @@ pub mod messages { } } } - -#[cfg(test)] -mod test { - use crate::instance::UserMeta; - use crate::types::{LoginSchema, MessageSendSchema, PartialDiscordFileAttachment}; - use crate::{instance::Instance}; - - use std::io::Read; - use std::{cell::RefCell, fs::File}; - use std::{io::BufReader, rc::Rc}; - - #[tokio::test] - async fn send_message() { - let channel_id = "1106954414356168802".to_string(); - let mut message = MessageSendSchema::new( - None, - Some("A Message!".to_string()), - None, - None, - None, - None, - None, - None, - None, - None, - ); - let mut instance = Instance::new(crate::URLBundle { - api: "http://localhost:3001/api".to_string(), - wss: "ws://localhost:3001/".to_string(), - cdn: "http://localhost:3001".to_string(), - }) - .await - .unwrap(); - let login_schema: LoginSchema = LoginSchema::new( - "user@test.xyz".to_string(), - "transrights".to_string(), - None, - None, - None, - None, - ) - .unwrap(); - let login_result = instance.login_account(&login_schema).await.unwrap(); - let token = login_result.token; - println!("TOKEN: {}", token); - let settings = login_result.settings; - let limits = instance.limits.clone(); - let mut user = UserMeta::new( - Rc::new(RefCell::new(instance)), - token, - limits, - settings, - None, - ); - let _ = user - .send_message(&mut message, channel_id, None) - .await - .unwrap(); - } - - #[tokio::test] - async fn send_message_attachment() { - let channel_id = "1106954414356168802".to_string(); - - let f = File::open("./README.md").unwrap(); - let mut reader = BufReader::new(f); - let mut buffer = Vec::new(); - - reader.read_to_end(&mut buffer).unwrap(); - - let attachment = PartialDiscordFileAttachment { - id: None, - filename: "README.md".to_string(), - description: None, - content_type: None, - size: None, - url: None, - proxy_url: None, - width: None, - height: None, - ephemeral: None, - duration_secs: None, - waveform: None, - content: buffer, - }; - - let mut message = MessageSendSchema::new( - None, - Some("trans rights now".to_string()), - None, - None, - None, - None, - None, - None, - None, - Some(vec![attachment.clone()]), - ); - let mut instance = Instance::new(crate::URLBundle { - api: "http://localhost:3001/api".to_string(), - wss: "ws://localhost:3001/".to_string(), - cdn: "http://localhost:3001".to_string(), - }) - .await - .unwrap(); - let login_schema: LoginSchema = LoginSchema::new( - "user@test.xyz".to_string(), - "transrights".to_string(), - None, - None, - None, - None, - ) - .unwrap(); - let login_result = instance.login_account(&login_schema).await.unwrap(); - let token = login_result.token; - let settings = login_result.settings; - let limits = instance.limits.clone(); - let mut user = UserMeta::new( - Rc::new(RefCell::new(instance)), - token, - limits, - settings, - None, - ); - let vec_attach = vec![attachment.clone()]; - let _arg = Some(&vec_attach); - let response = user - .send_message(&mut message, channel_id, Some(vec![attachment.clone()])) - .await - .unwrap(); - println!("[Response:] {}", response.text().await.unwrap()); - } -} diff --git a/src/api/policies/instance/instance.rs b/src/api/policies/instance/instance.rs index 20d7d6f..f183e11 100644 --- a/src/api/policies/instance/instance.rs +++ b/src/api/policies/instance/instance.rs @@ -37,21 +37,3 @@ impl Instance { Ok(instance_policies_schema) } } - -#[cfg(test)] -mod instance_policies_schema_test { - use crate::{instance::Instance, limit::LimitedRequester, URLBundle}; - - #[tokio::test] - async fn generate_instance_policies_schema() { - let urls = URLBundle::new( - "http://localhost:3001/api".to_string(), - "http://localhost:3001".to_string(), - "http://localhost:3001".to_string(), - ); - let _limited_requester = LimitedRequester::new().await; - let test_instance = Instance::new(urls.clone()).await.unwrap(); - - let _schema = test_instance.general_configuration_schema().await.unwrap(); - } -} diff --git a/src/api/users/users.rs b/src/api/users/users.rs index 4113c6b..098a92f 100644 --- a/src/api/users/users.rs +++ b/src/api/users/users.rs @@ -178,10 +178,3 @@ impl Instance { .await } } - -#[cfg(test)] -mod test { - - #[tokio::test] - async fn get_user() {} -} diff --git a/src/types/schema/auth.rs b/src/types/schema/auth.rs index 073d8d4..68c4546 100644 --- a/src/types/schema/auth.rs +++ b/src/types/schema/auth.rs @@ -187,7 +187,7 @@ You will receive a [`FieldFormatError`], if: #[serde(rename_all = "snake_case")] pub struct LoginSchema { pub login: String, - pub password: String, + pub password: Option, pub undelete: Option, pub captcha_key: Option, pub login_source: Option, @@ -210,15 +210,12 @@ impl LoginSchema { */ pub fn new( login: String, - password: String, + password: Option, undelete: Option, captcha_key: Option, login_source: Option, gift_code_sku_id: Option, ) -> Result { - let login = AuthUsername::new(login)?.username; - let password = AuthPassword::new(password)?.password; - Ok(LoginSchema { login, password, diff --git a/tests/auth.rs b/tests/auth.rs new file mode 100644 index 0000000..f90e229 --- /dev/null +++ b/tests/auth.rs @@ -0,0 +1,23 @@ +mod common; + +use chorus::types; + +#[tokio::test] +async fn test_registration() { + let mut bundle = common::setup().await; + let reg = types::RegisterSchema::new( + "Hiiii".to_string(), + None, + true, + None, + None, + None, + Some("2000-01-01".to_string()), + None, + None, + None, + ) + .unwrap(); + bundle.instance.register_account(®).await.unwrap(); + common::teardown(bundle).await; +} diff --git a/tests/channel.rs b/tests/channel.rs new file mode 100644 index 0000000..4e0db28 --- /dev/null +++ b/tests/channel.rs @@ -0,0 +1,23 @@ +mod common; +use chorus::types::Channel; + +#[tokio::test] +async fn get_channel() { + let mut bundle = common::setup().await; + let bundle_channel = bundle.channel.clone(); + let bundle_user = &mut bundle.user; + + assert_eq!( + bundle_channel, + Channel::get( + bundle_user.token.as_str(), + bundle.instance.urls.get_api(), + &bundle_channel.id.to_string(), + &mut bundle_user.limits, + &mut bundle.instance.limits + ) + .await + .unwrap() + ); + common::teardown(bundle).await +} diff --git a/tests/integration.rs b/tests/common/mod.rs similarity index 58% rename from tests/integration.rs rename to tests/common/mod.rs index 116e89f..3fdb42b 100644 --- a/tests/integration.rs +++ b/tests/common/mod.rs @@ -5,16 +5,16 @@ use chorus::{ }; #[derive(Debug)] -struct TestBundle { - urls: URLBundle, - user: UserMeta, - instance: Instance, - guild_id: String, - channel: Channel, +pub struct TestBundle { + pub urls: URLBundle, + pub user: UserMeta, + pub instance: Instance, + pub guild_id: String, + pub channel: Channel, } // Set up a test by creating an Instance and a User. Reduces Test boilerplate. -async fn setup() -> TestBundle { +pub async fn setup() -> TestBundle { let urls = URLBundle::new( "http://localhost:3001/api".to_string(), "ws://localhost:3001".to_string(), @@ -89,7 +89,7 @@ async fn setup() -> TestBundle { } // Teardown method to clean up after a test. -async fn teardown(mut bundle: TestBundle) { +pub async fn teardown(mut bundle: TestBundle) { Guild::delete( &mut bundle.user, bundle.instance.urls.get_api(), @@ -98,55 +98,3 @@ async fn teardown(mut bundle: TestBundle) { .await; bundle.user.delete().await; } - -mod guild { - use chorus::types::{Channel, Guild, GuildCreateSchema}; - - #[tokio::test] - async fn guild_creation_deletion() { - let mut bundle = crate::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, - }; - - let guild = Guild::create(&mut bundle.user, bundle.urls.get_api(), guild_create_schema) - .await - .unwrap(); - - println!("{}", guild); - - match Guild::delete(&mut bundle.user, bundle.urls.get_api(), guild).await { - None => assert!(true), - Some(_) => assert!(false), - } - crate::teardown(bundle).await - } - - #[tokio::test] - async fn get_channel() { - let mut bundle = crate::setup().await; - let bundle_channel = bundle.channel.clone(); - let bundle_user = &mut bundle.user; - - assert_eq!( - bundle_channel, - Channel::get( - bundle_user.token.as_str(), - bundle.instance.urls.get_api(), - &bundle_channel.id.to_string(), - &mut bundle_user.limits, - &mut bundle.instance.limits - ) - .await - .unwrap() - ); - crate::teardown(bundle).await - } -} diff --git a/tests/guild.rs b/tests/guild.rs new file mode 100644 index 0000000..6b50a94 --- /dev/null +++ b/tests/guild.rs @@ -0,0 +1,29 @@ +mod common; +use chorus::types::{Guild, GuildCreateSchema}; + +#[tokio::test] +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, + }; + + let guild = Guild::create(&mut bundle.user, bundle.urls.get_api(), guild_create_schema) + .await + .unwrap(); + + println!("{}", guild); + + match Guild::delete(&mut bundle.user, bundle.urls.get_api(), guild).await { + None => assert!(true), + Some(_) => assert!(false), + } + common::teardown(bundle).await +} diff --git a/tests/instance.rs b/tests/instance.rs new file mode 100644 index 0000000..d3cd5f0 --- /dev/null +++ b/tests/instance.rs @@ -0,0 +1,12 @@ +mod common; + +#[tokio::test] +async fn generate_general_configuration_schema() { + let bundle = common::setup().await; + bundle + .instance + .general_configuration_schema() + .await + .unwrap(); + common::teardown(bundle).await; +} diff --git a/tests/message.rs b/tests/message.rs new file mode 100644 index 0000000..6ccda0b --- /dev/null +++ b/tests/message.rs @@ -0,0 +1,80 @@ +mod common; + +use chorus::types; +use std::fs::File; +use std::io::{BufReader, Read}; + +#[tokio::test] +async fn send_message() { + let mut bundle = common::setup().await; + let mut message = types::MessageSendSchema::new( + None, + Some("A Message!".to_string()), + None, + None, + None, + None, + None, + None, + None, + None, + ); + let _ = bundle + .user + .send_message(&mut message, bundle.channel.id.to_string(), None) + .await + .unwrap(); + common::teardown(bundle).await +} + +#[tokio::test] +async fn send_message_attachment() { + let f = File::open("./README.md").unwrap(); + let mut reader = BufReader::new(f); + let mut buffer = Vec::new(); + let mut bundle = common::setup().await; + + reader.read_to_end(&mut buffer).unwrap(); + + let attachment = types::PartialDiscordFileAttachment { + id: None, + filename: "README.md".to_string(), + description: None, + content_type: None, + size: None, + url: None, + proxy_url: None, + width: None, + height: None, + ephemeral: None, + duration_secs: None, + waveform: None, + content: buffer, + }; + + let mut message = types::MessageSendSchema::new( + None, + Some("trans rights now".to_string()), + None, + None, + None, + None, + None, + None, + None, + Some(vec![attachment.clone()]), + ); + + let vec_attach = vec![attachment.clone()]; + let _arg = Some(&vec_attach); + bundle + .user + .send_message( + &mut message, + bundle.channel.id.to_string(), + Some(vec![attachment.clone()]), + ) + .await + .unwrap(); + common::teardown(bundle).await +}