mirror of
https://github.com/danbulant/Portfolio
synced 2026-05-24 12:35:31 +00:00
feat: candidate details tests
This commit is contained in:
parent
139248dc4c
commit
7a8affb9b1
1 changed files with 66 additions and 26 deletions
|
|
@ -435,9 +435,9 @@ mod tests {
|
|||
|
||||
use super::EncryptedApplicationDetails;
|
||||
use chrono::NaiveDate;
|
||||
use entity::{candidate, parent};
|
||||
use entity::{candidate, parent, admin};
|
||||
|
||||
use crate::candidate_details::ApplicationDetails;
|
||||
use crate::candidate_details::{ApplicationDetails};
|
||||
use crate::services::application_service::ApplicationService;
|
||||
|
||||
use std::path::{PathBuf};
|
||||
|
|
@ -455,17 +455,19 @@ mod tests {
|
|||
assert!(!CandidateService::is_application_id_valid(101));
|
||||
}
|
||||
|
||||
// TODO
|
||||
/* #[tokio::test]
|
||||
#[tokio::test]
|
||||
async fn test_password_reset() {
|
||||
let db = get_memory_sqlite_connection().await;
|
||||
let admin = create_admin(&db).await;
|
||||
let (candidate, _parent) = put_user_data(&db).await;
|
||||
|
||||
let private_key = crypto::decrypt_password(admin.private_key, "admin".to_string()).await.unwrap();
|
||||
|
||||
assert!(
|
||||
CandidateService::login(&db, candidate.application, "test".to_string(), "127.0.0.1".to_string()).await.is_ok()
|
||||
);
|
||||
|
||||
let new_password = CandidateService::reset_password(&db, candidate.application).await.unwrap();
|
||||
let new_password = CandidateService::reset_password(private_key, &db, candidate.application).await.unwrap();
|
||||
|
||||
assert!(
|
||||
CandidateService::login(&db, candidate.application, "test".to_string(), "127.0.0.1".to_string()).await.is_err()
|
||||
|
|
@ -475,20 +477,21 @@ mod tests {
|
|||
CandidateService::login(&db, candidate.application, new_password, "127.0.0.1".to_string()).await.is_ok()
|
||||
);
|
||||
|
||||
} */
|
||||
}
|
||||
|
||||
// TODO
|
||||
/* #[tokio::test]
|
||||
#[tokio::test]
|
||||
async fn test_list_candidates() {
|
||||
let db = get_memory_sqlite_connection().await;
|
||||
let candidates = CandidateService::list_candidates(&db, None).await.unwrap();
|
||||
let admin = create_admin(&db).await;
|
||||
let private_key = crypto::decrypt_password(admin.private_key, "admin".to_string()).await.unwrap();
|
||||
let candidates = CandidateService::list_candidates(private_key.clone(), &db, None).await.unwrap();
|
||||
assert_eq!(candidates.len(), 0);
|
||||
|
||||
put_user_data(&db).await;
|
||||
|
||||
let candidates = CandidateService::list_candidates(&db, None).await.unwrap();
|
||||
let candidates = CandidateService::list_candidates(private_key.clone(), &db, None).await.unwrap();
|
||||
assert_eq!(candidates.len(), 1);
|
||||
} */
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_encrypt_decrypt_private_key_with_passphrase() {
|
||||
|
|
@ -523,6 +526,31 @@ mod tests {
|
|||
assert_eq!(secret_message, decrypted_message);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
async fn create_admin(db: &DbConn) -> admin::Model {
|
||||
use chrono::Utc;
|
||||
use sea_orm::{Set, ActiveModelTrait};
|
||||
|
||||
let password = "admin".to_string();
|
||||
let (pubkey, priv_key) = crypto::create_identity();
|
||||
let enc_priv_key = crypto::encrypt_password(priv_key, password).await.unwrap();
|
||||
|
||||
let admin = admin::ActiveModel {
|
||||
name: Set("admin".to_string()),
|
||||
public_key: Set(pubkey),
|
||||
private_key: Set(enc_priv_key),
|
||||
password: Set("admin".to_string()),
|
||||
created_at: Set(Utc::now().naive_utc()),
|
||||
updated_at: Set(Utc::now().naive_utc()),
|
||||
..Default::default()
|
||||
}
|
||||
.insert(db)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
admin
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
async fn put_user_data(db: &DbConn) -> (candidate::Model, parent::Model) {
|
||||
let plain_text_password = "test".to_string();
|
||||
|
|
@ -537,20 +565,20 @@ mod tests {
|
|||
.unwrap();
|
||||
|
||||
let form = ApplicationDetails {
|
||||
name: "test".to_string(),
|
||||
surname: "aaa".to_string(),
|
||||
birthplace: "b".to_string(),
|
||||
birthdate: NaiveDate::from_ymd(1999, 1, 1),
|
||||
address: "test".to_string(),
|
||||
telephone: "test".to_string(),
|
||||
citizenship: "test".to_string(),
|
||||
email: "test".to_string(),
|
||||
sex: "test".to_string(),
|
||||
name: "name".to_string(),
|
||||
surname: "surname".to_string(),
|
||||
birthplace: "birthplace".to_string(),
|
||||
birthdate: NaiveDate::from_ymd(2000, 1, 1),
|
||||
address: "address".to_string(),
|
||||
telephone: "telephone".to_string(),
|
||||
citizenship: "citizenship".to_string(),
|
||||
email: "email".to_string(),
|
||||
sex: "sex".to_string(),
|
||||
study: "KB".to_string(),
|
||||
parent_name: "test".to_string(),
|
||||
parent_surname: "test".to_string(),
|
||||
parent_telephone: "test".to_string(),
|
||||
parent_email: "test".to_string(),
|
||||
parent_name: "parent_name".to_string(),
|
||||
parent_surname: "parent_surname".to_string(),
|
||||
parent_telephone: "parent_telephone".to_string(),
|
||||
parent_email: "parent_email".to_string(),
|
||||
};
|
||||
|
||||
ApplicationService::add_all_details(&db, candidate.application, form)
|
||||
|
|
@ -580,8 +608,20 @@ mod tests {
|
|||
.unwrap();
|
||||
let dec_details = enc_details.decrypt(dec_priv_key).await.ok().unwrap();
|
||||
|
||||
assert_eq!(dec_details.name, "test"); // TODO: test every element
|
||||
assert_eq!(dec_details.parent_surname, "test");
|
||||
assert_eq!(dec_details.name, "name");
|
||||
assert_eq!(dec_details.surname, "surname");
|
||||
assert_eq!(dec_details.birthplace, "birthplace");
|
||||
assert_eq!(dec_details.birthdate, NaiveDate::from_ymd(2000, 1, 1));
|
||||
assert_eq!(dec_details.address, "address");
|
||||
assert_eq!(dec_details.telephone, "telephone");
|
||||
assert_eq!(dec_details.citizenship, "citizenship");
|
||||
assert_eq!(dec_details.email, "email");
|
||||
assert_eq!(dec_details.sex, "sex");
|
||||
assert_eq!(dec_details.study, "KB");
|
||||
assert_eq!(dec_details.parent_name, "parent_name");
|
||||
assert_eq!(dec_details.parent_surname, "parent_surname");
|
||||
assert_eq!(dec_details.parent_telephone, "parent_telephone");
|
||||
assert_eq!(dec_details.parent_email, "parent_email");
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
|||
Loading…
Reference in a new issue