Refactor delete() to take less boilerplate args
This commit is contained in:
parent
3e4840d7a6
commit
ebeaf31343
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue