Merge pull request #161 from EETagent/test_lang_choice

(backend) (frontend) Test lang choice
This commit is contained in:
Vojtěch Jungmann 2023-01-17 21:24:45 +01:00 committed by GitHub
commit 0a3ce57b09
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 45 additions and 14 deletions

View file

@ -318,7 +318,8 @@ mod tests {
\"personalIdNumber\": \"0101010000\",
\"schoolName\": \"29988383\",
\"healthInsurance\": \"000\",
\"grades\": []
\"grades\": [],
\"testLanguage\": \"CZ\"
},
\"parents\": [
{

View file

@ -54,6 +54,7 @@ impl Mutation {
candidate.school_name = Set(enc_candidate.school_name.map(|e| e.into()));
candidate.health_insurance = Set(enc_candidate.health_insurance.map(|e| e.into()));
candidate.grades_json = Set(enc_candidate.grades_json.map(|e| e.into()));
candidate.test_language = Set(enc_candidate.test_language.map(|s| s));
candidate.encrypted_by_id = Set(Some(encrypted_by_id));
candidate.updated_at = Set(chrono::offset::Local::now().naive_local());

View file

@ -73,6 +73,7 @@ pub struct CandidateDetails {
pub school_name: String,
pub health_insurance: String,
pub grades: GradeList,
pub test_language: String,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]

View file

@ -27,6 +27,7 @@ pub struct EncryptedCandidateDetails {
pub school_name: Option<EncryptedString>,
pub health_insurance: Option<EncryptedString>,
pub grades_json: Option<EncryptedString>,
pub test_language: Option<String>,
}
#[derive(Debug, Clone)]
@ -151,6 +152,7 @@ impl EncryptedCandidateDetails {
school_name: d.10,
health_insurance: d.11,
grades_json: d.12,
test_language: Some(form.test_language.to_owned()),
}
)
}
@ -186,6 +188,7 @@ impl EncryptedCandidateDetails {
school_name: d.10.unwrap_or_default(),
health_insurance: d.11.unwrap_or_default(),
grades: GradeList::from_opt_str(d.12).unwrap_or_default(),
test_language: self.test_language.to_owned().unwrap_or_default().to_string(),
}
)
}
@ -221,6 +224,7 @@ impl From<&candidate::Model> for EncryptedCandidateDetails {
school_name: EncryptedString::try_from(&candidate.school_name).ok(),
health_insurance: EncryptedString::try_from(&candidate.health_insurance).ok(),
grades_json: EncryptedString::try_from(&candidate.grades_json).ok(),
test_language: candidate.test_language.to_owned(),
}
}
}
@ -359,6 +363,7 @@ impl TryFrom<ApplicationRow> for EncryptedApplicationDetails {
school_name: EncryptedString::try_from(&cp.school_name).ok(),
health_insurance: EncryptedString::try_from(&cp.health_insurance).ok(),
grades_json: None, // TODO
test_language: None // TODO
},
parents: vec![EncryptedParentDetails {
name: EncryptedString::try_from(&cp.parent_name).ok(),
@ -413,6 +418,7 @@ pub mod tests {
school_name: "school_name".to_string(),
health_insurance: "health_insurance".to_string(),
grades: GradeList::from(vec![]),
test_language: "test_language".to_string(),
},
parents: vec![ParentDetails {
name: "parent_name".to_string(),

View file

@ -12,7 +12,6 @@ pub struct GradeList(Vec<Grade>);
impl GradeList {
pub fn from_opt_str(grades: Option<String>) -> Option<Self> {
println!("grades: {:?}", grades);
grades.map(
|grades| serde_json::from_str(&grades).unwrap() // TODO: handle error
)

View file

@ -72,6 +72,7 @@ mod tests {
school_name: "school_name".to_string(),
health_insurance: "health_insurance".to_string(),
grades: GradeList::from(vec![]),
test_language: "test_language".to_string(),
},
parents: vec![ParentDetails {
name: "parent_name".to_string(),
@ -128,6 +129,10 @@ mod tests {
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, "0000001111".to_string());
assert_eq!(dec_details.candidate.school_name, form.candidate.school_name);
assert_eq!(dec_details.candidate.health_insurance, form.candidate.health_insurance);
assert_eq!(dec_details.candidate.grades, form.candidate.grades);
assert_eq!(dec_details.candidate.test_language, form.candidate.test_language);
assert_eq!(dec_details.parents.len(), form.parents.len());
for i in 0..dec_details.parents.len() {

View file

@ -21,6 +21,7 @@ pub struct Model {
pub school_name: Option<String>,
pub health_insurance: Option<String>,
pub grades_json: Option<String>,
pub test_language: Option<String>,
pub encrypted_by_id: Option<i32>,
pub created_at: DateTime,
pub updated_at: DateTime,

View file

@ -16,6 +16,7 @@ export interface CandidateData {
schoolName: string;
healthInsurance: string;
grades: Array<GradeBackend>;
testLanguage: string;
};
parents: Array<{
name: string;
@ -75,7 +76,8 @@ export const candidateData = writable<CandidateData>({
personalIdNumber: '',
schoolName: '',
healthInsurance: '',
grades: []
grades: [],
testLanguage: ''
},
parents: []
});

View file

@ -20,7 +20,8 @@ export const load: PageServerLoad = async ({ fetch, params }) => {
personalIdNumber: '',
schoolName: '',
healthInsurance: '',
grades: []
grades: [],
testLanguage: ''
},
parents: []
};

View file

@ -60,7 +60,8 @@
personalIdNumber: '',
schoolName: '',
healthInsurance: '',
grades: []
grades: [],
testLanguage: '',
},
parents: [
{
@ -120,7 +121,8 @@
semester: yup.string().required()
})
.required()
).required()
).required(),
testLanguage: yup.string().required(),
}),
parents: yup.array().of(
yup.object().shape({
@ -623,14 +625,24 @@
se hlásíte.
</p>
<div class="flex w-full flex-col">
<span class="field">
<SelectField
error={$typedErrors['candidate']['citizenship']}
bind:value={$form.candidate.citizenship}
placeholder="Občanství"
options={['Česká republika', 'Slovenská republika', 'Ukrajina', 'Jiné']}
/>
</span>
<div class="field flex w-full">
<span class="w-[50%]">
<SelectField
error={$typedErrors['candidate']['citizenship']}
bind:value={$form.candidate.citizenship}
placeholder="Občanství"
options={['Česká republika', 'Slovenská republika', 'Ukrajina', 'Jiné']}
/>
</span>
<span class="w-[50%] ml-2">
<SelectField
error={$typedErrors['candidate']['testLanguage']}
bind:value={$form.candidate.testLanguage}
placeholder="Jazyk odborných testů"
options={['Čeština', 'Angličtina']}
/>
</span>
</div>
<div class="field flex flex-row">
<span>
{#if $form.candidate.citizenship === 'Česká republika' || !$form.candidate.citizenship}

View file

@ -32,6 +32,7 @@ impl MigrationTrait for Migration {
.col(ColumnDef::new(Candidate::SchoolName).string())
.col(ColumnDef::new(Candidate::HealthInsurance).string())
.col(ColumnDef::new(Candidate::GradesJson).string())
.col(ColumnDef::new(Candidate::TestLanguage).string())
.col(ColumnDef::new(Candidate::EncryptedById).integer())
.col(ColumnDef::new(Candidate::CreatedAt).date_time().not_null())
.col(ColumnDef::new(Candidate::UpdatedAt).date_time().not_null())
@ -65,6 +66,7 @@ pub enum Candidate {
SchoolName,
HealthInsurance,
GradesJson,
TestLanguage,
EncryptedById,
CreatedAt,
UpdatedAt,