feat: multiple parents test

This commit is contained in:
Sebastian Pravda 2022-12-06 00:09:31 +01:00
parent 99d964cae4
commit b227155962
No known key found for this signature in database
GPG key ID: F3BC84F08EFA3F57

View file

@ -54,7 +54,43 @@ impl ParentService {
#[cfg(test)]
mod tests {
use crate::{utils::db::get_memory_sqlite_connection, models::{candidate::{ParentDetails, ApplicationDetails}, candidate_details::{tests::APPLICATION_DETAILS, EncryptedParentDetails, EncryptedApplicationDetails}}, services::{candidate_service::CandidateService, application_service::ApplicationService}};
use std::sync::Mutex;
use once_cell::sync::Lazy;
use crate::{utils::db::get_memory_sqlite_connection, models::{candidate::{ParentDetails, ApplicationDetails, CandidateDetails}, candidate_details::{tests::APPLICATION_DETAILS, EncryptedParentDetails, EncryptedApplicationDetails}}, services::{candidate_service::CandidateService, application_service::ApplicationService}, crypto};
use super::ParentService;
pub static APPLICATION_DETAILS_TWO_PARENTS: Lazy<Mutex<ApplicationDetails>> = Lazy::new(||
Mutex::new(ApplicationDetails {
candidate: CandidateDetails {
name: "name".to_string(),
surname: "surname".to_string(),
birthplace: "birthplace".to_string(),
birthdate: chrono::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(),
personal_id_number: "personal_id_number".to_string(),
study: "study".to_string(),
},
parents: vec![ParentDetails {
name: "parent_name".to_string(),
surname: "parent_surname".to_string(),
telephone: "parent_telephone".to_string(),
email: "parent_email".to_string(),
},
ParentDetails {
name: "parent_name2".to_string(),
surname: "parent_surname2".to_string(),
telephone: "parent_telephone2".to_string(),
email: "parent_email2".to_string(),
}],
})
);
#[tokio::test]
async fn create_parent_test() {
@ -63,4 +99,57 @@ mod tests {
super::ParentService::create(&db, 103100).await.unwrap();
super::ParentService::create(&db, 103100).await.unwrap();
}
#[tokio::test]
async fn add_parent_details_test() {
let db = get_memory_sqlite_connection().await;
let plain_text_password = "test".to_string();
let (candidate, _parent) = ApplicationService::create_candidate_with_parent(
&db,
103101,
&plain_text_password,
"".to_string(),
)
.await
.ok()
.unwrap();
ParentService::create(&db, 103101).await.unwrap();
let form = APPLICATION_DETAILS_TWO_PARENTS.lock().unwrap().clone();
let (candidate, parents) = ApplicationService::add_all_details(&db, candidate.clone(), &form)
.await
.unwrap();
let priv_key = crypto::decrypt_password(candidate.private_key.clone(), plain_text_password).await.unwrap();
let dec_details = EncryptedApplicationDetails::try_from((candidate, parents))
.unwrap()
.decrypt(priv_key)
.await
.unwrap();
assert_eq!(dec_details.candidate.name, form.candidate.name);
assert_eq!(dec_details.candidate.surname, form.candidate.surname);
assert_eq!(dec_details.candidate.birthplace, form.candidate.birthplace);
assert_eq!(dec_details.candidate.birthdate, form.candidate.birthdate);
assert_eq!(dec_details.candidate.address, form.candidate.address);
assert_eq!(dec_details.candidate.telephone, form.candidate.telephone);
assert_eq!(dec_details.candidate.citizenship, form.candidate.citizenship);
assert_eq!(dec_details.candidate.email, form.candidate.email);
assert_eq!(dec_details.candidate.sex, form.candidate.sex);
assert_eq!(dec_details.candidate.personal_id_number, form.candidate.personal_id_number);
assert_eq!(dec_details.candidate.study, form.candidate.study);
assert_eq!(dec_details.parents.len(), form.parents.len());
for i in 0..dec_details.parents.len() {
assert_eq!(dec_details.parents[i].name, form.parents[i].name);
assert_eq!(dec_details.parents[i].surname, form.parents[i].surname);
assert_eq!(dec_details.parents[i].telephone, form.parents[i].telephone);
assert_eq!(dec_details.parents[i].email, form.parents[i].email);
}
}
}