From 03e5a83d84448ccd7ead166f5fbee81208d2713c Mon Sep 17 00:00:00 2001 From: bitfl0wer Date: Mon, 29 May 2023 23:51:12 +0200 Subject: [PATCH] Refactor delete() --- src/api/guilds/guilds.rs | 15 +++++---------- tests/common/mod.rs | 7 +------ tests/guild.rs | 8 +------- 3 files changed, 7 insertions(+), 23 deletions(-) diff --git a/src/api/guilds/guilds.rs b/src/api/guilds/guilds.rs index 02bf58d..aef5eb4 100644 --- a/src/api/guilds/guilds.rs +++ b/src/api/guilds/guilds.rs @@ -85,14 +85,9 @@ impl Guild { /// None => println!("Guild deleted successfully"), /// } /// ``` - pub async fn delete( - user: &mut UserMeta, - url_api: &str, - guild_id: &str, - ) -> Option { - let url = format!("{}/guilds/{}/delete/", url_api, guild_id); - let limits_user = user.limits.get_as_mut(); - let limits_instance = &mut user.belongs_to.borrow_mut().limits; + pub async fn delete(user: &mut UserMeta, guild_id: &str) -> Option { + let mut belongs_to = user.belongs_to.borrow_mut(); + let url = format!("{}/guilds/{}/delete/", belongs_to.urls.get_api(), guild_id); let request = reqwest::Client::new() .post(url.clone()) .bearer_auth(user.token.clone()); @@ -101,8 +96,8 @@ impl Guild { .send_request( request, crate::api::limits::LimitType::Guild, - limits_instance, - limits_user, + &mut belongs_to.limits, + &mut user.limits, ) .await; if result.is_err() { diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 2bb0883..f8991e3 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -88,11 +88,6 @@ pub async fn setup() -> TestBundle { // Teardown method to clean up after a test. pub async fn teardown(mut bundle: TestBundle) { - Guild::delete( - &mut bundle.user, - bundle.instance.urls.get_api(), - &bundle.guild.id.to_string(), - ) - .await; + Guild::delete(&mut bundle.user, &bundle.guild.id.to_string()).await; bundle.user.delete().await; } diff --git a/tests/guild.rs b/tests/guild.rs index 56cb51d..8bd0838 100644 --- a/tests/guild.rs +++ b/tests/guild.rs @@ -19,13 +19,7 @@ async fn guild_creation_deletion() { .await .unwrap(); - match Guild::delete( - &mut bundle.user, - bundle.urls.get_api(), - &guild.id.to_string(), - ) - .await - { + match Guild::delete(&mut bundle.user, &guild.id.to_string()).await { None => assert!(true), Some(_) => assert!(false), }