Refactor delete() to take less boilerplate args
This commit is contained in:
parent
3e4840d7a6
commit
ebeaf31343
|
@ -58,23 +58,22 @@ impl Channel {
|
||||||
/// # Returns
|
/// # Returns
|
||||||
///
|
///
|
||||||
/// An `Option` that contains an `InstanceServerError` if an error occurred during the request, or `None` if the request was successful.
|
/// An `Option` that contains an `InstanceServerError` if an error occurred during the request, or `None` if the request was successful.
|
||||||
pub async fn delete(
|
pub async fn delete(self, user: &mut UserMeta) -> Option<InstanceServerError> {
|
||||||
self,
|
let mut belongs_to = user.belongs_to.borrow_mut();
|
||||||
token: &str,
|
|
||||||
url_api: &str,
|
|
||||||
limits_user: &mut Limits,
|
|
||||||
limits_instance: &mut Limits,
|
|
||||||
) -> Option<InstanceServerError> {
|
|
||||||
let request = Client::new()
|
let request = Client::new()
|
||||||
.delete(format!("{}/channels/{}/", url_api, self.id.to_string()))
|
.delete(format!(
|
||||||
.bearer_auth(token);
|
"{}/channels/{}/",
|
||||||
|
belongs_to.urls.get_api(),
|
||||||
|
self.id.to_string()
|
||||||
|
))
|
||||||
|
.bearer_auth(user.token());
|
||||||
match LimitedRequester::new()
|
match LimitedRequester::new()
|
||||||
.await
|
.await
|
||||||
.send_request(
|
.send_request(
|
||||||
request,
|
request,
|
||||||
crate::api::limits::LimitType::Channel,
|
crate::api::limits::LimitType::Channel,
|
||||||
limits_instance,
|
&mut belongs_to.limits,
|
||||||
limits_user,
|
&mut user.limits,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
|
|
|
@ -19,16 +19,7 @@ async fn get_channel() {
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn delete_channel() {
|
async fn delete_channel() {
|
||||||
let mut bundle = common::setup().await;
|
let mut bundle = common::setup().await;
|
||||||
let result = bundle
|
let result = bundle.channel.clone().delete(&mut bundle.user).await;
|
||||||
.channel
|
|
||||||
.clone()
|
|
||||||
.delete(
|
|
||||||
&bundle.user.token,
|
|
||||||
bundle.instance.urls.get_api(),
|
|
||||||
&mut bundle.user.limits,
|
|
||||||
&mut bundle.instance.limits,
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
assert!(result.is_none());
|
assert!(result.is_none());
|
||||||
common::teardown(bundle).await
|
common::teardown(bundle).await
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue