use serde::{Deserialize, Serialize};
use typed_builder::TypedBuilder;
#[derive(Debug, Eq, PartialEq, Clone, Serialize, Deserialize, TypedBuilder)]
#[serde(rename_all = "camelCase")]
#[serde(rename = "Criteria")]
pub struct Obj {
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(default=Some("Criteria".to_string()))]
#[builder(setter(strip_option))]
#[builder(setter(into))]
pub r#type: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(default)]
#[builder(setter(strip_option))]
#[builder(setter(into))]
pub id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(default)]
#[builder(setter(strip_option))]
#[builder(setter(into))]
pub narrative: Option<String>,
}
impl super::ToJsonLd for Obj {}
#[cfg(test)]
mod tests {
use super::*;
use crate::{constants, objects::ToJsonLd};
const EXP_JSON_LD_SIMPLE: &str = r#"{
"type": "Criteria",
"id": "https://raw.githubusercontent.com/hoijui/obadgen/master/res/ob-ents/criteria-1.json"
}"#;
const EXP_JSON_LD_ALL: &str = r#"{
"type": "Criteria",
"id": "https://raw.githubusercontent.com/hoijui/obadgen/master/res/ob-ents/criteria-2.json",
"narrative": "Much, much longer description."
}"#;
#[test]
fn test_builder_simple() -> Result<(), Box<dyn std::error::Error>> {
let obj = Obj::builder().id(constants::CRITERIA_1_ID).build();
let json_ld = obj.to_json_ld()?;
assert_eq!(&json_ld, EXP_JSON_LD_SIMPLE);
Ok(())
}
#[test]
fn test_builder_all() -> Result<(), Box<dyn std::error::Error>> {
let obj = Obj::builder()
.id(constants::CRITERIA_2_ID)
.narrative("Much, much longer description.")
.build();
let json_ld = obj.to_json_ld()?;
assert_eq!(&json_ld, EXP_JSON_LD_ALL);
Ok(())
}
}