- 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.
56 lines
1.9 KiB
Rust
56 lines
1.9 KiB
Rust
use imphnen_libs::enviroment::load_env;
|
|
use imphnen_utils::{get_iso_date, Env};
|
|
|
|
use std::error::Error;
|
|
use surrealdb::opt::auth::Root;
|
|
use surrealdb::sql::Thing;
|
|
|
|
#[tokio::main]
|
|
async fn main() -> Result<(), Box<dyn Error>> {
|
|
load_env();
|
|
let env = Env::new();
|
|
use surrealdb::engine::any;
|
|
let db = any::connect(&env.surrealdb_url).await?;
|
|
db.signin(Root {
|
|
username: &env.surrealdb_username,
|
|
password: &env.surrealdb_password,
|
|
})
|
|
.await?;
|
|
db.use_ns(env.surrealdb_namespace)
|
|
.use_db(env.surrealdb_dbname)
|
|
.await?;
|
|
|
|
db.query("DELETE type::thing('app_gacha_items', $id)")
|
|
.bind(("id", "gacha_item_test_id"))
|
|
.await?;
|
|
db.query("DELETE type::thing('app_gacha_rolls', $id)")
|
|
.bind(("id", "gacha_roll_test_id"))
|
|
.await?;
|
|
|
|
let gacha_item_id = "gacha_item_test_id";
|
|
db.query("CREATE type::thing('app_gacha_items', $id) SET name = $name, image_url = $image_url, is_deleted = $is_deleted, created_at = $created_at, updated_at = $updated_at")
|
|
.bind(("id", gacha_item_id))
|
|
.bind(("name", "Test Gacha Item"))
|
|
.bind(("image_url", "https://example.com/gacha_item.png"))
|
|
.bind(("is_deleted", false))
|
|
.bind(("created_at", get_iso_date()))
|
|
.bind(("updated_at", get_iso_date()))
|
|
.await?;
|
|
println!("Gacha Item seeded successfully!");
|
|
|
|
let gacha_roll_id = "gacha_roll_test_id";
|
|
db.query("CREATE type::thing('app_gacha_rolls', $id) SET item = $item, quantity = $quantity, weight = $weight, is_deleted = $is_deleted, created_at = $created_at, updated_at = $updated_at")
|
|
.bind(("id", gacha_roll_id))
|
|
.bind(("item", Thing::from(("app_gacha_items", gacha_item_id))))
|
|
.bind(("quantity", 10))
|
|
.bind(("weight", 1.0))
|
|
.bind(("is_deleted", false))
|
|
.bind(("created_at", get_iso_date()))
|
|
.bind(("updated_at", get_iso_date()))
|
|
.await?;
|
|
println!("Gacha Roll seeded successfully!");
|
|
|
|
println!("✅ Gacha items and rolls seeded.");
|
|
Ok(())
|
|
}
|