Compare commits
2 Commits
b29d987ee4
...
5fc1457f9c
Author | SHA1 | Date |
---|---|---|
kozabrada123 | 5fc1457f9c | |
kozabrada123 | 53f08ff1f9 |
|
@ -133,6 +133,8 @@ impl ChorusUser {
|
|||
/// To create normal connection types, see [Self::authorize_connection] and
|
||||
/// [Self::create_connection_callback]
|
||||
///
|
||||
/// As of 2024/08/21, Spacebar does not yet implement this endpoint.
|
||||
///
|
||||
/// # Examples
|
||||
/// ```no_run
|
||||
/// let domain = "example.com".to_string();
|
||||
|
|
|
@ -91,6 +91,8 @@ impl From<Connection> for PublicConnection {
|
|||
#[serde(rename_all = "lowercase")]
|
||||
/// A type of connection; the service the connection is for
|
||||
///
|
||||
/// Note: this is subject to change, and the enum is likely non-exhaustive
|
||||
///
|
||||
/// # Reference
|
||||
/// See <https://docs.discord.sex/resources/user#connection-type>
|
||||
pub enum ConnectionType {
|
||||
|
@ -105,6 +107,8 @@ pub enum ConnectionType {
|
|||
/// (Not returned in Get User Profile or when fetching connections)
|
||||
Contacts,
|
||||
Crunchyroll,
|
||||
/// Note: spacebar only
|
||||
Discord,
|
||||
Domain,
|
||||
Ebay,
|
||||
EpicGames,
|
||||
|
@ -151,9 +155,42 @@ impl Display for ConnectionType {
|
|||
}
|
||||
|
||||
impl ConnectionType {
|
||||
/// Returns an array of all the connections
|
||||
pub fn array() -> [ConnectionType; 25] {
|
||||
[
|
||||
/// Returns an vector of all the connection types
|
||||
// API note: this could be an array, but it is subject to change.
|
||||
pub fn vector() -> Vec<ConnectionType> {
|
||||
vec![
|
||||
ConnectionType::AmazonMusic,
|
||||
ConnectionType::BattleNet,
|
||||
ConnectionType::Bungie,
|
||||
ConnectionType::Contacts,
|
||||
ConnectionType::Crunchyroll,
|
||||
ConnectionType::Discord,
|
||||
ConnectionType::Domain,
|
||||
ConnectionType::Ebay,
|
||||
ConnectionType::EpicGames,
|
||||
ConnectionType::Facebook,
|
||||
ConnectionType::GitHub,
|
||||
ConnectionType::Instagram,
|
||||
ConnectionType::LeagueOfLegends,
|
||||
ConnectionType::PayPal,
|
||||
ConnectionType::Playstation,
|
||||
ConnectionType::Reddit,
|
||||
ConnectionType::RiotGames,
|
||||
ConnectionType::Samsung,
|
||||
ConnectionType::Spotify,
|
||||
ConnectionType::Skype,
|
||||
ConnectionType::Steam,
|
||||
ConnectionType::TikTok,
|
||||
ConnectionType::Twitch,
|
||||
ConnectionType::Twitter,
|
||||
ConnectionType::Xbox,
|
||||
ConnectionType::YouTube,
|
||||
]
|
||||
}
|
||||
|
||||
/// Returns an vector of all the connection types available on discord
|
||||
pub fn discord_vector() -> Vec<ConnectionType> {
|
||||
vec![
|
||||
ConnectionType::AmazonMusic,
|
||||
ConnectionType::BattleNet,
|
||||
ConnectionType::Bungie,
|
||||
|
@ -181,6 +218,23 @@ impl ConnectionType {
|
|||
ConnectionType::YouTube,
|
||||
]
|
||||
}
|
||||
|
||||
/// Returns an vector of all the connection types available on spacebar
|
||||
pub fn spacebar_vector() -> Vec<ConnectionType> {
|
||||
vec![
|
||||
ConnectionType::BattleNet,
|
||||
ConnectionType::Discord,
|
||||
ConnectionType::EpicGames,
|
||||
ConnectionType::Facebook,
|
||||
ConnectionType::GitHub,
|
||||
ConnectionType::Reddit,
|
||||
ConnectionType::Spotify,
|
||||
ConnectionType::Twitch,
|
||||
ConnectionType::Twitter,
|
||||
ConnectionType::Xbox,
|
||||
ConnectionType::YouTube,
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(
|
||||
|
@ -226,10 +280,10 @@ impl Display for TwoWayLinkType {
|
|||
/// # Reference
|
||||
/// See <https://docs.discord.sex/resources/user#subreddit-structure>
|
||||
pub struct ConnectionSubreddit {
|
||||
/// The subreddit's internal id, e.g. "t5_388p4"
|
||||
pub id: String,
|
||||
/// How many reddit users follow the subreddit
|
||||
pub subscribers: usize,
|
||||
/// The subreddit's relative url, e.g. "/r/discordapp/"
|
||||
pub url: String,
|
||||
/// The subreddit's internal id, e.g. "t5_388p4"
|
||||
pub id: String,
|
||||
/// How many reddit users follow the subreddit
|
||||
pub subscribers: usize,
|
||||
/// The subreddit's relative url, e.g. "/r/discordapp/"
|
||||
pub url: String,
|
||||
}
|
||||
|
|
169
tests/user.rs
169
tests/user.rs
|
@ -2,7 +2,13 @@
|
|||
// 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/.
|
||||
|
||||
use chorus::types::{PublicUser, Snowflake, User};
|
||||
use chorus::{
|
||||
errors::ChorusError,
|
||||
types::{
|
||||
ConnectionType, DeleteDisableUserSchema, PublicUser, Snowflake, User,
|
||||
UserModifyProfileSchema, UserNote,
|
||||
},
|
||||
};
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
use wasm_bindgen_test::*;
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
|
@ -43,3 +49,164 @@ async fn test_get_user_profile() {
|
|||
|
||||
common::teardown(bundle).await;
|
||||
}
|
||||
|
||||
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
|
||||
#[cfg_attr(not(target_arch = "wasm32"), tokio::test)]
|
||||
async fn test_modify_user_profile() {
|
||||
let mut bundle = common::setup().await;
|
||||
|
||||
let bio = Some(String::from("A user."));
|
||||
let pronouns = Some(String::from("they/them"));
|
||||
|
||||
let modify = UserModifyProfileSchema {
|
||||
bio: bio.clone(),
|
||||
pronouns: pronouns.clone(),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
bundle.user.modify_profile(modify).await.unwrap();
|
||||
|
||||
let user_id = bundle.user.object.read().unwrap().id;
|
||||
|
||||
let user_profile = bundle
|
||||
.user
|
||||
.get_user_profile(user_id, chorus::types::GetUserProfileSchema::default())
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(user_profile.profile_metadata.bio, bio);
|
||||
assert_eq!(user_profile.profile_metadata.pronouns, pronouns.unwrap());
|
||||
|
||||
common::teardown(bundle).await;
|
||||
}
|
||||
|
||||
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
|
||||
#[cfg_attr(not(target_arch = "wasm32"), tokio::test)]
|
||||
async fn test_disable_user() {
|
||||
let mut bundle = common::setup().await;
|
||||
|
||||
let mut other_user = bundle.create_user("integrationtestuser4").await;
|
||||
|
||||
other_user
|
||||
.disable(DeleteDisableUserSchema { password: None })
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
common::teardown(bundle).await;
|
||||
}
|
||||
|
||||
// Note: these two tests are currently broken.
|
||||
// FIXME: readd them once bitfl0wer/server#2 is merged
|
||||
/*
|
||||
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
|
||||
#[cfg_attr(not(target_arch = "wasm32"), tokio::test)]
|
||||
async fn test_get_user_note() {
|
||||
let mut bundle = common::setup().await;
|
||||
|
||||
let mut other_user = bundle.create_user("integrationtestuser3").await;
|
||||
|
||||
let user_id = bundle.user.object.read().unwrap().id;
|
||||
let other_user_id = other_user.object.read().unwrap().id;
|
||||
|
||||
let result = bundle.user.get_user_note(other_user_id).await;
|
||||
assert!(matches!(
|
||||
result.err().unwrap(),
|
||||
ChorusError::NotFound { .. }
|
||||
));
|
||||
|
||||
bundle
|
||||
.user
|
||||
.set_user_note(other_user_id, Some(String::from("A note.")))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert!(false);
|
||||
|
||||
let result = bundle.user.get_user_note(other_user_id).await;
|
||||
assert_eq!(
|
||||
result,
|
||||
Ok(UserNote {
|
||||
user_id,
|
||||
note_user_id: other_user_id,
|
||||
note: String::from("A note.")
|
||||
})
|
||||
);
|
||||
|
||||
other_user
|
||||
.delete(DeleteDisableUserSchema { password: None })
|
||||
.await
|
||||
.unwrap();
|
||||
common::teardown(bundle).await;
|
||||
}
|
||||
|
||||
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
|
||||
#[cfg_attr(not(target_arch = "wasm32"), tokio::test)]
|
||||
async fn test_set_user_note() {
|
||||
let mut bundle = common::setup().await;
|
||||
|
||||
let mut other_user = bundle.create_user("integrationtestuser3").await;
|
||||
|
||||
let user_id = bundle.user.object.read().unwrap().id;
|
||||
let other_user_id = other_user.object.read().unwrap().id;
|
||||
|
||||
bundle
|
||||
.user
|
||||
.set_user_note(other_user_id, Some(String::from("A note.")))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let result = bundle.user.get_user_note(other_user_id).await;
|
||||
assert_eq!(
|
||||
result,
|
||||
Ok(UserNote {
|
||||
user_id,
|
||||
note_user_id: other_user_id,
|
||||
note: String::from("A note.")
|
||||
})
|
||||
);
|
||||
|
||||
other_user
|
||||
.delete(DeleteDisableUserSchema { password: None })
|
||||
.await
|
||||
.unwrap();
|
||||
common::teardown(bundle).await;
|
||||
}*/
|
||||
|
||||
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
|
||||
#[cfg_attr(not(target_arch = "wasm32"), tokio::test)]
|
||||
async fn test_get_user_affinities() {
|
||||
let mut bundle = common::setup().await;
|
||||
|
||||
let result = bundle.user.get_user_affinities().await.unwrap();
|
||||
|
||||
assert!(result.user_affinities.is_empty());
|
||||
assert!(result.inverse_user_affinities.is_empty());
|
||||
|
||||
common::teardown(bundle).await;
|
||||
}
|
||||
|
||||
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
|
||||
#[cfg_attr(not(target_arch = "wasm32"), tokio::test)]
|
||||
async fn test_get_guild_affinities() {
|
||||
let mut bundle = common::setup().await;
|
||||
|
||||
let result = bundle.user.get_guild_affinities().await.unwrap();
|
||||
|
||||
assert!(result.guild_affinities.is_empty());
|
||||
|
||||
common::teardown(bundle).await;
|
||||
}
|
||||
|
||||
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
|
||||
#[cfg_attr(not(target_arch = "wasm32"), tokio::test)]
|
||||
async fn test_get_connections() {
|
||||
let mut bundle = common::setup().await;
|
||||
|
||||
let result = bundle.user.get_connections().await.unwrap();
|
||||
|
||||
// We can't *really* test creating or getting connections...
|
||||
// TODO: Find a way?
|
||||
assert!(result.is_empty());
|
||||
|
||||
common::teardown(bundle).await;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue