diff --git a/lib/src/questions.rs b/lib/src/questions.rs index f009ba5..1071a9b 100644 --- a/lib/src/questions.rs +++ b/lib/src/questions.rs @@ -215,3 +215,62 @@ pub mod convert_async { } #[cfg(feature = "convert_async")] pub use convert_async::QuestionsConverterAsync; + +#[cfg(test)] +mod test { + use super::*; + use insta::assert_yaml_snapshot; + use serde_json::json; + + pub fn sample_question() -> Question { + Question { + id: "Вопрос 1".into(), + description: "Сколько будет (2 * 2 * 2 + 2) * 2 * 2 + 2".into(), + answer: "42".into(), + batch_info: BatchInfo { + description: "Тестовый".into(), + date: "00-000-2000".into(), + ..Default::default() + }, + ..Default::default() + } + } + + #[test] + fn test_question_ser() { + assert_yaml_snapshot!(sample_question(), @r#" + --- + id: Вопрос 1 + description: Сколько будет (2 * 2 * 2 + 2) * 2 * 2 + 2 + answer: "42" + batch_info: + description: Тестовый + date: 00-000-2000 + + "#); + } + #[test] + fn test_question_de() { + let question_from_json: Result = serde_json::from_value(json!({ + "id": "Вопрос 1", + "description": "Сколько будет (2 * 2 * 2 + 2) * 2 * 2 + 2", + "answer": "42", + "batch_info": { + "description": "Тестовый", + "date": "00-000-2000" + } + })); + assert!(question_from_json.is_ok()); + + assert_yaml_snapshot!(question_from_json.unwrap(), @r#" + --- + id: Вопрос 1 + description: Сколько будет (2 * 2 * 2 + 2) * 2 * 2 + 2 + answer: "42" + batch_info: + description: Тестовый + date: 00-000-2000 + + "#); + } +}