Skip to main content

klirr_core/models/
invoiced_items.rs

1use crate::prelude::*;
2
3/// The items being invoiced this month, either services or expenses.
4#[derive(Clone, Debug, Display, Serialize, Deserialize, IsVariant, PartialEq)]
5pub enum InvoicedItems {
6    #[display("Service {{ time_off: {} }} ", time_off.map(|d| *d).unwrap_or(Quantity::ZERO))]
7    Service { time_off: Option<TimeOff> },
8    #[display("Expenses")]
9    Expenses,
10}
11impl MaybeIsExpenses for InvoicedItems {
12    fn is_expenses(&self) -> bool {
13        self.is_expenses()
14    }
15}
16
17impl Default for InvoicedItems {
18    fn default() -> Self {
19        Self::Service { time_off: None }
20    }
21}
22
23impl HasSample for InvoicedItems {
24    fn sample() -> Self {
25        Self::Service {
26            time_off: Some(TimeOff::sample()),
27        }
28    }
29    fn sample_other() -> Self {
30        Self::Expenses
31    }
32}
33
34#[cfg(test)]
35mod tests {
36    use super::*;
37    use test_log::test;
38
39    type Sut = InvoicedItems;
40
41    #[test]
42    fn equality() {
43        assert_eq!(Sut::sample(), Sut::sample());
44        assert_eq!(Sut::sample_other(), Sut::sample_other());
45    }
46
47    #[test]
48    fn inequality() {
49        assert_ne!(Sut::sample(), Sut::sample_other());
50    }
51
52    #[test]
53    fn is_expenses() {
54        assert!(MaybeIsExpenses::is_expenses(&Sut::Expenses));
55        assert!(!MaybeIsExpenses::is_expenses(&Sut::Service {
56            time_off: None
57        }));
58    }
59}