ferric_fred/
series_group.rs1use chrono::NaiveDate;
2use serde::{Deserialize, Serialize};
3
4use crate::SeriesGroupId;
5
6#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
15pub struct SeriesGroup {
16 pub title: String,
18
19 #[serde(rename = "series_group")]
21 pub id: SeriesGroupId,
22
23 pub region_type: String,
25
26 pub season: String,
28
29 pub units: String,
31
32 pub frequency: String,
34
35 pub min_date: NaiveDate,
37
38 pub max_date: NaiveDate,
40}
41
42#[cfg(test)]
43mod tests {
44 use super::*;
45
46 const SERIES_GROUP: &str = r#"{
47 "title": "All Employees: Total Private",
48 "region_type": "state",
49 "series_group": "1223",
50 "season": "NSA",
51 "units": "Thousands of Persons",
52 "frequency": "Monthly",
53 "min_date": "1990-01-01",
54 "max_date": "2026-05-01"
55 }"#;
56
57 #[test]
58 fn parses_group_metadata() {
59 let group: SeriesGroup = serde_json::from_str(SERIES_GROUP).expect("series group parses");
60 assert_eq!(group.id, SeriesGroupId::new("1223"));
61 assert_eq!(group.title, "All Employees: Total Private");
62 assert_eq!(group.region_type, "state");
63 assert_eq!(group.season, "NSA");
64 assert_eq!(group.min_date, NaiveDate::from_ymd_opt(1990, 1, 1).unwrap());
65 assert_eq!(group.max_date, NaiveDate::from_ymd_opt(2026, 5, 1).unwrap());
66 }
67}