From e0326e3b0a53e7672febd70b6b39bcef5e032415 Mon Sep 17 00:00:00 2001
From: Dmitry <b4tm4n@mail.ru>
Date: Sat, 12 Aug 2023 23:35:17 +0300
Subject: [PATCH] add questions ser/de tests

---
 lib/src/questions.rs | 59 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)

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<Question, _> = 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
+          
+        "#);
+    }
+}