From 9cc7243c98a5c4edd3d8d16f5b15c548fe26d66d Mon Sep 17 00:00:00 2001 From: Flori Weber Date: Sun, 18 Jun 2023 23:24:10 +0200 Subject: [PATCH 1/5] Mark Friend Requests and Blocking as completed --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 82ac173..b239410 100644 --- a/README.md +++ b/README.md @@ -58,8 +58,8 @@ ### User Management - [ ] [User profile customization](https://github.com/polyphony-chat/chorus/issues/41) - [x] Gettings users and user profiles -- [ ] [Friend requests](https://github.com/polyphony-chat/chorus/issues/92) -- [ ] [Blocking users](https://github.com/polyphony-chat/chorus/issues/92) +- [x] [Friend requests](https://github.com/polyphony-chat/chorus/issues/92) +- [x] [Blocking users](https://github.com/polyphony-chat/chorus/issues/92) - [ ] User presence (online, offline, idle, etc.) - [ ] User status (custom status, etc.) - [x] Account deletion From 0a1de13f2948b4e0f701dd771fa4baa3bb8cd497 Mon Sep 17 00:00:00 2001 From: Flori Weber Date: Mon, 19 Jun 2023 18:11:53 +0200 Subject: [PATCH 2/5] Add a friendship test (:3) --- tests/relationships.rs | 59 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/tests/relationships.rs b/tests/relationships.rs index 187f07e..bdb5e68 100644 --- a/tests/relationships.rs +++ b/tests/relationships.rs @@ -1,4 +1,4 @@ -use chorus::types::{self, RegisterSchema, RegisterSchemaOptions}; +use chorus::types::{self, RegisterSchema, RegisterSchemaOptions, Relationship, RelationshipType}; mod common; @@ -47,6 +47,61 @@ async fn test_get_relationships() { }; other_user.send_friend_request(friend_request_schema).await; let relationships = user.get_relationships().await.unwrap(); - println!("{:?}", relationships); + assert_eq!(relationships.get(0).unwrap().id, other_user.object.id); + common::teardown(bundle).await +} + +#[tokio::test] +async fn test_modify_relationship_friends() { + let register_schema = RegisterSchemaOptions { + date_of_birth: Some("2000-01-01".to_string()), + ..RegisterSchema::builder("integrationtestuser2", true) + } + .build() + .unwrap(); + + let mut bundle = common::setup().await; + let belongs_to = &mut bundle.instance; + let user = &mut bundle.user; + let mut other_user = belongs_to.register_account(®ister_schema).await.unwrap(); + other_user + .modify_user_relationship( + &user.object.id.to_string(), + types::RelationshipType::Friends, + ) + .await; + let relationships = user.get_relationships().await.unwrap(); + assert_eq!(relationships.get(0).unwrap().id, other_user.object.id); + assert_eq!( + relationships.get(0).unwrap().relationship_type, + RelationshipType::Incoming + ); + let relationships = other_user.get_relationships().await.unwrap(); + assert_eq!(relationships.get(0).unwrap().id, user.object.id); + assert_eq!( + relationships.get(0).unwrap().relationship_type, + RelationshipType::Outgoing + ); + user.modify_user_relationship( + other_user.object.id.to_string().as_str(), + RelationshipType::Friends, + ) + .await; + assert_eq!( + other_user + .get_relationships() + .await + .unwrap() + .get(0) + .unwrap() + .relationship_type, + RelationshipType::Friends + ); + user.remove_relationship(other_user.object.id.to_string().as_str()) + .await; + assert_eq!( + other_user.get_relationships().await.unwrap(), + Vec::::new() + ); common::teardown(bundle).await } From 06b4f5fb657a08838e3648a3940f12dc9fc5f5a9 Mon Sep 17 00:00:00 2001 From: Flori Weber Date: Mon, 19 Jun 2023 18:12:01 +0200 Subject: [PATCH 3/5] Add Eq, PartialEq derives --- src/types/entities/relationship.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/types/entities/relationship.rs b/src/types/entities/relationship.rs index b965907..a6abc09 100644 --- a/src/types/entities/relationship.rs +++ b/src/types/entities/relationship.rs @@ -6,7 +6,7 @@ use crate::types::Snowflake; use super::PublicUser; -#[derive(Debug, Deserialize, Serialize, Clone, Default)] +#[derive(Debug, Deserialize, Serialize, Clone, Default, PartialEq, Eq)] /// See https://discord-userdoccers.vercel.app/resources/user#relationship-structure pub struct Relationship { pub id: Snowflake, @@ -17,7 +17,7 @@ pub struct Relationship { pub since: Option>, } -#[derive(Serialize_repr, Deserialize_repr, Debug, Clone, Default)] +#[derive(Serialize_repr, Deserialize_repr, Debug, Clone, Default, Eq, PartialEq)] #[repr(u8)] /// See https://discord-userdoccers.vercel.app/resources/user#relationship-type pub enum RelationshipType { From 17223d338aa403a169112fb791897c5248060df6 Mon Sep 17 00:00:00 2001 From: Flori Weber Date: Mon, 19 Jun 2023 18:12:09 +0200 Subject: [PATCH 4/5] change post to delete --- src/api/users/relationships.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/users/relationships.rs b/src/api/users/relationships.rs index 0a09e2d..fae5725 100644 --- a/src/api/users/relationships.rs +++ b/src/api/users/relationships.rs @@ -143,7 +143,7 @@ impl UserMeta { self.belongs_to.borrow().urls.get_api(), user_id ); - let request = Client::new().post(url).bearer_auth(self.token()); + let request = Client::new().delete(url).bearer_auth(self.token()); handle_request_as_option(request, self, crate::api::limits::LimitType::Global).await } } From f7ea86917fae12de14ebae935e35b2f2989b0579 Mon Sep 17 00:00:00 2001 From: Flori Weber Date: Mon, 19 Jun 2023 18:46:49 +0200 Subject: [PATCH 5/5] Add block and unblock test --- tests/relationships.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/relationships.rs b/tests/relationships.rs index bdb5e68..474b015 100644 --- a/tests/relationships.rs +++ b/tests/relationships.rs @@ -105,3 +105,40 @@ async fn test_modify_relationship_friends() { ); common::teardown(bundle).await } + +#[tokio::test] +async fn test_modify_relationship_block() { + let register_schema = RegisterSchemaOptions { + date_of_birth: Some("2000-01-01".to_string()), + ..RegisterSchema::builder("integrationtestuser2", true) + } + .build() + .unwrap(); + + let mut bundle = common::setup().await; + let belongs_to = &mut bundle.instance; + let user = &mut bundle.user; + let mut other_user = belongs_to.register_account(®ister_schema).await.unwrap(); + other_user + .modify_user_relationship( + &user.object.id.to_string(), + types::RelationshipType::Blocked, + ) + .await; + let relationships = user.get_relationships().await.unwrap(); + assert_eq!(relationships, Vec::::new()); + let relationships = other_user.get_relationships().await.unwrap(); + assert_eq!(relationships.get(0).unwrap().id, user.object.id); + assert_eq!( + relationships.get(0).unwrap().relationship_type, + RelationshipType::Blocked + ); + other_user + .remove_relationship(user.object.id.to_string().as_str()) + .await; + assert_eq!( + other_user.get_relationships().await.unwrap(), + Vec::::new() + ); + common::teardown(bundle).await +}