From bd7bb90baf4260ecc541a1874762f700d1c1504b Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Mon, 20 Nov 2023 14:03:06 +0100 Subject: [PATCH] Add tests for WASM --- tests/auth.rs | 12 ++++++++++++ tests/channels.rs | 36 ++++++++++++++++++++++++++++++++++++ tests/gateway.rs | 29 +++++++++++++++++++++++++++++ tests/guilds.rs | 35 +++++++++++++++++++++++++++++++++++ tests/instance.rs | 11 +++++++++++ tests/invites.rs | 12 ++++++++++++ tests/members.rs | 11 +++++++++++ tests/messages.rs | 29 +++++++++++++++++++++++++++++ tests/relationships.rs | 29 +++++++++++++++++++++++++++++ tests/roles.rs | 17 +++++++++++++++++ 10 files changed, 221 insertions(+) diff --git a/tests/auth.rs b/tests/auth.rs index f89e5e4..4c79562 100644 --- a/tests/auth.rs +++ b/tests/auth.rs @@ -1,7 +1,13 @@ use chorus::types::RegisterSchema; +// PRETTYFYME: Move common wasm setup to common.rs +#[cfg(target_arch = "wasm32")] +use wasm_bindgen_test::*; +#[cfg(target_arch = "wasm32")] +wasm_bindgen_test_configure!(run_in_browser); mod common; +#[cfg(not(target_arch = "wasm32"))] #[tokio::test] async fn test_registration() { let bundle = common::setup().await; @@ -14,3 +20,9 @@ async fn test_registration() { bundle.instance.clone().register_account(reg).await.unwrap(); common::teardown(bundle).await; } + +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn test_registration_wasm() { + test_registration().await +} diff --git a/tests/channels.rs b/tests/channels.rs index 1647652..d1b85b2 100644 --- a/tests/channels.rs +++ b/tests/channels.rs @@ -4,6 +4,42 @@ use chorus::types::{ }; mod common; +// PRETTYFYME: Move common wasm setup to common.rs + +#[cfg(target_arch = "wasm32")] +use wasm_bindgen_test::*; +#[cfg(target_arch = "wasm32")] +wasm_bindgen_test_configure!(run_in_browser); +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn test_get_channel_wasm() { + get_channel().await +} +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn test_delete_channel_wasm() { + delete_channel().await +} +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn test_modify_channel_wasm() { + modify_channel().await +} +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn test_get_channel_messages_wasm() { + get_channel_messages().await +} +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn test_create_dm_wasm() { + create_dm().await +} +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn test_remove_add_person_from_to_dm_wasm() { + remove_add_person_from_to_dm().await +} #[tokio::test] async fn get_channel() { diff --git a/tests/gateway.rs b/tests/gateway.rs index 0b1e12f..a05a798 100644 --- a/tests/gateway.rs +++ b/tests/gateway.rs @@ -4,6 +4,35 @@ use std::sync::{Arc, RwLock}; use chorus::gateway::*; use chorus::types::{self, ChannelModifySchema, RoleCreateModifySchema, RoleObject}; +// PRETTYFYME: Move common wasm setup to common.rs +#[cfg(target_arch = "wasm32")] +use wasm_bindgen_test::*; +#[cfg(target_arch = "wasm32")] +wasm_bindgen_test_configure!(run_in_browser); + +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn test_gateway_establish_wasm() { + test_gateway_establish().await +} + +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn test_gateway_authenticate_wasm() { + test_gateway_authenticate().await +} + +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn test_self_updating_structs_wasm() { + test_self_updating_structs().await +} + +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn test_recursive_self_updating_structs_wasm() { + test_recursive_self_updating_structs().await +} #[tokio::test] /// Tests establishing a connection (hello and heartbeats) on the local gateway; diff --git a/tests/guilds.rs b/tests/guilds.rs index d7e2699..2bafbab 100644 --- a/tests/guilds.rs +++ b/tests/guilds.rs @@ -3,6 +3,41 @@ use chorus::types::{ }; mod common; +// PRETTYFYME: Move common wasm setup to common.rs +#[cfg(target_arch = "wasm32")] +use wasm_bindgen_test::*; +#[cfg(target_arch = "wasm32")] +wasm_bindgen_test_configure!(run_in_browser); + +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn guild_creation_deletion_wasm() { + guild_creation_deletion().await +} + +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn get_channels_wasm() { + get_channels().await +} + +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn guild_create_ban_wasm() { + guild_create_ban().await +} + +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn modify_guild_wasm() { + modify_guild().await +} + +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn guild_remove_member_wasm() { + guild_remove_member().await +} #[tokio::test] async fn guild_creation_deletion() { diff --git a/tests/instance.rs b/tests/instance.rs index d3cd5f0..2466e60 100644 --- a/tests/instance.rs +++ b/tests/instance.rs @@ -1,4 +1,15 @@ mod common; +// PRETTYFYME: Move common wasm setup to common.rs +#[cfg(target_arch = "wasm32")] +use wasm_bindgen_test::*; +#[cfg(target_arch = "wasm32")] +wasm_bindgen_test_configure!(run_in_browser); + +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn guild_creation_deletion_wasm() { + guild_creation_deletion().await +} #[tokio::test] async fn generate_general_configuration_schema() { diff --git a/tests/invites.rs b/tests/invites.rs index ab264d4..a535b84 100644 --- a/tests/invites.rs +++ b/tests/invites.rs @@ -1,5 +1,17 @@ mod common; use chorus::types::CreateChannelInviteSchema; +// PRETTYFYME: Move common wasm setup to common.rs +#[cfg(target_arch = "wasm32")] +use wasm_bindgen_test::*; +#[cfg(target_arch = "wasm32")] +wasm_bindgen_test_configure!(run_in_browser); + +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn create_accept_invite_wasm() { + create_accept_invite().await +} + #[tokio::test] async fn create_accept_invite() { let mut bundle = common::setup().await; diff --git a/tests/members.rs b/tests/members.rs index fbab772..a2043ef 100644 --- a/tests/members.rs +++ b/tests/members.rs @@ -1,7 +1,18 @@ use chorus::{errors::ChorusResult, types::GuildMember}; +// PRETTYFYME: Move common wasm setup to common.rs +#[cfg(target_arch = "wasm32")] +use wasm_bindgen_test::*; +#[cfg(target_arch = "wasm32")] +wasm_bindgen_test_configure!(run_in_browser); mod common; +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn add_remove_role_wasm() { + add_remove_role().await.unwrap() +} + #[tokio::test] async fn add_remove_role() -> ChorusResult<()> { let mut bundle = common::setup().await; diff --git a/tests/messages.rs b/tests/messages.rs index 5ad9a89..fc46831 100644 --- a/tests/messages.rs +++ b/tests/messages.rs @@ -2,9 +2,38 @@ use std::fs::File; use std::io::{BufReader, Read}; use chorus::types::{self, Guild, Message, MessageSearchQuery}; +// PRETTYFYME: Move common wasm setup to common.rs +#[cfg(target_arch = "wasm32")] +use wasm_bindgen_test::*; +#[cfg(target_arch = "wasm32")] +wasm_bindgen_test_configure!(run_in_browser); mod common; +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn send_message_wasm() { + send_message().await +} + +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn send_message_attachment_wasm() { + send_message_attachment().await +} + +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn search_messages_wasm() { + search_messages().await +} + +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn test_stickies_wasm() { + test_stickies().await +} + #[tokio::test] async fn send_message() { let mut bundle = common::setup().await; diff --git a/tests/relationships.rs b/tests/relationships.rs index 09ddab0..7f26e0f 100644 --- a/tests/relationships.rs +++ b/tests/relationships.rs @@ -1,7 +1,36 @@ use chorus::types::{self, Relationship, RelationshipType}; +// PRETTYFYME: Move common wasm setup to common.rs +#[cfg(target_arch = "wasm32")] +use wasm_bindgen_test::*; +#[cfg(target_arch = "wasm32")] +wasm_bindgen_test_configure!(run_in_browser); mod common; +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn test_get_relationships_wasm() { + test_get_relationships().await +} + +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn test_get_mutual_relationships_wasm() { + test_get_mutual_relationships().await +} + +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn test_modify_relationship_friends_wasm() { + test_modify_relationship_friends().await +} + +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn test_modify_relationship_block_wasm() { + test_modify_relationship_block().await +} + #[tokio::test] async fn test_get_mutual_relationships() { let mut bundle = common::setup().await; diff --git a/tests/roles.rs b/tests/roles.rs index 8691138..0dd3b7f 100644 --- a/tests/roles.rs +++ b/tests/roles.rs @@ -1,7 +1,24 @@ use chorus::types::{self, RoleCreateModifySchema, RoleObject}; +// PRETTYFYME: Move common wasm setup to common.rs +#[cfg(target_arch = "wasm32")] +use wasm_bindgen_test::*; +#[cfg(target_arch = "wasm32")] +wasm_bindgen_test_configure!(run_in_browser); mod common; +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn create_and_get_roles_wasm() { + create_and_get_roles().await +} + +#[cfg(target_arch = "wasm32")] +#[wasm_bindgen_test] +async fn get_and_delete_role_wasm() { + get_and_delete_role().await +} + #[tokio::test] async fn create_and_get_roles() { let mut bundle = common::setup().await;