chorus/tests/common/mod.rs

132 lines
4.1 KiB
Rust
Raw Normal View History

2023-08-12 22:40:40 +02:00
use std::sync::{Arc, RwLock};
use chorus::gateway::Gateway;
2023-05-27 22:12:07 +02:00
use chorus::{
2023-08-24 21:06:28 +02:00
instance::{ChorusUser, Instance},
2023-06-10 00:23:49 +02:00
types::{
Channel, ChannelCreateSchema, Guild, GuildCreateSchema, RegisterSchema,
2023-06-25 11:33:50 +02:00
RoleCreateModifySchema, RoleObject,
2023-06-10 00:23:49 +02:00
},
2023-06-20 02:59:18 +02:00
UrlBundle,
2023-05-27 22:12:07 +02:00
};
Join/Leave Guilds, (Group) DMs and minor improvements (#157) ## Summary: **Added:** - Schemas `PrivateChannelCreateSchema` `ChannelInviteCreateSchema`, `AddChannelRecipientSchema` recursively (including schemas which were needed to create these schemas) - Methods `create_private_channel`, `leave_guild`, `accept_invite`, `create_user_invite`, `create_guild_invite`, `add_channel_recipient`, `remove_channel_recipient` - Integration tests for the functionality covered by implementing #45 - Documentation in some places where I noticed it would be useful to have some - `create_user` method in `/src/tests`: Cuts down on test boilerplate needed to create an addition test user **Changed:** - `.gitignore` - Added `.DS_store` files to gitignore (some weird macos files), removed Cargo.lock, as Cargo.lock should be included for libraries - Added a lot of default trait derives like Clone, Copy, PartialEq, Eq, Ord, PartialOrd to structs and enums where I saw them missing - Added missing `teardown()` calls to the integration tests - Renamed integration test files in `/src/tests` dir to all be plural: `channel.rs` -> `channels.rs` - Made more fields on `User` type `Option<>` - All instances in `/src/tests` where a second test user was created using a RegistrationSchema and the register_user method were replaced with the new `create_user` method - README.md: Marked roadmap fields covered by #45 as implemented - Changed visibility of `/src/tests/common/mod.rs` methods from `pub` to `pub(crate)`. In hindsight, this was probably not required, haha **Removed:** - Unneeded import in`src/types/config/types/guild_configuration.rs` ## Commit log: * Add .DS_store, remove Cargo.lock * Create PrivateChannelCreateSchema * pub use users * add channels.rs * create channels.rs * Add Deserialize/Serialize derives * Implement create_private_channel * Add create_dm() test * Make optional fields on `User` `Option<>` * Check boxes for implemented features * Create users/guilds.rs * Remove unneeded import * Add UserMeta::leave_guild() * Create api/invites/mod.rs * Add debug print to send_request * Rename tests files * Create invites.rs * create invite.rs * Add documentation * Implement accept_invite * Sort fields on Channel alphabetically * Add invite mod * Add forgotten teardown() at test end * change visiblities, add create_user() * Implement `create_user_invite()` * start working on invite tests * Add allow flags * Fix bad url * Create CreateChannelInviteSchema and friends * remove non-implemented test code * add body to requests * Add Clone to UserMeta * More comprehensive error message when running into a deserialization error * Add arguments documentation to accept_invite * Add Eq derive to GuildFeaturesList * Add Eq derive to Emoji * Add Eq derive to GuildBan * Add create_accept_invite() test * Add Default derive to ChannelCreateSchema * Change create_guild_invite to return GuildInvite * Dates as chrono::Date(Utc); sort alphabetically * Add default derives wherever possible * Implement add_- and remove_channel_recipient * Create AddChannelRecipientSchema * replace otheruser regs with bundle.creeate_user() * Add (disabled) test remove_add_person_from_to_dm()
2023-07-17 19:36:28 +02:00
#[allow(dead_code)]
2023-05-27 22:12:07 +02:00
#[derive(Debug)]
Join/Leave Guilds, (Group) DMs and minor improvements (#157) ## Summary: **Added:** - Schemas `PrivateChannelCreateSchema` `ChannelInviteCreateSchema`, `AddChannelRecipientSchema` recursively (including schemas which were needed to create these schemas) - Methods `create_private_channel`, `leave_guild`, `accept_invite`, `create_user_invite`, `create_guild_invite`, `add_channel_recipient`, `remove_channel_recipient` - Integration tests for the functionality covered by implementing #45 - Documentation in some places where I noticed it would be useful to have some - `create_user` method in `/src/tests`: Cuts down on test boilerplate needed to create an addition test user **Changed:** - `.gitignore` - Added `.DS_store` files to gitignore (some weird macos files), removed Cargo.lock, as Cargo.lock should be included for libraries - Added a lot of default trait derives like Clone, Copy, PartialEq, Eq, Ord, PartialOrd to structs and enums where I saw them missing - Added missing `teardown()` calls to the integration tests - Renamed integration test files in `/src/tests` dir to all be plural: `channel.rs` -> `channels.rs` - Made more fields on `User` type `Option<>` - All instances in `/src/tests` where a second test user was created using a RegistrationSchema and the register_user method were replaced with the new `create_user` method - README.md: Marked roadmap fields covered by #45 as implemented - Changed visibility of `/src/tests/common/mod.rs` methods from `pub` to `pub(crate)`. In hindsight, this was probably not required, haha **Removed:** - Unneeded import in`src/types/config/types/guild_configuration.rs` ## Commit log: * Add .DS_store, remove Cargo.lock * Create PrivateChannelCreateSchema * pub use users * add channels.rs * create channels.rs * Add Deserialize/Serialize derives * Implement create_private_channel * Add create_dm() test * Make optional fields on `User` `Option<>` * Check boxes for implemented features * Create users/guilds.rs * Remove unneeded import * Add UserMeta::leave_guild() * Create api/invites/mod.rs * Add debug print to send_request * Rename tests files * Create invites.rs * create invite.rs * Add documentation * Implement accept_invite * Sort fields on Channel alphabetically * Add invite mod * Add forgotten teardown() at test end * change visiblities, add create_user() * Implement `create_user_invite()` * start working on invite tests * Add allow flags * Fix bad url * Create CreateChannelInviteSchema and friends * remove non-implemented test code * add body to requests * Add Clone to UserMeta * More comprehensive error message when running into a deserialization error * Add arguments documentation to accept_invite * Add Eq derive to GuildFeaturesList * Add Eq derive to Emoji * Add Eq derive to GuildBan * Add create_accept_invite() test * Add Default derive to ChannelCreateSchema * Change create_guild_invite to return GuildInvite * Dates as chrono::Date(Utc); sort alphabetically * Add default derives wherever possible * Implement add_- and remove_channel_recipient * Create AddChannelRecipientSchema * replace otheruser regs with bundle.creeate_user() * Add (disabled) test remove_add_person_from_to_dm()
2023-07-17 19:36:28 +02:00
pub(crate) struct TestBundle {
2023-06-20 02:59:18 +02:00
pub urls: UrlBundle,
2023-08-24 21:06:28 +02:00
pub user: ChorusUser,
2023-05-27 22:12:07 +02:00
pub instance: Instance,
2023-08-12 22:40:40 +02:00
pub guild: Arc<RwLock<Guild>>,
pub role: Arc<RwLock<RoleObject>>,
pub channel: Arc<RwLock<Channel>>,
2023-05-27 22:12:07 +02:00
}
#[allow(unused)]
Join/Leave Guilds, (Group) DMs and minor improvements (#157) ## Summary: **Added:** - Schemas `PrivateChannelCreateSchema` `ChannelInviteCreateSchema`, `AddChannelRecipientSchema` recursively (including schemas which were needed to create these schemas) - Methods `create_private_channel`, `leave_guild`, `accept_invite`, `create_user_invite`, `create_guild_invite`, `add_channel_recipient`, `remove_channel_recipient` - Integration tests for the functionality covered by implementing #45 - Documentation in some places where I noticed it would be useful to have some - `create_user` method in `/src/tests`: Cuts down on test boilerplate needed to create an addition test user **Changed:** - `.gitignore` - Added `.DS_store` files to gitignore (some weird macos files), removed Cargo.lock, as Cargo.lock should be included for libraries - Added a lot of default trait derives like Clone, Copy, PartialEq, Eq, Ord, PartialOrd to structs and enums where I saw them missing - Added missing `teardown()` calls to the integration tests - Renamed integration test files in `/src/tests` dir to all be plural: `channel.rs` -> `channels.rs` - Made more fields on `User` type `Option<>` - All instances in `/src/tests` where a second test user was created using a RegistrationSchema and the register_user method were replaced with the new `create_user` method - README.md: Marked roadmap fields covered by #45 as implemented - Changed visibility of `/src/tests/common/mod.rs` methods from `pub` to `pub(crate)`. In hindsight, this was probably not required, haha **Removed:** - Unneeded import in`src/types/config/types/guild_configuration.rs` ## Commit log: * Add .DS_store, remove Cargo.lock * Create PrivateChannelCreateSchema * pub use users * add channels.rs * create channels.rs * Add Deserialize/Serialize derives * Implement create_private_channel * Add create_dm() test * Make optional fields on `User` `Option<>` * Check boxes for implemented features * Create users/guilds.rs * Remove unneeded import * Add UserMeta::leave_guild() * Create api/invites/mod.rs * Add debug print to send_request * Rename tests files * Create invites.rs * create invite.rs * Add documentation * Implement accept_invite * Sort fields on Channel alphabetically * Add invite mod * Add forgotten teardown() at test end * change visiblities, add create_user() * Implement `create_user_invite()` * start working on invite tests * Add allow flags * Fix bad url * Create CreateChannelInviteSchema and friends * remove non-implemented test code * add body to requests * Add Clone to UserMeta * More comprehensive error message when running into a deserialization error * Add arguments documentation to accept_invite * Add Eq derive to GuildFeaturesList * Add Eq derive to Emoji * Add Eq derive to GuildBan * Add create_accept_invite() test * Add Default derive to ChannelCreateSchema * Change create_guild_invite to return GuildInvite * Dates as chrono::Date(Utc); sort alphabetically * Add default derives wherever possible * Implement add_- and remove_channel_recipient * Create AddChannelRecipientSchema * replace otheruser regs with bundle.creeate_user() * Add (disabled) test remove_add_person_from_to_dm()
2023-07-17 19:36:28 +02:00
impl TestBundle {
2023-08-24 21:06:28 +02:00
pub(crate) async fn create_user(&mut self, username: &str) -> ChorusUser {
Join/Leave Guilds, (Group) DMs and minor improvements (#157) ## Summary: **Added:** - Schemas `PrivateChannelCreateSchema` `ChannelInviteCreateSchema`, `AddChannelRecipientSchema` recursively (including schemas which were needed to create these schemas) - Methods `create_private_channel`, `leave_guild`, `accept_invite`, `create_user_invite`, `create_guild_invite`, `add_channel_recipient`, `remove_channel_recipient` - Integration tests for the functionality covered by implementing #45 - Documentation in some places where I noticed it would be useful to have some - `create_user` method in `/src/tests`: Cuts down on test boilerplate needed to create an addition test user **Changed:** - `.gitignore` - Added `.DS_store` files to gitignore (some weird macos files), removed Cargo.lock, as Cargo.lock should be included for libraries - Added a lot of default trait derives like Clone, Copy, PartialEq, Eq, Ord, PartialOrd to structs and enums where I saw them missing - Added missing `teardown()` calls to the integration tests - Renamed integration test files in `/src/tests` dir to all be plural: `channel.rs` -> `channels.rs` - Made more fields on `User` type `Option<>` - All instances in `/src/tests` where a second test user was created using a RegistrationSchema and the register_user method were replaced with the new `create_user` method - README.md: Marked roadmap fields covered by #45 as implemented - Changed visibility of `/src/tests/common/mod.rs` methods from `pub` to `pub(crate)`. In hindsight, this was probably not required, haha **Removed:** - Unneeded import in`src/types/config/types/guild_configuration.rs` ## Commit log: * Add .DS_store, remove Cargo.lock * Create PrivateChannelCreateSchema * pub use users * add channels.rs * create channels.rs * Add Deserialize/Serialize derives * Implement create_private_channel * Add create_dm() test * Make optional fields on `User` `Option<>` * Check boxes for implemented features * Create users/guilds.rs * Remove unneeded import * Add UserMeta::leave_guild() * Create api/invites/mod.rs * Add debug print to send_request * Rename tests files * Create invites.rs * create invite.rs * Add documentation * Implement accept_invite * Sort fields on Channel alphabetically * Add invite mod * Add forgotten teardown() at test end * change visiblities, add create_user() * Implement `create_user_invite()` * start working on invite tests * Add allow flags * Fix bad url * Create CreateChannelInviteSchema and friends * remove non-implemented test code * add body to requests * Add Clone to UserMeta * More comprehensive error message when running into a deserialization error * Add arguments documentation to accept_invite * Add Eq derive to GuildFeaturesList * Add Eq derive to Emoji * Add Eq derive to GuildBan * Add create_accept_invite() test * Add Default derive to ChannelCreateSchema * Change create_guild_invite to return GuildInvite * Dates as chrono::Date(Utc); sort alphabetically * Add default derives wherever possible * Implement add_- and remove_channel_recipient * Create AddChannelRecipientSchema * replace otheruser regs with bundle.creeate_user() * Add (disabled) test remove_add_person_from_to_dm()
2023-07-17 19:36:28 +02:00
let register_schema = RegisterSchema {
username: username.to_string(),
consent: true,
date_of_birth: Some("2000-01-01".to_string()),
..Default::default()
};
self.instance
2023-09-01 13:01:50 +02:00
.clone()
.register_account(register_schema)
Join/Leave Guilds, (Group) DMs and minor improvements (#157) ## Summary: **Added:** - Schemas `PrivateChannelCreateSchema` `ChannelInviteCreateSchema`, `AddChannelRecipientSchema` recursively (including schemas which were needed to create these schemas) - Methods `create_private_channel`, `leave_guild`, `accept_invite`, `create_user_invite`, `create_guild_invite`, `add_channel_recipient`, `remove_channel_recipient` - Integration tests for the functionality covered by implementing #45 - Documentation in some places where I noticed it would be useful to have some - `create_user` method in `/src/tests`: Cuts down on test boilerplate needed to create an addition test user **Changed:** - `.gitignore` - Added `.DS_store` files to gitignore (some weird macos files), removed Cargo.lock, as Cargo.lock should be included for libraries - Added a lot of default trait derives like Clone, Copy, PartialEq, Eq, Ord, PartialOrd to structs and enums where I saw them missing - Added missing `teardown()` calls to the integration tests - Renamed integration test files in `/src/tests` dir to all be plural: `channel.rs` -> `channels.rs` - Made more fields on `User` type `Option<>` - All instances in `/src/tests` where a second test user was created using a RegistrationSchema and the register_user method were replaced with the new `create_user` method - README.md: Marked roadmap fields covered by #45 as implemented - Changed visibility of `/src/tests/common/mod.rs` methods from `pub` to `pub(crate)`. In hindsight, this was probably not required, haha **Removed:** - Unneeded import in`src/types/config/types/guild_configuration.rs` ## Commit log: * Add .DS_store, remove Cargo.lock * Create PrivateChannelCreateSchema * pub use users * add channels.rs * create channels.rs * Add Deserialize/Serialize derives * Implement create_private_channel * Add create_dm() test * Make optional fields on `User` `Option<>` * Check boxes for implemented features * Create users/guilds.rs * Remove unneeded import * Add UserMeta::leave_guild() * Create api/invites/mod.rs * Add debug print to send_request * Rename tests files * Create invites.rs * create invite.rs * Add documentation * Implement accept_invite * Sort fields on Channel alphabetically * Add invite mod * Add forgotten teardown() at test end * change visiblities, add create_user() * Implement `create_user_invite()` * start working on invite tests * Add allow flags * Fix bad url * Create CreateChannelInviteSchema and friends * remove non-implemented test code * add body to requests * Add Clone to UserMeta * More comprehensive error message when running into a deserialization error * Add arguments documentation to accept_invite * Add Eq derive to GuildFeaturesList * Add Eq derive to Emoji * Add Eq derive to GuildBan * Add create_accept_invite() test * Add Default derive to ChannelCreateSchema * Change create_guild_invite to return GuildInvite * Dates as chrono::Date(Utc); sort alphabetically * Add default derives wherever possible * Implement add_- and remove_channel_recipient * Create AddChannelRecipientSchema * replace otheruser regs with bundle.creeate_user() * Add (disabled) test remove_add_person_from_to_dm()
2023-07-17 19:36:28 +02:00
.await
.unwrap()
}
2023-08-24 21:06:28 +02:00
pub(crate) async fn clone_user_without_gateway(&self) -> ChorusUser {
ChorusUser {
belongs_to: self.user.belongs_to.clone(),
token: self.user.token.clone(),
limits: self.user.limits.clone(),
settings: self.user.settings.clone(),
object: self.user.object.clone(),
2023-08-29 14:24:32 +02:00
gateway: Gateway::new(self.instance.urls.wss.clone()).await.unwrap(),
}
}
Join/Leave Guilds, (Group) DMs and minor improvements (#157) ## Summary: **Added:** - Schemas `PrivateChannelCreateSchema` `ChannelInviteCreateSchema`, `AddChannelRecipientSchema` recursively (including schemas which were needed to create these schemas) - Methods `create_private_channel`, `leave_guild`, `accept_invite`, `create_user_invite`, `create_guild_invite`, `add_channel_recipient`, `remove_channel_recipient` - Integration tests for the functionality covered by implementing #45 - Documentation in some places where I noticed it would be useful to have some - `create_user` method in `/src/tests`: Cuts down on test boilerplate needed to create an addition test user **Changed:** - `.gitignore` - Added `.DS_store` files to gitignore (some weird macos files), removed Cargo.lock, as Cargo.lock should be included for libraries - Added a lot of default trait derives like Clone, Copy, PartialEq, Eq, Ord, PartialOrd to structs and enums where I saw them missing - Added missing `teardown()` calls to the integration tests - Renamed integration test files in `/src/tests` dir to all be plural: `channel.rs` -> `channels.rs` - Made more fields on `User` type `Option<>` - All instances in `/src/tests` where a second test user was created using a RegistrationSchema and the register_user method were replaced with the new `create_user` method - README.md: Marked roadmap fields covered by #45 as implemented - Changed visibility of `/src/tests/common/mod.rs` methods from `pub` to `pub(crate)`. In hindsight, this was probably not required, haha **Removed:** - Unneeded import in`src/types/config/types/guild_configuration.rs` ## Commit log: * Add .DS_store, remove Cargo.lock * Create PrivateChannelCreateSchema * pub use users * add channels.rs * create channels.rs * Add Deserialize/Serialize derives * Implement create_private_channel * Add create_dm() test * Make optional fields on `User` `Option<>` * Check boxes for implemented features * Create users/guilds.rs * Remove unneeded import * Add UserMeta::leave_guild() * Create api/invites/mod.rs * Add debug print to send_request * Rename tests files * Create invites.rs * create invite.rs * Add documentation * Implement accept_invite * Sort fields on Channel alphabetically * Add invite mod * Add forgotten teardown() at test end * change visiblities, add create_user() * Implement `create_user_invite()` * start working on invite tests * Add allow flags * Fix bad url * Create CreateChannelInviteSchema and friends * remove non-implemented test code * add body to requests * Add Clone to UserMeta * More comprehensive error message when running into a deserialization error * Add arguments documentation to accept_invite * Add Eq derive to GuildFeaturesList * Add Eq derive to Emoji * Add Eq derive to GuildBan * Add create_accept_invite() test * Add Default derive to ChannelCreateSchema * Change create_guild_invite to return GuildInvite * Dates as chrono::Date(Utc); sort alphabetically * Add default derives wherever possible * Implement add_- and remove_channel_recipient * Create AddChannelRecipientSchema * replace otheruser regs with bundle.creeate_user() * Add (disabled) test remove_add_person_from_to_dm()
2023-07-17 19:36:28 +02:00
}
2023-05-27 22:12:07 +02:00
// Set up a test by creating an Instance and a User. Reduces Test boilerplate.
Join/Leave Guilds, (Group) DMs and minor improvements (#157) ## Summary: **Added:** - Schemas `PrivateChannelCreateSchema` `ChannelInviteCreateSchema`, `AddChannelRecipientSchema` recursively (including schemas which were needed to create these schemas) - Methods `create_private_channel`, `leave_guild`, `accept_invite`, `create_user_invite`, `create_guild_invite`, `add_channel_recipient`, `remove_channel_recipient` - Integration tests for the functionality covered by implementing #45 - Documentation in some places where I noticed it would be useful to have some - `create_user` method in `/src/tests`: Cuts down on test boilerplate needed to create an addition test user **Changed:** - `.gitignore` - Added `.DS_store` files to gitignore (some weird macos files), removed Cargo.lock, as Cargo.lock should be included for libraries - Added a lot of default trait derives like Clone, Copy, PartialEq, Eq, Ord, PartialOrd to structs and enums where I saw them missing - Added missing `teardown()` calls to the integration tests - Renamed integration test files in `/src/tests` dir to all be plural: `channel.rs` -> `channels.rs` - Made more fields on `User` type `Option<>` - All instances in `/src/tests` where a second test user was created using a RegistrationSchema and the register_user method were replaced with the new `create_user` method - README.md: Marked roadmap fields covered by #45 as implemented - Changed visibility of `/src/tests/common/mod.rs` methods from `pub` to `pub(crate)`. In hindsight, this was probably not required, haha **Removed:** - Unneeded import in`src/types/config/types/guild_configuration.rs` ## Commit log: * Add .DS_store, remove Cargo.lock * Create PrivateChannelCreateSchema * pub use users * add channels.rs * create channels.rs * Add Deserialize/Serialize derives * Implement create_private_channel * Add create_dm() test * Make optional fields on `User` `Option<>` * Check boxes for implemented features * Create users/guilds.rs * Remove unneeded import * Add UserMeta::leave_guild() * Create api/invites/mod.rs * Add debug print to send_request * Rename tests files * Create invites.rs * create invite.rs * Add documentation * Implement accept_invite * Sort fields on Channel alphabetically * Add invite mod * Add forgotten teardown() at test end * change visiblities, add create_user() * Implement `create_user_invite()` * start working on invite tests * Add allow flags * Fix bad url * Create CreateChannelInviteSchema and friends * remove non-implemented test code * add body to requests * Add Clone to UserMeta * More comprehensive error message when running into a deserialization error * Add arguments documentation to accept_invite * Add Eq derive to GuildFeaturesList * Add Eq derive to Emoji * Add Eq derive to GuildBan * Add create_accept_invite() test * Add Default derive to ChannelCreateSchema * Change create_guild_invite to return GuildInvite * Dates as chrono::Date(Utc); sort alphabetically * Add default derives wherever possible * Implement add_- and remove_channel_recipient * Create AddChannelRecipientSchema * replace otheruser regs with bundle.creeate_user() * Add (disabled) test remove_add_person_from_to_dm()
2023-07-17 19:36:28 +02:00
pub(crate) async fn setup() -> TestBundle {
2023-06-20 02:59:18 +02:00
let urls = UrlBundle::new(
2023-05-27 22:12:07 +02:00
"http://localhost:3001/api".to_string(),
"ws://localhost:3001".to_string(),
"http://localhost:3001".to_string(),
);
2023-09-01 13:01:50 +02:00
let instance = Instance::new(urls.clone(), true).await.unwrap();
2023-05-27 22:12:07 +02:00
// Requires the existance of the below user.
2023-06-25 11:33:50 +02:00
let reg = RegisterSchema {
username: "integrationtestuser".into(),
consent: true,
2023-06-19 10:27:32 +02:00
date_of_birth: Some("2000-01-01".to_string()),
2023-06-25 11:33:50 +02:00
..Default::default()
};
2023-05-27 22:12:07 +02:00
let guild_create_schema = GuildCreateSchema {
name: Some("Test-Guild!".to_string()),
region: None,
icon: None,
channels: None,
guild_template_code: None,
system_channel_id: None,
rules_channel_id: None,
};
let channel_create_schema = ChannelCreateSchema {
name: "testchannel".to_string(),
channel_type: Some(chorus::types::ChannelType::GuildText),
2023-05-27 22:12:07 +02:00
topic: None,
icon: None,
bitrate: None,
user_limit: None,
rate_limit_per_user: None,
position: None,
permission_overwrites: None,
parent_id: None,
id: None,
nsfw: Some(false),
rtc_region: None,
default_auto_archive_duration: None,
default_reaction_emoji: None,
flags: Some(0),
default_thread_rate_limit_per_user: Some(0),
video_quality_mode: None,
};
2023-09-01 13:01:50 +02:00
let mut user = instance.clone().register_account(reg).await.unwrap();
2023-05-29 23:46:43 +02:00
let guild = Guild::create(&mut user, guild_create_schema).await.unwrap();
let channel = Channel::create(&mut user, guild.id, None, channel_create_schema)
2023-05-29 23:57:23 +02:00
.await
.unwrap();
2023-05-27 22:12:07 +02:00
2023-06-10 00:23:49 +02:00
let role_create_schema: chorus::types::RoleCreateModifySchema = RoleCreateModifySchema {
name: Some("Bundle role".to_string()),
permissions: Some("8".to_string()), // Administrator permissions
hoist: Some(true),
icon: None,
unicode_emoji: Some("".to_string()),
mentionable: Some(true),
position: None,
color: None,
};
2023-06-22 13:14:07 +02:00
let role = chorus::types::RoleObject::create(&mut user, guild.id, role_create_schema)
2023-06-10 00:23:49 +02:00
.await
.unwrap();
2023-05-27 22:12:07 +02:00
TestBundle {
urls,
user,
instance,
2023-08-12 22:40:40 +02:00
guild: Arc::new(RwLock::new(guild)),
role: Arc::new(RwLock::new(role)),
channel: Arc::new(RwLock::new(channel)),
2023-05-27 22:12:07 +02:00
}
}
// Teardown method to clean up after a test.
2023-06-19 19:01:18 +02:00
#[allow(dead_code)]
Join/Leave Guilds, (Group) DMs and minor improvements (#157) ## Summary: **Added:** - Schemas `PrivateChannelCreateSchema` `ChannelInviteCreateSchema`, `AddChannelRecipientSchema` recursively (including schemas which were needed to create these schemas) - Methods `create_private_channel`, `leave_guild`, `accept_invite`, `create_user_invite`, `create_guild_invite`, `add_channel_recipient`, `remove_channel_recipient` - Integration tests for the functionality covered by implementing #45 - Documentation in some places where I noticed it would be useful to have some - `create_user` method in `/src/tests`: Cuts down on test boilerplate needed to create an addition test user **Changed:** - `.gitignore` - Added `.DS_store` files to gitignore (some weird macos files), removed Cargo.lock, as Cargo.lock should be included for libraries - Added a lot of default trait derives like Clone, Copy, PartialEq, Eq, Ord, PartialOrd to structs and enums where I saw them missing - Added missing `teardown()` calls to the integration tests - Renamed integration test files in `/src/tests` dir to all be plural: `channel.rs` -> `channels.rs` - Made more fields on `User` type `Option<>` - All instances in `/src/tests` where a second test user was created using a RegistrationSchema and the register_user method were replaced with the new `create_user` method - README.md: Marked roadmap fields covered by #45 as implemented - Changed visibility of `/src/tests/common/mod.rs` methods from `pub` to `pub(crate)`. In hindsight, this was probably not required, haha **Removed:** - Unneeded import in`src/types/config/types/guild_configuration.rs` ## Commit log: * Add .DS_store, remove Cargo.lock * Create PrivateChannelCreateSchema * pub use users * add channels.rs * create channels.rs * Add Deserialize/Serialize derives * Implement create_private_channel * Add create_dm() test * Make optional fields on `User` `Option<>` * Check boxes for implemented features * Create users/guilds.rs * Remove unneeded import * Add UserMeta::leave_guild() * Create api/invites/mod.rs * Add debug print to send_request * Rename tests files * Create invites.rs * create invite.rs * Add documentation * Implement accept_invite * Sort fields on Channel alphabetically * Add invite mod * Add forgotten teardown() at test end * change visiblities, add create_user() * Implement `create_user_invite()` * start working on invite tests * Add allow flags * Fix bad url * Create CreateChannelInviteSchema and friends * remove non-implemented test code * add body to requests * Add Clone to UserMeta * More comprehensive error message when running into a deserialization error * Add arguments documentation to accept_invite * Add Eq derive to GuildFeaturesList * Add Eq derive to Emoji * Add Eq derive to GuildBan * Add create_accept_invite() test * Add Default derive to ChannelCreateSchema * Change create_guild_invite to return GuildInvite * Dates as chrono::Date(Utc); sort alphabetically * Add default derives wherever possible * Implement add_- and remove_channel_recipient * Create AddChannelRecipientSchema * replace otheruser regs with bundle.creeate_user() * Add (disabled) test remove_add_person_from_to_dm()
2023-07-17 19:36:28 +02:00
pub(crate) async fn teardown(mut bundle: TestBundle) {
2023-08-12 22:40:40 +02:00
let id = bundle.guild.read().unwrap().id;
Guild::delete(&mut bundle.user, id).await.unwrap();
2023-06-22 13:14:07 +02:00
bundle.user.delete().await.unwrap()
2023-05-27 22:12:07 +02:00
}