fix: use params directly for api that requires too many args
This commit is contained in:
parent
63bee6f545
commit
48b912d6cc
|
|
@ -37,25 +37,13 @@ fn template_creator_resource_url(base_url: &str, creator_id: Uuid) -> String {
|
||||||
impl Client {
|
impl Client {
|
||||||
pub async fn create_template_category(
|
pub async fn create_template_category(
|
||||||
&self,
|
&self,
|
||||||
name: &str,
|
params: &CreateTemplateCategoryParams,
|
||||||
icon: &str,
|
|
||||||
bg_color: &str,
|
|
||||||
description: &str,
|
|
||||||
category_type: TemplateCategoryType,
|
|
||||||
priority: i32,
|
|
||||||
) -> Result<TemplateCategory, AppResponseError> {
|
) -> Result<TemplateCategory, AppResponseError> {
|
||||||
let url = category_resources_url(&self.base_url);
|
let url = category_resources_url(&self.base_url);
|
||||||
let resp = self
|
let resp = self
|
||||||
.http_client_with_auth(Method::POST, &url)
|
.http_client_with_auth(Method::POST, &url)
|
||||||
.await?
|
.await?
|
||||||
.json(&CreateTemplateCategoryParams {
|
.json(params)
|
||||||
name: name.to_string(),
|
|
||||||
icon: icon.to_string(),
|
|
||||||
bg_color: bg_color.to_string(),
|
|
||||||
description: description.to_string(),
|
|
||||||
priority,
|
|
||||||
category_type,
|
|
||||||
})
|
|
||||||
.send()
|
.send()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
|
@ -109,29 +97,16 @@ impl Client {
|
||||||
AppResponse::<()>::from_response(resp).await?.into_error()
|
AppResponse::<()>::from_response(resp).await?.into_error()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
|
||||||
pub async fn update_template_category(
|
pub async fn update_template_category(
|
||||||
&self,
|
&self,
|
||||||
category_id: Uuid,
|
category_id: Uuid,
|
||||||
name: &str,
|
params: &UpdateTemplateCategoryParams,
|
||||||
icon: &str,
|
|
||||||
bg_color: &str,
|
|
||||||
description: &str,
|
|
||||||
category_type: TemplateCategoryType,
|
|
||||||
priority: i32,
|
|
||||||
) -> Result<TemplateCategory, AppResponseError> {
|
) -> Result<TemplateCategory, AppResponseError> {
|
||||||
let url = category_resource_url(&self.base_url, category_id);
|
let url = category_resource_url(&self.base_url, category_id);
|
||||||
let resp = self
|
let resp = self
|
||||||
.http_client_with_auth(Method::PUT, &url)
|
.http_client_with_auth(Method::PUT, &url)
|
||||||
.await?
|
.await?
|
||||||
.json(&UpdateTemplateCategoryParams {
|
.json(params)
|
||||||
name: name.to_string(),
|
|
||||||
icon: icon.to_string(),
|
|
||||||
bg_color: bg_color.to_string(),
|
|
||||||
description: description.to_string(),
|
|
||||||
category_type,
|
|
||||||
priority,
|
|
||||||
})
|
|
||||||
.send()
|
.send()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
use app_error::ErrorCode;
|
use app_error::ErrorCode;
|
||||||
use client_api::entity::{AccountLink, TemplateCategoryType};
|
use client_api::entity::{
|
||||||
|
AccountLink, CreateTemplateCategoryParams, TemplateCategoryType, UpdateTemplateCategoryParams,
|
||||||
|
};
|
||||||
use client_api_test::*;
|
use client_api_test::*;
|
||||||
use collab::core::collab::DataSource;
|
use collab::core::collab::DataSource;
|
||||||
use collab::core::origin::CollabOrigin;
|
use collab::core::origin::CollabOrigin;
|
||||||
|
|
@ -55,43 +57,44 @@ async fn get_document_collab_from_remote(
|
||||||
async fn test_template_category_crud() {
|
async fn test_template_category_crud() {
|
||||||
let (authorized_client, _) = generate_unique_registered_user_client().await;
|
let (authorized_client, _) = generate_unique_registered_user_client().await;
|
||||||
let category_name = Uuid::new_v4().to_string();
|
let category_name = Uuid::new_v4().to_string();
|
||||||
|
let params = CreateTemplateCategoryParams {
|
||||||
|
name: category_name.clone(),
|
||||||
|
icon: "icon".to_string(),
|
||||||
|
bg_color: "bg_color".to_string(),
|
||||||
|
description: "description".to_string(),
|
||||||
|
category_type: TemplateCategoryType::Feature,
|
||||||
|
priority: 1,
|
||||||
|
};
|
||||||
let new_template_category = authorized_client
|
let new_template_category = authorized_client
|
||||||
.create_template_category(
|
.create_template_category(¶ms)
|
||||||
category_name.as_str(),
|
|
||||||
"icon",
|
|
||||||
"bg_color",
|
|
||||||
"description",
|
|
||||||
TemplateCategoryType::Feature,
|
|
||||||
1,
|
|
||||||
)
|
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(new_template_category.name, category_name);
|
assert_eq!(new_template_category.name, category_name);
|
||||||
assert_eq!(new_template_category.icon, "icon");
|
assert_eq!(new_template_category.icon, params.icon);
|
||||||
assert_eq!(new_template_category.bg_color, "bg_color");
|
assert_eq!(new_template_category.bg_color, params.bg_color);
|
||||||
assert_eq!(new_template_category.description, "description");
|
assert_eq!(new_template_category.description, params.description);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
new_template_category.category_type,
|
new_template_category.category_type,
|
||||||
TemplateCategoryType::Feature
|
TemplateCategoryType::Feature
|
||||||
);
|
);
|
||||||
assert_eq!(new_template_category.priority, 1);
|
assert_eq!(new_template_category.priority, 1);
|
||||||
let updated_category_name = Uuid::new_v4().to_string();
|
let updated_category_name = Uuid::new_v4().to_string();
|
||||||
|
let params = UpdateTemplateCategoryParams {
|
||||||
|
name: updated_category_name.clone(),
|
||||||
|
icon: "new_icon".to_string(),
|
||||||
|
bg_color: "new_bg_color".to_string(),
|
||||||
|
description: "new_description".to_string(),
|
||||||
|
category_type: TemplateCategoryType::UseCase,
|
||||||
|
priority: 2,
|
||||||
|
};
|
||||||
let updated_template_category = authorized_client
|
let updated_template_category = authorized_client
|
||||||
.update_template_category(
|
.update_template_category(new_template_category.id, ¶ms)
|
||||||
new_template_category.id,
|
|
||||||
updated_category_name.as_str(),
|
|
||||||
"new_icon",
|
|
||||||
"new_bg_color",
|
|
||||||
"new_description",
|
|
||||||
TemplateCategoryType::UseCase,
|
|
||||||
2,
|
|
||||||
)
|
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(updated_template_category.name, updated_category_name);
|
assert_eq!(updated_template_category.name, updated_category_name);
|
||||||
assert_eq!(updated_template_category.icon, "new_icon");
|
assert_eq!(updated_template_category.icon, params.icon);
|
||||||
assert_eq!(updated_template_category.bg_color, "new_bg_color");
|
assert_eq!(updated_template_category.bg_color, params.bg_color);
|
||||||
assert_eq!(updated_template_category.description, "new_description");
|
assert_eq!(updated_template_category.description, params.description);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
updated_template_category.category_type,
|
updated_template_category.category_type,
|
||||||
TemplateCategoryType::UseCase
|
TemplateCategoryType::UseCase
|
||||||
|
|
@ -104,9 +107,9 @@ async fn test_template_category_crud() {
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(template_category.name, updated_category_name);
|
assert_eq!(template_category.name, updated_category_name);
|
||||||
assert_eq!(template_category.icon, "new_icon");
|
assert_eq!(template_category.icon, params.icon);
|
||||||
assert_eq!(template_category.bg_color, "new_bg_color");
|
assert_eq!(template_category.bg_color, params.bg_color);
|
||||||
assert_eq!(template_category.description, "new_description");
|
assert_eq!(template_category.description, params.description);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
template_category.category_type,
|
template_category.category_type,
|
||||||
TemplateCategoryType::UseCase
|
TemplateCategoryType::UseCase
|
||||||
|
|
@ -114,21 +117,20 @@ async fn test_template_category_crud() {
|
||||||
assert_eq!(template_category.priority, 2);
|
assert_eq!(template_category.priority, 2);
|
||||||
|
|
||||||
let second_category_name = Uuid::new_v4().to_string();
|
let second_category_name = Uuid::new_v4().to_string();
|
||||||
|
let params = CreateTemplateCategoryParams {
|
||||||
|
name: second_category_name.clone(),
|
||||||
|
icon: "second_icon".to_string(),
|
||||||
|
bg_color: "second_bg_color".to_string(),
|
||||||
|
description: "second_description".to_string(),
|
||||||
|
category_type: TemplateCategoryType::Feature,
|
||||||
|
priority: 3,
|
||||||
|
};
|
||||||
authorized_client
|
authorized_client
|
||||||
.create_template_category(
|
.create_template_category(¶ms)
|
||||||
second_category_name.as_str(),
|
|
||||||
"second_icon",
|
|
||||||
"second_bg_color",
|
|
||||||
"second_description",
|
|
||||||
TemplateCategoryType::Feature,
|
|
||||||
3,
|
|
||||||
)
|
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let guest_client = localhost_client();
|
let guest_client = localhost_client();
|
||||||
let result = guest_client
|
let result = guest_client.create_template_category(¶ms).await;
|
||||||
.create_template_category("", "", "", "", TemplateCategoryType::Feature, 0)
|
|
||||||
.await;
|
|
||||||
assert!(result.is_err());
|
assert!(result.is_err());
|
||||||
assert_eq!(result.unwrap_err().code, ErrorCode::NotLoggedIn);
|
assert_eq!(result.unwrap_err().code, ErrorCode::NotLoggedIn);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue