questions: add sync convert test
This commit is contained in:
		@@ -157,6 +157,42 @@ pub mod convert {
 | 
			
		||||
            Box::new(iter)
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    #[cfg(test)]
 | 
			
		||||
    mod test {
 | 
			
		||||
        use crate::questions::test::convert_common::sample_batch;
 | 
			
		||||
 | 
			
		||||
        use super::*;
 | 
			
		||||
        use insta::assert_yaml_snapshot;
 | 
			
		||||
        use std::iter;
 | 
			
		||||
 | 
			
		||||
        #[test]
 | 
			
		||||
        fn test_convert() {
 | 
			
		||||
            let mut source = iter::once((
 | 
			
		||||
                String::from("test.json"),
 | 
			
		||||
                Ok::<SourceQuestionsBatch, serde_json::Error>(sample_batch()),
 | 
			
		||||
            ));
 | 
			
		||||
            let converted: Vec<_> = source.convert().collect();
 | 
			
		||||
            assert_yaml_snapshot!(converted, @r#"
 | 
			
		||||
            ---
 | 
			
		||||
            - id: Вопрос 1
 | 
			
		||||
              description: Сколько будет (2 * 2 * 2 + 2) * 2 * 2 + 2
 | 
			
		||||
              answer: "42"
 | 
			
		||||
              batch_info:
 | 
			
		||||
                filename: test.json
 | 
			
		||||
                description: Тестовый
 | 
			
		||||
                date: 00-000-2000
 | 
			
		||||
            - id: Вопрос 2
 | 
			
		||||
              description: Зимой и летом одним цветом
 | 
			
		||||
              answer: ёлка
 | 
			
		||||
              batch_info:
 | 
			
		||||
                filename: test.json
 | 
			
		||||
                description: Тестовый
 | 
			
		||||
                date: 00-000-2000
 | 
			
		||||
              
 | 
			
		||||
            "#);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
#[cfg(feature = "convert")]
 | 
			
		||||
pub use convert::QuestionsConverter;
 | 
			
		||||
@@ -222,6 +258,33 @@ mod test {
 | 
			
		||||
    use insta::assert_yaml_snapshot;
 | 
			
		||||
    use serde_json::json;
 | 
			
		||||
 | 
			
		||||
    #[cfg(any(feature = "convert", feature = "convert_async"))]
 | 
			
		||||
    pub mod convert_common {
 | 
			
		||||
        use crate::source::{SourceQuestion, SourceQuestionsBatch};
 | 
			
		||||
 | 
			
		||||
        pub fn sample_batch() -> SourceQuestionsBatch {
 | 
			
		||||
            SourceQuestionsBatch {
 | 
			
		||||
                description: "Тестовый".into(),
 | 
			
		||||
                date: "00-000-2000".into(),
 | 
			
		||||
                questions: vec![
 | 
			
		||||
                    SourceQuestion {
 | 
			
		||||
                        id: "Вопрос 1".into(),
 | 
			
		||||
                        description: "Сколько будет (2 * 2 * 2 + 2) * 2 * 2 + 2".into(),
 | 
			
		||||
                        answer: "42".into(),
 | 
			
		||||
                        ..Default::default()
 | 
			
		||||
                    },
 | 
			
		||||
                    SourceQuestion {
 | 
			
		||||
                        id: "Вопрос 2".into(),
 | 
			
		||||
                        description: "Зимой и летом одним цветом".into(),
 | 
			
		||||
                        answer: "ёлка".into(),
 | 
			
		||||
                        ..Default::default()
 | 
			
		||||
                    },
 | 
			
		||||
                ],
 | 
			
		||||
                ..Default::default()
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn sample_question() -> Question {
 | 
			
		||||
        Question {
 | 
			
		||||
            id: "Вопрос 1".into(),
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user