bo4e_core/enums/
invoice_status.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 = "Rechnungsstatus"))]
11#[non_exhaustive]
12pub enum InvoiceStatus {
13 #[serde(rename = "UNGEPRUEFT")]
15 Unchecked,
16
17 #[serde(rename = "GEPRUEFT_OK")]
19 CheckedOk,
20
21 #[serde(rename = "GEPRUEFT_FEHLERHAFT")]
23 CheckedWithErrors,
24
25 #[serde(rename = "GEBUCHT")]
27 Booked,
28
29 #[serde(rename = "BEZAHLT")]
31 Paid,
32}
33
34impl InvoiceStatus {
35 pub fn german_name(&self) -> &'static str {
37 match self {
38 Self::Unchecked => "Ungeprueft",
39 Self::CheckedOk => "Geprueft OK",
40 Self::CheckedWithErrors => "Geprueft fehlerhaft",
41 Self::Booked => "Gebucht",
42 Self::Paid => "Bezahlt",
43 }
44 }
45}
46
47#[cfg(test)]
48mod tests {
49 use super::*;
50
51 #[test]
52 fn test_serialize() {
53 assert_eq!(
54 serde_json::to_string(&InvoiceStatus::Unchecked).unwrap(),
55 r#""UNGEPRUEFT""#
56 );
57 assert_eq!(
58 serde_json::to_string(&InvoiceStatus::Paid).unwrap(),
59 r#""BEZAHLT""#
60 );
61 }
62
63 #[test]
64 fn test_deserialize() {
65 assert_eq!(
66 serde_json::from_str::<InvoiceStatus>(r#""UNGEPRUEFT""#).unwrap(),
67 InvoiceStatus::Unchecked
68 );
69 assert_eq!(
70 serde_json::from_str::<InvoiceStatus>(r#""GEPRUEFT_OK""#).unwrap(),
71 InvoiceStatus::CheckedOk
72 );
73 }
74
75 #[test]
76 fn test_roundtrip() {
77 for status in [
78 InvoiceStatus::Unchecked,
79 InvoiceStatus::CheckedOk,
80 InvoiceStatus::CheckedWithErrors,
81 InvoiceStatus::Booked,
82 InvoiceStatus::Paid,
83 ] {
84 let json = serde_json::to_string(&status).unwrap();
85 let parsed: InvoiceStatus = serde_json::from_str(&json).unwrap();
86 assert_eq!(status, parsed);
87 }
88 }
89}