Refactor tests to improve response parsing and validation

- Introduced a new common module with response helper functions to streamline response parsing across tests.
- Updated role controller tests to assert success messages in responses for create, update, and delete operations.
- Enhanced role service tests to validate response structures and ensure proper error handling.
- Modified team controller and service tests to check for success messages and validate response data formats.
- Improved user controller and service tests to include success message assertions and error handling for invalid inputs.
- Ensured all tests utilize the new response parsing functions for consistency and maintainability.
This commit is contained in:
MythEclipse committed 2025-10-05 16:00:46 +07:00
1 parent a32f54873b
commit 9cecc8fa05
25 files changed
+893 -512

No files matched your search

+11 -8
View File
@@ -62,11 +62,14 @@ mod tests {
)
.await;
// Verify response
assert_eq!(response.status(), StatusCode::OK);
// Verify response
assert_eq!(response.status(), StatusCode::OK);
let login_response: ResponseSuccessDto = response.into_body().await.unwrap();
assert!(login_response.data.is_some());
let login_response: ResponseSuccessDto = crate::common::response_helpers::parse_response(response, 8192).await;
let data_val = login_response.data.expect("login should return data");
// Try to deserialize token structure
let token_obj: TokenDto = serde_json::from_value(data_val).expect("login data must be TokenDto");
assert!(!token_obj.access_token.is_empty(), "access_token must be present");
// Clean up
let user = repo.query_user_by_email(email.clone()).await.unwrap();
@@ -93,10 +96,10 @@ mod tests {
)
.await;
// Verify response
assert_eq!(response.status(), StatusCode::UNAUTHORIZED);
// Verify response
assert_eq!(response.status(), StatusCode::UNAUTHORIZED);
let error_response: MessageResponseDto = response.into_body().await.unwrap();
assert!(error_response.message.contains("Email or password not correct"));
let error_response: MessageResponseDto = crate::common::response_helpers::parse_response(response, 8192).await;
assert!(error_response.message.to_lowercase().contains("email or password") || error_response.message.to_lowercase().contains("not correct") || error_response.message.to_lowercase().contains("invalid credentials"));
}
}