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/.
|
|
|
|
|
2024-06-03 07:32:11 +02:00
|
|
|
use std::str::FromStr;
|
|
|
|
|
2024-06-23 17:23:13 +02:00
|
|
|
use chorus::gateway::{Gateway, GatewayOptions};
|
2024-06-27 08:45:51 +02:00
|
|
|
use chorus::types::{IntoShared, PermissionFlags};
|
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,
|
2024-04-28 14:15:57 +02:00
|
|
|
RoleCreateModifySchema, RoleObject, Shared
|
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
|
|
|
};
|
|
|
|
|
2024-06-03 07:32:11 +02:00
|
|
|
use chrono::NaiveDate;
|
|
|
|
|
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,
|
2024-01-21 17:07:19 +01:00
|
|
|
pub guild: Shared<Guild>,
|
|
|
|
pub role: Shared<RoleObject>,
|
|
|
|
pub channel: Shared<Channel>,
|
2023-05-27 22:12:07 +02:00
|
|
|
}
|
|
|
|
|
2023-07-22 14:39:36 +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,
|
2024-06-03 07:32:11 +02:00
|
|
|
date_of_birth: Some(NaiveDate::from_str("2000-01-01").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
|
|
|
..Default::default()
|
|
|
|
};
|
|
|
|
self.instance
|
2023-09-01 13:01:50 +02:00
|
|
|
.clone()
|
2023-09-01 12:12:07 +02:00
|
|
|
.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 {
|
2023-07-22 14:39:36 +02:00
|
|
|
belongs_to: self.user.belongs_to.clone(),
|
|
|
|
token: self.user.token.clone(),
|
2024-07-05 18:15:24 +02:00
|
|
|
mfa_token: None,
|
2023-07-22 14:39:36 +02:00
|
|
|
limits: self.user.limits.clone(),
|
|
|
|
settings: self.user.settings.clone(),
|
|
|
|
object: self.user.object.clone(),
|
2024-06-23 17:23:13 +02:00
|
|
|
gateway: Gateway::spawn(self.instance.urls.wss.clone(), GatewayOptions::default())
|
2023-11-15 18:44:19 +01:00
|
|
|
.await
|
|
|
|
.unwrap(),
|
2023-07-22 14:39:36 +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
|
|
|
}
|
|
|
|
|
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 {
|
2024-06-23 17:23:13 +02:00
|
|
|
|
|
|
|
// So we can get logs when tests fail
|
|
|
|
let _ = simple_logger::SimpleLogger::with_level(simple_logger::SimpleLogger::new(), log::LevelFilter::Debug).init();
|
|
|
|
|
2023-12-15 00:10:33 +01:00
|
|
|
let instance = Instance::new("http://localhost:3001/api").await.unwrap();
|
2024-01-31 22:27:53 +01:00
|
|
|
// Requires the existence of the below user.
|
2023-06-25 11:33:50 +02:00
|
|
|
let reg = RegisterSchema {
|
|
|
|
username: "integrationtestuser".into(),
|
|
|
|
consent: true,
|
2024-06-03 07:32:11 +02:00
|
|
|
date_of_birth: Some(NaiveDate::from_str("2000-01-01").unwrap()),
|
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(),
|
2023-08-22 17:55:29 +02:00
|
|
|
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();
|
2023-08-25 00:02:26 +02:00
|
|
|
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()),
|
2024-06-27 08:45:51 +02:00
|
|
|
permissions: PermissionFlags::from_bits(8), // Administrator permissions
|
2023-06-10 00:23:49 +02:00
|
|
|
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-12-15 00:10:33 +01:00
|
|
|
let urls = UrlBundle::new(
|
|
|
|
"http://localhost:3001/api".to_string(),
|
|
|
|
"http://localhost:3001/api".to_string(),
|
2024-06-23 17:23:13 +02:00
|
|
|
"ws://localhost:3001/".to_string(),
|
2023-12-15 00:10:33 +01:00
|
|
|
"http://localhost:3001".to_string(),
|
|
|
|
);
|
2023-05-27 22:12:07 +02:00
|
|
|
TestBundle {
|
|
|
|
urls,
|
|
|
|
user,
|
|
|
|
instance,
|
2024-01-22 14:56:23 +01:00
|
|
|
guild: guild.into_shared(),
|
|
|
|
role: role.into_shared(),
|
|
|
|
channel: channel.into_shared(),
|
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
|
|
|
}
|