- 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.
85 lines
1.8 KiB
Rust
85 lines
1.8 KiB
Rust
use imphnen_libs::ResourceEnum;
|
|
use imphnen_utils::{get_iso_date, make_thing};
|
|
use serde::{Deserialize, Serialize};
|
|
use surrealdb::Uuid;
|
|
use surrealdb::sql::Thing;
|
|
|
|
use super::testimonials_dto::{
|
|
TestimonialsCreateRequestDto, TestimonialsQueryDto, TestimonialsUpdateRequestDto,
|
|
};
|
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
|
pub struct TestimonialsSchema {
|
|
pub id: Thing,
|
|
pub user: Thing,
|
|
pub role: String,
|
|
pub content: String,
|
|
pub is_deleted: bool,
|
|
pub created_at: String,
|
|
pub updated_at: String,
|
|
}
|
|
|
|
impl Default for TestimonialsSchema {
|
|
fn default() -> Self {
|
|
Self {
|
|
id: make_thing(
|
|
&ResourceEnum::Testimonials.to_string(),
|
|
&Uuid::new_v4().to_string(),
|
|
),
|
|
user: make_thing(
|
|
&ResourceEnum::Users.to_string(),
|
|
&Uuid::new_v4().to_string(),
|
|
),
|
|
role: String::new(),
|
|
content: String::new(),
|
|
is_deleted: false,
|
|
created_at: get_iso_date(),
|
|
updated_at: get_iso_date(),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl TestimonialsSchema {
|
|
pub fn from(dto: TestimonialsQueryDto) -> Self {
|
|
Self {
|
|
id: dto.id,
|
|
user: dto.user.id,
|
|
role: dto.role,
|
|
content: dto.content,
|
|
is_deleted: dto.is_deleted,
|
|
created_at: dto.created_at,
|
|
updated_at: dto.updated_at,
|
|
}
|
|
}
|
|
|
|
pub fn create(payload: TestimonialsCreateRequestDto, user_id: &Thing) -> Self {
|
|
Self {
|
|
id: make_thing(
|
|
&ResourceEnum::Testimonials.to_string(),
|
|
&Uuid::new_v4().to_string(),
|
|
),
|
|
user: user_id.clone(),
|
|
role: payload.role,
|
|
content: payload.content,
|
|
is_deleted: false,
|
|
created_at: get_iso_date(),
|
|
updated_at: get_iso_date(),
|
|
}
|
|
}
|
|
|
|
pub fn update(
|
|
payload: TestimonialsUpdateRequestDto,
|
|
id: String,
|
|
user_id: &Thing,
|
|
) -> Self {
|
|
Self {
|
|
id: make_thing(&ResourceEnum::Testimonials.to_string(), &id),
|
|
role: payload.role,
|
|
content: payload.content,
|
|
updated_at: get_iso_date(),
|
|
user: user_id.clone(),
|
|
..Default::default()
|
|
}
|
|
}
|
|
}
|