add questions ser/de tests
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
c061fef267
commit
e0326e3b0a
@ -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
|
||||
|
||||
"#);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user