Refactor delete() to take less boilerplate args

This commit is contained in:
bitfl0wer 2023-05-29 23:08:52 +02:00
parent 001dc9f80c
commit 808224d4fb
No known key found for this signature in database
GPG Key ID: 84BBB60DF895ABF2
2 changed files with 11 additions and 21 deletions

View File

@ -58,23 +58,22 @@ impl Channel {
/// # Returns
///
/// An `Option` that contains an `InstanceServerError` if an error occurred during the request, or `None` if the request was successful.
pub async fn delete(
self,
token: &str,
url_api: &str,
limits_user: &mut Limits,
limits_instance: &mut Limits,
) -> Option<InstanceServerError> {
pub async fn delete(self, user: &mut UserMeta) -> Option<InstanceServerError> {
let mut belongs_to = user.belongs_to.borrow_mut();
let request = Client::new()
.delete(format!("{}/channels/{}/", url_api, self.id.to_string()))
.bearer_auth(token);
.delete(format!(
"{}/channels/{}/",
belongs_to.urls.get_api(),
self.id.to_string()
))
.bearer_auth(user.token());
match LimitedRequester::new()
.await
.send_request(
request,
crate::api::limits::LimitType::Channel,
limits_instance,
limits_user,
&mut belongs_to.limits,
&mut user.limits,
)
.await
{

View File

@ -19,16 +19,7 @@ async fn get_channel() {
#[tokio::test]
async fn delete_channel() {
let mut bundle = common::setup().await;
let result = bundle
.channel
.clone()
.delete(
&bundle.user.token,
bundle.instance.urls.get_api(),
&mut bundle.user.limits,
&mut bundle.instance.limits,
)
.await;
let result = bundle.channel.clone().delete(&mut bundle.user).await;
assert!(result.is_none());
common::teardown(bundle).await
}