mirror of
https://github.com/danbulant/Portfolio
synced 2026-05-27 05:51:56 +00:00
refactor: personal_id_number in ApplicationDetails
This commit is contained in:
parent
0a400e0b38
commit
6499c8ce96
5 changed files with 117 additions and 128 deletions
|
|
@ -359,6 +359,7 @@ mod tests {
|
||||||
\"citizenship\": \"Czech Republic\",
|
\"citizenship\": \"Czech Republic\",
|
||||||
\"email\": \"magor@magor.cz\",
|
\"email\": \"magor@magor.cz\",
|
||||||
\"sex\": \"MALE\",
|
\"sex\": \"MALE\",
|
||||||
|
\"personal_id_number\": \"0000000000\",
|
||||||
\"study\": \"KB\",
|
\"study\": \"KB\",
|
||||||
\"parent_name\": \"maminka\",
|
\"parent_name\": \"maminka\",
|
||||||
\"parent_surname\": \"chad\",
|
\"parent_surname\": \"chad\",
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,7 @@ pub struct EncryptedApplicationDetails {
|
||||||
pub citizenship: EncryptedString,
|
pub citizenship: EncryptedString,
|
||||||
pub email: EncryptedString,
|
pub email: EncryptedString,
|
||||||
pub sex: EncryptedString,
|
pub sex: EncryptedString,
|
||||||
|
pub personal_id_number: EncryptedString,
|
||||||
pub study: String,
|
pub study: String,
|
||||||
|
|
||||||
// Parent
|
// Parent
|
||||||
|
|
@ -96,6 +97,7 @@ impl EncryptedApplicationDetails {
|
||||||
EncryptedString::new(&form.citizenship, &recipients),
|
EncryptedString::new(&form.citizenship, &recipients),
|
||||||
EncryptedString::new(&form.email, &recipients),
|
EncryptedString::new(&form.email, &recipients),
|
||||||
EncryptedString::new(&form.sex, &recipients),
|
EncryptedString::new(&form.sex, &recipients),
|
||||||
|
EncryptedString::new(&form.personal_id_number, &recipients),
|
||||||
|
|
||||||
EncryptedString::new(&form.parent_name, &recipients),
|
EncryptedString::new(&form.parent_name, &recipients),
|
||||||
EncryptedString::new(&form.parent_surname, &recipients),
|
EncryptedString::new(&form.parent_surname, &recipients),
|
||||||
|
|
@ -113,12 +115,13 @@ impl EncryptedApplicationDetails {
|
||||||
citizenship: d.6,
|
citizenship: d.6,
|
||||||
email: d.7,
|
email: d.7,
|
||||||
sex: d.8,
|
sex: d.8,
|
||||||
|
personal_id_number: d.9,
|
||||||
study: form.study,
|
study: form.study,
|
||||||
|
|
||||||
parent_name: d.9,
|
parent_name: d.10,
|
||||||
parent_surname: d.10,
|
parent_surname: d.11,
|
||||||
parent_telephone: d.11,
|
parent_telephone: d.12,
|
||||||
parent_email: d.12,
|
parent_email: d.13,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -133,10 +136,11 @@ impl EncryptedApplicationDetails {
|
||||||
self.citizenship.decrypt(&priv_key), // 6
|
self.citizenship.decrypt(&priv_key), // 6
|
||||||
self.email.decrypt(&priv_key), // 7
|
self.email.decrypt(&priv_key), // 7
|
||||||
self.sex.decrypt(&priv_key), // 8
|
self.sex.decrypt(&priv_key), // 8
|
||||||
self.parent_name.decrypt(&priv_key),
|
self.personal_id_number.decrypt(&priv_key),// 9
|
||||||
self.parent_surname.decrypt(&priv_key),
|
self.parent_name.decrypt(&priv_key), // 10
|
||||||
self.parent_telephone.decrypt(&priv_key),
|
self.parent_surname.decrypt(&priv_key), // 11
|
||||||
self.parent_email.decrypt(&priv_key),
|
self.parent_telephone.decrypt(&priv_key), // 12
|
||||||
|
self.parent_email.decrypt(&priv_key), // 13
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(ApplicationDetails {
|
Ok(ApplicationDetails {
|
||||||
|
|
@ -149,12 +153,13 @@ impl EncryptedApplicationDetails {
|
||||||
citizenship: d.6,
|
citizenship: d.6,
|
||||||
email: d.7,
|
email: d.7,
|
||||||
sex: d.8,
|
sex: d.8,
|
||||||
|
personal_id_number: d.9,
|
||||||
study: self.study,
|
study: self.study,
|
||||||
|
|
||||||
parent_name: d.9,
|
parent_name: d.10,
|
||||||
parent_surname: d.10,
|
parent_surname: d.11,
|
||||||
parent_telephone: d.11,
|
parent_telephone: d.12,
|
||||||
parent_email: d.12,
|
parent_email: d.13,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -175,6 +180,7 @@ impl TryFrom<(candidate::Model, parent::Model)> for EncryptedApplicationDetails
|
||||||
citizenship: EncryptedString::try_from(candidate.citizenship)?,
|
citizenship: EncryptedString::try_from(candidate.citizenship)?,
|
||||||
email: EncryptedString::try_from(candidate.email)?,
|
email: EncryptedString::try_from(candidate.email)?,
|
||||||
sex: EncryptedString::try_from(candidate.sex)?,
|
sex: EncryptedString::try_from(candidate.sex)?,
|
||||||
|
personal_id_number: EncryptedString::try_from(candidate.personal_identification_number)?,
|
||||||
study: candidate.study.ok_or(ServiceError::CandidateDetailsNotSet)?,
|
study: candidate.study.ok_or(ServiceError::CandidateDetailsNotSet)?,
|
||||||
|
|
||||||
parent_name: EncryptedString::try_from(parent.name)?,
|
parent_name: EncryptedString::try_from(parent.name)?,
|
||||||
|
|
@ -201,6 +207,7 @@ impl TryFrom<CandidateWithParent> for EncryptedApplicationDetails {
|
||||||
citizenship: EncryptedString::try_from(cp.citizenship)?,
|
citizenship: EncryptedString::try_from(cp.citizenship)?,
|
||||||
email: EncryptedString::try_from(cp.email)?,
|
email: EncryptedString::try_from(cp.email)?,
|
||||||
sex: EncryptedString::try_from(cp.sex)?,
|
sex: EncryptedString::try_from(cp.sex)?,
|
||||||
|
personal_id_number: EncryptedString::try_from(cp.personal_identification_number)?,
|
||||||
study: cp.study.ok_or(ServiceError::CandidateDetailsNotSet)?,
|
study: cp.study.ok_or(ServiceError::CandidateDetailsNotSet)?,
|
||||||
|
|
||||||
parent_name: EncryptedString::try_from(cp.parent_name)?,
|
parent_name: EncryptedString::try_from(cp.parent_name)?,
|
||||||
|
|
@ -213,7 +220,7 @@ impl TryFrom<CandidateWithParent> for EncryptedApplicationDetails {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
|
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
|
||||||
pub struct ApplicationDetails {
|
pub struct ApplicationDetails {
|
||||||
// Candidate
|
// Candidate
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
|
@ -226,7 +233,7 @@ pub struct ApplicationDetails {
|
||||||
pub email: String,
|
pub email: String,
|
||||||
pub sex: String,
|
pub sex: String,
|
||||||
pub study: String,
|
pub study: String,
|
||||||
|
pub personal_id_number: String,
|
||||||
// Parent
|
// Parent
|
||||||
pub parent_name: String,
|
pub parent_name: String,
|
||||||
pub parent_surname: String,
|
pub parent_surname: String,
|
||||||
|
|
@ -235,33 +242,61 @@ pub struct ApplicationDetails {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
pub mod tests {
|
||||||
|
use std::sync::Mutex;
|
||||||
|
|
||||||
|
use chrono::NaiveDate;
|
||||||
|
use once_cell::sync::Lazy;
|
||||||
|
|
||||||
use crate::crypto;
|
use crate::crypto;
|
||||||
|
|
||||||
use super::{ApplicationDetails, EncryptedApplicationDetails, EncryptedString};
|
use super::{ApplicationDetails, EncryptedApplicationDetails, EncryptedString};
|
||||||
|
|
||||||
|
pub static APPLICATION_DETAILS: Lazy<Mutex<ApplicationDetails>> = Lazy::new(||
|
||||||
|
Mutex::new(ApplicationDetails {
|
||||||
|
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(),
|
||||||
|
parent_email: "parent_email".to_string(),
|
||||||
|
parent_name: "parent_name".to_string(),
|
||||||
|
parent_surname: "parent_surname".to_string(),
|
||||||
|
parent_telephone: "parent_telephone".to_string()
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
pub fn assert_all_application_details(details: &ApplicationDetails) {
|
||||||
|
assert_eq!(details.name, "name");
|
||||||
|
assert_eq!(details.surname, "surname");
|
||||||
|
assert_eq!(details.birthplace, "birthplace");
|
||||||
|
assert_eq!(details.birthdate, chrono::NaiveDate::from_ymd(2000, 1, 1));
|
||||||
|
assert_eq!(details.address, "address");
|
||||||
|
assert_eq!(details.telephone, "telephone");
|
||||||
|
assert_eq!(details.citizenship, "citizenship");
|
||||||
|
assert_eq!(details.email, "email");
|
||||||
|
assert_eq!(details.sex, "sex");
|
||||||
|
assert_eq!(details.study, "study");
|
||||||
|
assert_eq!(details.personal_id_number, "personal_id_number");
|
||||||
|
assert_eq!(details.parent_name, "parent_name");
|
||||||
|
assert_eq!(details.parent_surname, "parent_surname");
|
||||||
|
assert_eq!(details.parent_telephone, "parent_telephone");
|
||||||
|
assert_eq!(details.parent_email, "parent_email");
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_encrypted_application_details_new() {
|
async fn test_encrypted_application_details_new() {
|
||||||
const PUBLIC_KEY: &str = "age1u889gp407hsz309wn09kxx9anl6uns30m27lfwnctfyq9tq4qpus8tzmq5";
|
const PUBLIC_KEY: &str = "age1u889gp407hsz309wn09kxx9anl6uns30m27lfwnctfyq9tq4qpus8tzmq5";
|
||||||
const PRIVATE_KEY: &str =
|
const PRIVATE_KEY: &str =
|
||||||
"AGE-SECRET-KEY-14QG24502DMUUQDT2SPMX2YXPSES0X8UD6NT0PCTDAT6RH8V5Q3GQGSRXPS";
|
"AGE-SECRET-KEY-14QG24502DMUUQDT2SPMX2YXPSES0X8UD6NT0PCTDAT6RH8V5Q3GQGSRXPS";
|
||||||
let encrypted_details = EncryptedApplicationDetails::new(
|
let encrypted_details = EncryptedApplicationDetails::new(
|
||||||
ApplicationDetails {
|
APPLICATION_DETAILS.lock().unwrap().clone(),
|
||||||
name: "test".to_string(),
|
|
||||||
surname: "test".to_string(),
|
|
||||||
birthplace: "test".to_string(),
|
|
||||||
birthdate: chrono::offset::Local::now().date_naive(),
|
|
||||||
address: "test".to_string(),
|
|
||||||
telephone: "test".to_string(),
|
|
||||||
citizenship: "test".to_string(),
|
|
||||||
email: "test".to_string(),
|
|
||||||
parent_email: "test".to_string(),
|
|
||||||
parent_name: "test".to_string(),
|
|
||||||
parent_surname: "test".to_string(),
|
|
||||||
parent_telephone: "test".to_string(),
|
|
||||||
sex: "test".to_string(),
|
|
||||||
study: "test".to_string(),
|
|
||||||
},
|
|
||||||
vec![PUBLIC_KEY],
|
vec![PUBLIC_KEY],
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
|
@ -271,19 +306,19 @@ mod tests {
|
||||||
crypto::decrypt_password_with_private_key(&encrypted_details.name.0, PRIVATE_KEY)
|
crypto::decrypt_password_with_private_key(&encrypted_details.name.0, PRIVATE_KEY)
|
||||||
.await
|
.await
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
"test"
|
"name"
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
crypto::decrypt_password_with_private_key(&encrypted_details.email.0, PRIVATE_KEY)
|
crypto::decrypt_password_with_private_key(&encrypted_details.email.0, PRIVATE_KEY)
|
||||||
.await
|
.await
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
"test"
|
"email"
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
crypto::decrypt_password_with_private_key(&encrypted_details.sex.0, PRIVATE_KEY)
|
crypto::decrypt_password_with_private_key(&encrypted_details.sex.0, PRIVATE_KEY)
|
||||||
.await
|
.await
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
"test"
|
"sex"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -292,23 +327,9 @@ mod tests {
|
||||||
const PUBLIC_KEY: &str = "age1u889gp407hsz309wn09kxx9anl6uns30m27lfwnctfyq9tq4qpus8tzmq5";
|
const PUBLIC_KEY: &str = "age1u889gp407hsz309wn09kxx9anl6uns30m27lfwnctfyq9tq4qpus8tzmq5";
|
||||||
const PRIVATE_KEY: &str =
|
const PRIVATE_KEY: &str =
|
||||||
"AGE-SECRET-KEY-14QG24502DMUUQDT2SPMX2YXPSES0X8UD6NT0PCTDAT6RH8V5Q3GQGSRXPS";
|
"AGE-SECRET-KEY-14QG24502DMUUQDT2SPMX2YXPSES0X8UD6NT0PCTDAT6RH8V5Q3GQGSRXPS";
|
||||||
|
|
||||||
let encrypted_details = EncryptedApplicationDetails::new(
|
let encrypted_details = EncryptedApplicationDetails::new(
|
||||||
ApplicationDetails {
|
APPLICATION_DETAILS.lock().unwrap().clone(),
|
||||||
name: "test".to_string(),
|
|
||||||
surname: "test".to_string(),
|
|
||||||
birthplace: "test".to_string(),
|
|
||||||
birthdate: chrono::offset::Local::now().date_naive(),
|
|
||||||
address: "test".to_string(),
|
|
||||||
telephone: "test".to_string(),
|
|
||||||
citizenship: "test".to_string(),
|
|
||||||
email: "test".to_string(),
|
|
||||||
parent_email: "test".to_string(),
|
|
||||||
parent_name: "test".to_string(),
|
|
||||||
parent_surname: "test".to_string(),
|
|
||||||
parent_telephone: "test".to_string(),
|
|
||||||
sex: "test".to_string(),
|
|
||||||
study: "test".to_string(),
|
|
||||||
},
|
|
||||||
vec![PUBLIC_KEY],
|
vec![PUBLIC_KEY],
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
|
@ -319,11 +340,32 @@ mod tests {
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(application_details.name, "test");
|
assert_all_application_details(&application_details);
|
||||||
assert_eq!(application_details.email, "test");
|
|
||||||
assert_eq!(application_details.sex, "test");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
/* #[tokio::test]
|
||||||
|
async fn test_encrypted_application_details_from_candidate_parent() {
|
||||||
|
const PUBLIC_KEY: &str = "age1u889gp407hsz309wn09kxx9anl6uns30m27lfwnctfyq9tq4qpus8tzmq5";
|
||||||
|
const PRIVATE_KEY: &str =
|
||||||
|
"AGE-SECRET-KEY-14QG24502DMUUQDT2SPMX2YXPSES0X8UD6NT0PCTDAT6RH8V5Q3GQGSRXPS";
|
||||||
|
|
||||||
|
const birthdate: NaiveDate = chrono::offset::Local::now().date_naive();
|
||||||
|
let encrypted_details = EncryptedApplicationDetails::try_from(
|
||||||
|
,
|
||||||
|
vec![PUBLIC_KEY],
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let application_details = encrypted_details
|
||||||
|
.decrypt(PRIVATE_KEY.to_string())
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
assert_all_application_details(&application_details);
|
||||||
|
} */
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_encrypted_string_new() {
|
async fn test_encrypted_string_new() {
|
||||||
const PUBLIC_KEY: &str = "age1u889gp407hsz309wn09kxx9anl6uns30m27lfwnctfyq9tq4qpus8tzmq5";
|
const PUBLIC_KEY: &str = "age1u889gp407hsz309wn09kxx9anl6uns30m27lfwnctfyq9tq4qpus8tzmq5";
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,7 @@ impl Mutation {
|
||||||
user.citizenship = Set(Some(enc_details.citizenship.into()));
|
user.citizenship = Set(Some(enc_details.citizenship.into()));
|
||||||
user.email = Set(Some(enc_details.email.into()));
|
user.email = Set(Some(enc_details.email.into()));
|
||||||
user.sex = Set(Some(enc_details.sex.into()));
|
user.sex = Set(Some(enc_details.sex.into()));
|
||||||
|
user.personal_identification_number = Set(Some(enc_details.personal_id_number.into()));
|
||||||
user.study = Set(Some(enc_details.study.into()));
|
user.study = Set(Some(enc_details.study.into()));
|
||||||
|
|
||||||
user.updated_at = Set(chrono::offset::Local::now().naive_local());
|
user.updated_at = Set(chrono::offset::Local::now().naive_local());
|
||||||
|
|
@ -66,7 +67,8 @@ impl Mutation {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::candidate_details::{ApplicationDetails, EncryptedApplicationDetails};
|
use crate::candidate_details::tests::APPLICATION_DETAILS;
|
||||||
|
use crate::candidate_details::{EncryptedApplicationDetails};
|
||||||
use crate::util::get_memory_sqlite_connection;
|
use crate::util::get_memory_sqlite_connection;
|
||||||
use crate::{Mutation, Query};
|
use crate::{Mutation, Query};
|
||||||
|
|
||||||
|
|
@ -111,22 +113,7 @@ mod tests {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let encrypted_details: EncryptedApplicationDetails = EncryptedApplicationDetails::new(
|
let encrypted_details: EncryptedApplicationDetails = EncryptedApplicationDetails::new(
|
||||||
ApplicationDetails {
|
APPLICATION_DETAILS.lock().unwrap().clone(),
|
||||||
name: "test".to_string(),
|
|
||||||
surname: "test".to_string(),
|
|
||||||
birthplace: "test".to_string(),
|
|
||||||
birthdate: chrono::offset::Local::now().date_naive(),
|
|
||||||
address: "test".to_string(),
|
|
||||||
telephone: "test".to_string(),
|
|
||||||
citizenship: "test".to_string(),
|
|
||||||
email: "test".to_string(),
|
|
||||||
parent_email: "test".to_string(),
|
|
||||||
parent_name: "test".to_string(),
|
|
||||||
parent_surname: "test".to_string(),
|
|
||||||
parent_telephone: "test".to_string(),
|
|
||||||
sex: "test".to_string(),
|
|
||||||
study: "test".to_string(),
|
|
||||||
},
|
|
||||||
vec!["age1u889gp407hsz309wn09kxx9anl6uns30m27lfwnctfyq9tq4qpus8tzmq5"],
|
vec!["age1u889gp407hsz309wn09kxx9anl6uns30m27lfwnctfyq9tq4qpus8tzmq5"],
|
||||||
).await.unwrap();
|
).await.unwrap();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,8 @@ impl Mutation {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::candidate_details::{ApplicationDetails, EncryptedApplicationDetails};
|
use crate::candidate_details::tests::APPLICATION_DETAILS;
|
||||||
|
use crate::candidate_details::{EncryptedApplicationDetails};
|
||||||
use crate::util::get_memory_sqlite_connection;
|
use crate::util::get_memory_sqlite_connection;
|
||||||
use crate::{Mutation, Query};
|
use crate::{Mutation, Query};
|
||||||
|
|
||||||
|
|
@ -81,22 +82,7 @@ mod tests {
|
||||||
let parent = Mutation::create_parent(&db, APPLICATION_ID).await.unwrap();
|
let parent = Mutation::create_parent(&db, APPLICATION_ID).await.unwrap();
|
||||||
|
|
||||||
let encrypted_details: EncryptedApplicationDetails = EncryptedApplicationDetails::new(
|
let encrypted_details: EncryptedApplicationDetails = EncryptedApplicationDetails::new(
|
||||||
ApplicationDetails {
|
APPLICATION_DETAILS.lock().unwrap().clone(),
|
||||||
name: "test".to_string(),
|
|
||||||
surname: "test".to_string(),
|
|
||||||
birthplace: "test".to_string(),
|
|
||||||
birthdate: chrono::offset::Local::now().date_naive(),
|
|
||||||
address: "test".to_string(),
|
|
||||||
telephone: "test".to_string(),
|
|
||||||
citizenship: "test".to_string(),
|
|
||||||
email: "test".to_string(),
|
|
||||||
parent_email: "test".to_string(),
|
|
||||||
parent_name: "test".to_string(),
|
|
||||||
parent_surname: "test".to_string(),
|
|
||||||
parent_telephone: "test".to_string(),
|
|
||||||
sex: "test".to_string(),
|
|
||||||
study: "test".to_string(),
|
|
||||||
},
|
|
||||||
vec!["age1u889gp407hsz309wn09kxx9anl6uns30m27lfwnctfyq9tq4qpus8tzmq5"],
|
vec!["age1u889gp407hsz309wn09kxx9anl6uns30m27lfwnctfyq9tq4qpus8tzmq5"],
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
|
|
||||||
|
|
@ -247,14 +247,13 @@ impl CandidateService {
|
||||||
pub mod tests {
|
pub mod tests {
|
||||||
use sea_orm::{DbConn};
|
use sea_orm::{DbConn};
|
||||||
|
|
||||||
|
use crate::candidate_details::tests::assert_all_application_details;
|
||||||
use crate::util::get_memory_sqlite_connection;
|
use crate::util::get_memory_sqlite_connection;
|
||||||
use crate::{crypto, services::candidate_service::CandidateService, Mutation};
|
use crate::{crypto, services::candidate_service::CandidateService, Mutation};
|
||||||
|
|
||||||
use super::EncryptedApplicationDetails;
|
use super::EncryptedApplicationDetails;
|
||||||
use chrono::NaiveDate;
|
|
||||||
use entity::{candidate, parent, admin};
|
use entity::{candidate, parent, admin};
|
||||||
|
|
||||||
use crate::candidate_details::{ApplicationDetails};
|
|
||||||
use crate::services::application_service::ApplicationService;
|
use crate::services::application_service::ApplicationService;
|
||||||
|
|
||||||
const APPLICATION_ID: i32 = 103151;
|
const APPLICATION_ID: i32 = 103151;
|
||||||
|
|
@ -368,6 +367,8 @@ pub mod tests {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub async fn put_user_data(db: &DbConn) -> (candidate::Model, parent::Model) {
|
pub async fn put_user_data(db: &DbConn) -> (candidate::Model, parent::Model) {
|
||||||
|
use crate::candidate_details::tests::APPLICATION_DETAILS;
|
||||||
|
|
||||||
let plain_text_password = "test".to_string();
|
let plain_text_password = "test".to_string();
|
||||||
let (candidate, _parent) = ApplicationService::create_candidate_with_parent(
|
let (candidate, _parent) = ApplicationService::create_candidate_with_parent(
|
||||||
&db,
|
&db,
|
||||||
|
|
@ -379,22 +380,7 @@ pub mod tests {
|
||||||
.ok()
|
.ok()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let form = ApplicationDetails {
|
let form = APPLICATION_DETAILS.lock().unwrap().clone();
|
||||||
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: "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)
|
ApplicationService::add_all_details(&db, candidate.application, form)
|
||||||
.await
|
.await
|
||||||
|
|
@ -423,19 +409,6 @@ pub mod tests {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let dec_details = enc_details.decrypt(dec_priv_key).await.ok().unwrap();
|
let dec_details = enc_details.decrypt(dec_priv_key).await.ok().unwrap();
|
||||||
|
|
||||||
assert_eq!(dec_details.name, "name");
|
assert_all_application_details(&dec_details);
|
||||||
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");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue