• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pulibrary / bibdata / da4a9cd5-78f1-4afd-b9b1-022bf0107b90

18 Aug 2025 04:00PM UTC coverage: 92.367% (-0.2%) from 92.556%
da4a9cd5-78f1-4afd-b9b1-022bf0107b90

Pull #2859

circleci

christinach
Move config.tonl in .cargo to be consistent with the hierarchical structure
see https://doc.rust-lang.org/cargo/reference/config.html#hierarchical-structure

Co-authored-by: Jane Sandberg <sandbergja@users.noreply.github.com>
Pull Request #2859: Support format id structure

41 of 57 new or added lines in 6 files covered. (71.93%)

7 existing lines in 2 files now uncovered.

7019 of 7599 relevant lines covered (92.37%)

425.52 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.31
/lib/bibdata_rs/src/ephemera/ephemera_folder/format.rs
1
use crate::solr;
2
use serde::Deserialize;
3

4
use serde::de::Deserializer;
5
use serde::Serialize;
6

7
#[derive(Copy, Clone, Debug, Serialize, PartialEq)]
8
pub struct Format {
9
    pub pref_label: Option<solr::FormatFacet>,
10
}
11

12
impl<'de> Deserialize<'de> for Format {
13
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
41✔
14
    where
41✔
15
        D: Deserializer<'de>,
41✔
16
    {
17
        #[derive(Deserialize)]
18
        struct FormatNestedId {
19
            #[serde(rename = "exact_match")]
20
            exact_match: Option<serde_json::Value>,
21
        }
22

23
        let format_nested = FormatNestedId::deserialize(deserializer)?;
41✔
24
        let facet = format_nested
41✔
25
            .exact_match
41✔
26
            .as_ref()
41✔
27
            .and_then(|em| em.get("@id"))
41✔
28
            .map(|id_val| {
41✔
29
                Some(if id_val.is_string() {
41✔
30
                    solr::FormatFacet::Book
1✔
31
                } else if id_val.is_object() {
40✔
32
                    solr::FormatFacet::Book
40✔
33
                } else {
34
                    // If @id is neither string nor object, return None
NEW
35
                    return None;
×
36
                })
37
            });
41✔
38

39
        Ok(Format {
41✔
40
            pref_label: facet.flatten(),
41✔
41
        })
41✔
42
    }
41✔
43
}
44

45
#[cfg(test)]
46
mod tests {
47
    use super::*;
48

49
    #[test]
50
    fn it_can_parse_format_from_the_json_ld() {
1✔
51
        let json_ld = r#"[
1✔
52
            {
1✔
53
              "@id": "https://figgy-staging.princeton.edu/catalog/5dbeae15-f46a-4411-a385-ce6df02231dc",
1✔
54
              "@type": "skos:Concept",
1✔
55
              "pref_label": "Pamphlets",
1✔
56
              "in_scheme": {
1✔
57
                "@id": "https://figgy.princeton.edu/ns/ephemeraGenres",
1✔
58
                "@type": "skos:ConceptScheme",
1✔
59
                "pref_label": "Ephemera Genres"
1✔
60
              },
1✔
61
              "exact_match": {
1✔
62
                "@id": {
1✔
63
                  "@id": "http://id.loc.gov/vocabulary/graphicMaterials/tgm001221"
1✔
64
                }
1✔
65
              }
1✔
66
            }
1✔
67
          ]"#;
1✔
68
        let formats: Vec<Format> = serde_json::from_str(json_ld).unwrap();
1✔
69
        assert_eq!(formats[0].pref_label, Some(solr::FormatFacet::Book));
1✔
70
    }
1✔
71

72
    #[test]
73
    fn it_can_parse_format_from_the_json_ld_when_exact_match_has_one_id() {
1✔
74
        let json_ld = r#"[
1✔
75
            {
1✔
76
              "@id": "https://figgy-staging.princeton.edu/catalog/5dbeae15-f46a-4411-a385-ce6df02231dc",
1✔
77
              "@type": "skos:Concept",
1✔
78
              "pref_label": "Pamphlets",
1✔
79
              "in_scheme": {
1✔
80
                "@id": "https://figgy.princeton.edu/ns/ephemeraGenres",
1✔
81
                "@type": "skos:ConceptScheme",
1✔
82
                "pref_label": "Ephemera Genres"
1✔
83
              },
1✔
84
              "exact_match": {
1✔
85
                  "@id": "http://id.loc.gov/vocabulary/graphicMaterials/tgm001221"
1✔
86
              }
1✔
87
            }
1✔
88
          ]"#;
1✔
89
        let formats: Vec<Format> = serde_json::from_str(json_ld).unwrap();
1✔
90
        assert_eq!(formats[0].pref_label, Some(solr::FormatFacet::Book));
1✔
91
    }
1✔
92
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc