Refactor tests to enhance response validation and error handling
- Updated gacha claims service tests to parse and verify error JSON content for various scenarios. - Improved gacha credits controller tests by adding checks for success messages in JSON responses. - Enhanced gacha items service tests to validate response data structure and content. - Modified IAM auth controller and service tests to ensure token data integrity and presence of required fields. - Refined permissions controller and service tests to assert response data correctness. - Improved roles controller and service tests to validate response data and ensure non-empty fields. - Enhanced teams controller tests to verify sensitive data exposure and required fields in responses. - Updated users controller and service tests to ensure response data integrity and presence of required fields.
This commit is contained in:
@@ -116,7 +116,7 @@ impl<'a> RolesRepository<'a> {
|
||||
pub async fn query_create_role(
|
||||
&self,
|
||||
payload: RolesRequestCreateDto,
|
||||
) -> Result<String> {
|
||||
) -> Result<RolesDetailItemDto> {
|
||||
let now = Instant::now();
|
||||
let db = &self.state.surrealdb_ws;
|
||||
let role_id = Uuid::new_v4().to_string();
|
||||
@@ -134,7 +134,7 @@ impl<'a> RolesRepository<'a> {
|
||||
updated_at: Some(crate::get_iso_date()),
|
||||
};
|
||||
let _: Option<RolesSchema> = db
|
||||
.create((&ResourceEnum::Roles.to_string(), role_id))
|
||||
.create((&ResourceEnum::Roles.to_string(), role_id.clone()))
|
||||
.content(role)
|
||||
.await?;
|
||||
let elapsed = now.elapsed();
|
||||
@@ -143,7 +143,8 @@ impl<'a> RolesRepository<'a> {
|
||||
{
|
||||
println!("Query 'query_create_role' took: {elapsed:.2?}");
|
||||
}
|
||||
Ok("Role with permissions created successfully".into())
|
||||
// After successful creation, fetch the created role
|
||||
self.query_role_by_id(role_id).await
|
||||
}
|
||||
|
||||
#[instrument(skip(self, id, data), err)]
|
||||
|
||||
@@ -3,6 +3,7 @@ use crate::{
|
||||
AppState, MetaRequestDto, ResponseListSuccessDto, ResponseSuccessDto,
|
||||
common_response, success_list_response, success_response, validate_request,
|
||||
};
|
||||
use imphnen_utils::success_created_response;
|
||||
use axum::{http::StatusCode, response::Response};
|
||||
|
||||
pub struct RolesService;
|
||||
@@ -48,7 +49,7 @@ impl RolesService {
|
||||
}
|
||||
}
|
||||
match repo.query_create_role(payload).await {
|
||||
Ok(msg) => common_response(StatusCode::CREATED, &msg),
|
||||
Ok(created_role) => success_created_response(ResponseSuccessDto { data: created_role }),
|
||||
Err(e) => common_response(StatusCode::INTERNAL_SERVER_ERROR, &e.to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -247,7 +247,7 @@ impl UsersSchema {
|
||||
password,
|
||||
phone_number: user.phone_number,
|
||||
phone_for_verification: None,
|
||||
is_active: false,
|
||||
is_active: user.is_active,
|
||||
mentor_id: None, // Regular users should not have a mentor_id by default
|
||||
gender: None,
|
||||
birthdate: None,
|
||||
|
||||
@@ -5,11 +5,10 @@ use super::{
|
||||
use imphnen_entities::UsersDetailQueryDto;
|
||||
use crate::{
|
||||
AppState, MetaRequestDto, ResponseListSuccessDto, UsersRepository, UsersSchema,
|
||||
};
|
||||
use crate::{
|
||||
ResponseSuccessDto, common_response, success_list_response,
|
||||
success_response, validate_request,
|
||||
};
|
||||
use imphnen_utils::success_created_response;
|
||||
use axum::{http::StatusCode, response::Response, extract::Multipart};
|
||||
use imphnen_libs::{ResourceEnum, hash_password, verify_password, MinioConfig, FileType, decode_base64_file, extract_content_type_from_data_url, create_minio_service_from_config};
|
||||
use imphnen_utils::make_thing_from_enum;
|
||||
@@ -130,8 +129,16 @@ pub trait UsersServiceTrait: Send + Sync + 'static {
|
||||
{
|
||||
return common_response(StatusCode::BAD_REQUEST, "User already exists");
|
||||
}
|
||||
match repo.query_create_user(UsersSchema::create(new_user)).await {
|
||||
Ok(msg) => common_response(StatusCode::CREATED, &msg),
|
||||
match repo.query_create_user(UsersSchema::create(new_user.clone())).await {
|
||||
Ok(_msg) => {
|
||||
// After successful creation, fetch the created user
|
||||
match repo.query_user_by_email(new_user.email).await {
|
||||
Ok(created_user) => success_created_response(ResponseSuccessDto {
|
||||
data: UserDto::from(&created_user),
|
||||
}),
|
||||
Err(e) => common_response(StatusCode::INTERNAL_SERVER_ERROR, &e.to_string()),
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
common_response(StatusCode::INTERNAL_SERVER_ERROR, &err.to_string())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user