bo4e_core/enums/
contract_form.rs1use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
9#[cfg_attr(feature = "json-schema", derive(schemars::JsonSchema))]
10#[cfg_attr(feature = "json-schema", schemars(rename = "Vertragsform"))]
11#[non_exhaustive]
12pub enum ContractForm {
13 #[serde(rename = "ONLINE")]
15 Online,
16
17 #[serde(rename = "DIREKT")]
19 Direct,
20
21 #[serde(rename = "FAX")]
23 Fax,
24}
25
26impl ContractForm {
27 pub fn german_name(&self) -> &'static str {
29 match self {
30 Self::Online => "Online",
31 Self::Direct => "Direkt",
32 Self::Fax => "Auftragsfax",
33 }
34 }
35}
36
37#[cfg(test)]
38mod tests {
39 use super::*;
40
41 #[test]
42 fn test_serialize() {
43 assert_eq!(
44 serde_json::to_string(&ContractForm::Online).unwrap(),
45 r#""ONLINE""#
46 );
47 assert_eq!(
48 serde_json::to_string(&ContractForm::Direct).unwrap(),
49 r#""DIREKT""#
50 );
51 }
52
53 #[test]
54 fn test_deserialize() {
55 assert_eq!(
56 serde_json::from_str::<ContractForm>(r#""ONLINE""#).unwrap(),
57 ContractForm::Online
58 );
59 assert_eq!(
60 serde_json::from_str::<ContractForm>(r#""FAX""#).unwrap(),
61 ContractForm::Fax
62 );
63 }
64
65 #[test]
66 fn test_roundtrip() {
67 for form in [
68 ContractForm::Online,
69 ContractForm::Direct,
70 ContractForm::Fax,
71 ] {
72 let json = serde_json::to_string(&form).unwrap();
73 let parsed: ContractForm = serde_json::from_str(&json).unwrap();
74 assert_eq!(form, parsed);
75 }
76 }
77}