konnektoren_core/challenges/custom/
custom_impl.rs1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, JsonSchema)]
5pub struct Custom {
6 pub id: String,
8 pub name: String,
10 pub description: String,
12 pub html: String,
14 pub results_html: Option<String>,
16 pub css: String,
18 pub js: String,
20 pub i18n: Option<String>,
22 pub data: serde_json::Value,
24 pub task_ids: Option<Vec<usize>>,
26 pub package_url: Option<String>,
28}
29
30impl Default for Custom {
31 fn default() -> Self {
32 let data = include_str!("../../../assets/custom_default.yml");
33 serde_yaml::from_str(data).unwrap()
34 }
35}
36
37#[cfg(test)]
38mod tests {
39 use super::*;
40
41 #[test]
42 fn new_dataset() {
43 let id = "123".to_string();
44 let name = "Test".to_string();
45 let data = serde_json::json!({
46 "key": "value"
47 });
48 let dataset = Custom {
49 id: id.clone(),
50 name: name.clone(),
51 description: "".to_string(),
52 html: "".to_string(),
53 results_html: None,
54 css: "".to_string(),
55 js: "".to_string(),
56 i18n: None,
57 data: data.clone(),
58 task_ids: None,
59 package_url: None,
60 };
61
62 assert_eq!(dataset.id, id);
63 assert_eq!(dataset.name, name);
64 assert_eq!(dataset.data, data);
65 }
66
67 #[test]
68 fn serialize_dataset() {
69 let json_str = r#"{"id":"123","name":"Test","description":"","html":"","results_html":null,"css":"","js":"","i18n":null,"data":{"key":"value"},"task_ids":null,"package_url":null}"#;
70 let dataset = Custom {
71 id: "123".to_string(),
72 name: "Test".to_string(),
73 description: "".to_string(),
74 html: "".to_string(),
75 results_html: None,
76 css: "".to_string(),
77 js: "".to_string(),
78 i18n: None,
79 data: serde_json::json!({
80 "key": "value"
81 }),
82 task_ids: None,
83 package_url: None,
84 };
85
86 let serialized = serde_json::to_string(&dataset).unwrap();
87 assert_eq!(serialized, json_str);
88 }
89}