Add comprehensive tests for mentor repository and authentication

- Implemented tests for creating, retrieving, updating, and deleting mentors in `mentor_repository_test.rs`.
- Added tests for user authentication, including successful login, invalid email formats, and inactive users in `auth_login_tests.rs`.
- Created a mock test environment setup in `mock_test.rs` to facilitate database operations during tests.
- Updated module structure to include new test files for mentors and authentication.
- Ensured cleanup of the database after tests to maintain isolation and prevent side effects.
This commit is contained in:
MythEclipse
2025-07-21 21:29:04 +07:00
parent e66f1f1634
commit 1a2e0c58b6
103 changed files with 7851 additions and 1509 deletions
+7 -1
View File
@@ -2,6 +2,7 @@ use imphnen_iam::UsersSchema;
use imphnen_libs::enviroment::load_env;
use imphnen_utils::{get_iso_date, hash_password, Env};
use std::error::Error;
use surrealdb::{opt::auth::Root, sql::Thing};
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
@@ -40,6 +41,10 @@ async fn main() -> Result<(), Box<dyn Error>> {
];
for (id, email, fullname, role_id) in users {
db.query("DELETE type::thing('app_users', $id)")
.bind(("id", id))
.await?;
let user = UsersSchema {
id: Thing::from(("app_users", id)),
fullname: fullname.into(),
@@ -49,6 +54,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
phone_number: "081234567890".into(),
is_active: true,
is_deleted: false,
mentor_id: None,
gender: None,
birthdate: None,
role: Thing::from(("app_roles", role_id)),
@@ -60,7 +66,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
.content(user)
.await?;
println!("✅ Inserted user: {} ({})", fullname, email);
println!("✅ Inserted user: {fullname} ({email})");
}
println!("✅ All Users seeded");