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

pulibrary / bibdata / 3165b919-56f4-4faa-baf4-b5a08621230c

18 Sep 2025 03:08PM UTC coverage: 90.866% (+0.2%) from 90.675%
3165b919-56f4-4faa-baf4-b5a08621230c

Pull #2927

circleci

Ryan Laddusaw
Add QA DSpace config
Pull Request #2927: Index theses from dspace 7+

1411 of 1519 new or added lines in 16 files covered. (92.89%)

41 existing lines in 7 files now uncovered.

8874 of 9766 relevant lines covered (90.87%)

338.18 hits per line

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

96.34
/lib/bibdata_rs/src/solr/dataspace_solr_mapping.rs
1
// This module is responsible for mapping Dataspace metadata to the catalog's solr schema
2

3
use super::SolrDocument;
4
use crate::theses::dataspace::document::DataspaceDocument;
5
use crate::theses::legacy_dataspace::document::DataspaceDocument as LegacyDataspaceDocument;
6

7
impl From<&DataspaceDocument> for SolrDocument {
8
    fn from(doc: &DataspaceDocument) -> Self {
25✔
9
        SolrDocument::builder()
25✔
10
            .with_id(match &doc.id {
25✔
11
                Some(id) => id,
4✔
12
                None => "",
21✔
13
            })
14
            .with_access_facet(doc.access_facet())
25✔
15
            .with_advanced_location_s(doc.advanced_location())
25✔
16
            .with_advisor_display_unwrap(doc.contributor_advisor.clone())
25✔
17
            .with_author_display_unwrap(doc.contributor_author.clone())
25✔
18
            .with_author_s_unwrap(doc.all_authors())
25✔
19
            .with_author_sort(match &doc.contributor_author {
25✔
20
                Some(authors) => authors.first().cloned().unwrap(),
1✔
21
                None => None,
24✔
22
            })
23
            .with_call_number_browse_s(doc.call_number())
25✔
24
            .with_call_number_display(doc.call_number())
25✔
25
            .with_certificate_display(doc.authorized_ceritificates())
25✔
26
            .with_contributor_display_unwrap(doc.contributor.clone())
25✔
27
            .with_department_display(doc.authorized_departments())
25✔
28
            .with_format(vec![super::FormatFacet::SeniorThesis])
25✔
29
            .with_holdings_1display(doc.physical_holding_string())
25✔
30
            .with_location(doc.location())
25✔
31
            .with_location_code_s(doc.location_code())
25✔
32
            .with_location_display(doc.location_display())
25✔
33
            .with_electronic_access_1display(doc.ark_hash())
25✔
34
            .with_electronic_portfolio_s(doc.online_portfolio_statements())
25✔
35
            .with_restrictions_note_display(doc.restrictions_note_display())
25✔
36
            .with_title_citation_display(match &doc.title {
25✔
37
                Some(titles) => titles.first().cloned().unwrap(),
1✔
38
                None => None,
24✔
39
            })
40
            .with_title_display(match &doc.title {
25✔
41
                Some(titles) => titles.first().cloned().unwrap(),
1✔
42
                None => None,
24✔
43
            })
44
            .with_title_sort(title_sort_as_option(doc.title.as_ref()))
25✔
45
            .with_title_t(doc.title_search_versions())
25✔
46
            .with_language_facet(doc.languages())
25✔
47
            .with_language_name_display(doc.languages())
25✔
48
            .with_class_year_s(doc.class_year().map(|year| vec![year]))
25✔
49
            .with_pub_date_start_sort(doc.class_year())
25✔
50
            .with_pub_date_end_sort(doc.class_year())
25✔
51
            .with_description_display_unwrap(doc.format_extent.clone())
25✔
52
            .with_summary_note_display_unwrap(doc.description_abstract.clone())
25✔
53
            .build()
25✔
54
    }
25✔
55
}
56

57
impl From<&LegacyDataspaceDocument> for SolrDocument {
58
    fn from(doc: &LegacyDataspaceDocument) -> Self {
27✔
59
        SolrDocument::builder()
27✔
60
            .with_id(match &doc.id {
27✔
61
                Some(id) => id,
6✔
62
                None => "",
21✔
63
            })
64
            .with_access_facet(doc.access_facet())
27✔
65
            .with_advanced_location_s(doc.advanced_location())
27✔
66
            .with_advisor_display(doc.contributor_advisor.clone())
27✔
67
            .with_author_display(doc.contributor_author.clone())
27✔
68
            .with_author_s(doc.all_authors())
27✔
69
            .with_author_sort(match &doc.contributor_author {
27✔
70
                Some(authors) => authors.first().cloned(),
3✔
71
                None => None,
24✔
72
            })
73
            .with_call_number_browse_s(doc.call_number())
27✔
74
            .with_call_number_display(doc.call_number())
27✔
75
            .with_certificate_display(doc.authorized_ceritificates())
27✔
76
            .with_contributor_display(doc.contributor.clone())
27✔
77
            .with_department_display(doc.authorized_departments())
27✔
78
            .with_format(vec![super::FormatFacet::SeniorThesis])
27✔
79
            .with_holdings_1display(doc.physical_holding_string())
27✔
80
            .with_location(doc.location())
27✔
81
            .with_location_code_s(doc.location_code())
27✔
82
            .with_location_display(doc.location_display())
27✔
83
            .with_electronic_access_1display(doc.ark_hash())
27✔
84
            .with_electronic_portfolio_s(doc.online_portfolio_statements())
27✔
85
            .with_restrictions_note_display(doc.restrictions_note_display())
27✔
86
            .with_title_citation_display(match &doc.title {
27✔
87
                Some(titles) => titles.first().cloned(),
3✔
88
                None => None,
24✔
89
            })
90
            .with_title_display(match &doc.title {
27✔
91
                Some(titles) => titles.first().cloned(),
3✔
92
                None => None,
24✔
93
            })
94
            .with_title_sort(title_sort(doc.title.as_ref()))
27✔
95
            .with_title_t(doc.title_search_versions())
27✔
96
            .with_language_facet(doc.languages())
27✔
97
            .with_language_name_display(doc.languages())
27✔
98
            .with_class_year_s(doc.class_year().map(|year| vec![year]))
27✔
99
            .with_pub_date_start_sort(doc.class_year())
27✔
100
            .with_pub_date_end_sort(doc.class_year())
27✔
101
            .with_description_display(doc.format_extent.clone())
27✔
102
            .with_summary_note_display(doc.description_abstract.clone())
27✔
103
            .build()
27✔
104
    }
27✔
105
}
106

107
fn title_sort(titles: Option<&Vec<String>>) -> Option<String> {
35✔
108
    match titles {
35✔
109
        Some(title_vec) => {
11✔
110
            let first = title_vec.first()?;
11✔
111
            Some(
112
                first
11✔
113
                    .to_lowercase()
11✔
114
                    .chars()
11✔
115
                    .filter(|c| !c.is_ascii_punctuation())
230✔
116
                    .collect::<String>()
11✔
117
                    .trim_start_matches("a ")
11✔
118
                    .trim_start_matches("an ")
11✔
119
                    .trim_start_matches("the ")
11✔
120
                    .chars()
11✔
121
                    .filter(|c| !c.is_whitespace())
205✔
122
                    .collect::<String>(),
11✔
123
            )
124
        }
125
        None => None,
24✔
126
    }
127
}
35✔
128

129
fn title_sort_as_option(titles: Option<&Vec<Option<String>>>) -> Option<String> {
25✔
130
    match titles {
25✔
131
        Some(title_vec) => {
1✔
132
            let first = title_vec.first()?;
1✔
133
            Some(
134
                first
1✔
135
                    .as_ref()
1✔
136
                    .unwrap()
1✔
137
                    .to_lowercase()
1✔
138
                    .chars()
1✔
139
                    .filter(|c| !c.is_ascii_punctuation())
30✔
140
                    .collect::<String>()
1✔
141
                    .trim_start_matches("a ")
1✔
142
                    .trim_start_matches("an ")
1✔
143
                    .trim_start_matches("the ")
1✔
144
                    .chars()
1✔
145
                    .filter(|c| !c.is_whitespace())
29✔
146
                    .collect::<String>(),
1✔
147
            )
148
        }
149
        None => None,
24✔
150
    }
151
}
25✔
152

153
#[cfg(test)]
154
mod tests {
155
    use crate::solr::{AccessFacet, FormatFacet};
156
    use crate::theses::dataspace::document::Metadatum;
157

158
    use super::*;
159

160
    fn metadatum_vec_from_string(value: &str) -> Vec<Metadatum> {
41✔
161
        vec![Metadatum { value: Some(value.to_string()) }]
41✔
162
    }
41✔
163

164
    #[test]
165
    fn it_can_convert_into_solr_document() {
1✔
166
        let metadata = LegacyDataspaceDocument::builder()
1✔
167
            .with_id("dsp01b2773v788")
1✔
168
            .with_description_abstract("Summary")
1✔
169
            .with_contributor("Wolff, Tamsen".to_string())
1✔
170
            .with_contributor_advisor("Sandberg, Robert".to_string())
1✔
171
            .with_contributor_author("Clark, Hillary".to_string())
1✔
172
            .with_date_classyear("2014")
1✔
173
            .with_department("Princeton University. Department of English")
1✔
174
            .with_department("Princeton University. Program in Theater")
1✔
175
            .with_format_extent("102 pages")
1✔
176
            .with_language_iso("en_US")
1✔
177
            .with_title("Dysfunction: A Play in One Act".to_string())
1✔
178
            .build();
1✔
179

180
        let solr = SolrDocument::from(&metadata);
1✔
181

182
        assert_eq!(solr.id, "dsp01b2773v788");
1✔
183
        assert_eq!(
1✔
184
            solr.title_t.unwrap(),
1✔
185
            vec!["Dysfunction: A Play in One Act"]
1✔
186
        );
187
        assert_eq!(
1✔
188
            solr.title_citation_display.unwrap(),
1✔
189
            "Dysfunction: A Play in One Act"
190
        );
191
        assert_eq!(
1✔
192
            solr.title_display.unwrap(),
1✔
193
            "Dysfunction: A Play in One Act"
194
        );
195
        assert_eq!(solr.title_sort.unwrap(), "dysfunctionaplayinoneact");
1✔
196
    }
1✔
197

198
    #[test]
199
    fn it_adds_the_expected_fields() {
1✔
200
        let document = DataspaceDocument::builder()
1✔
201
            .with_id("dsp01b2773v788")
1✔
202
            .with_description_abstract(metadatum_vec_from_string("Summary"))
1✔
203
            .with_contributor(metadatum_vec_from_string("Wolff, Tamsen"))
1✔
204
            .with_contributor_advisor(metadatum_vec_from_string("Sandberg, Robert"))
1✔
205
            .with_contributor_author(metadatum_vec_from_string("Clark, Hillary"))
1✔
206
            .with_identifier_uri(metadatum_vec_from_string("http://arks.princeton.edu/ark:/88435/dsp01b2773v788"))
1✔
207
            .with_format_extent(metadatum_vec_from_string("102 pages"))
1✔
208
            .with_language_iso(metadatum_vec_from_string("en_US"))
1✔
209
            .with_title(metadatum_vec_from_string("Dysfunction: A Play in One Act"))
1✔
210
            .with_date_classyear(metadatum_vec_from_string("2014"))
1✔
211
            .with_department(metadatum_vec_from_string("Princeton University. Department of English"))
1✔
212
            .with_department(metadatum_vec_from_string("Princeton University. Program in Theater"))
1✔
213
            .with_rights_access_rights(metadatum_vec_from_string("Walk-in Access..."))
1✔
214
            .build();
1✔
215
        let solr = SolrDocument::from(&document);
1✔
216
        assert_eq!(solr.author_display, Some(vec!["Clark, Hillary".to_owned()]));
1✔
217
        assert_eq!(
1✔
218
            solr.author_s.unwrap().sort(),
1✔
219
            [
1✔
220
                "Clark, Hillary".to_owned(),
1✔
221
                "Sandberg, Robert".to_owned(),
1✔
222
                "Wolff, Tamsen".to_owned()
1✔
223
            ]
1✔
224
            .sort()
1✔
225
        );
226
        assert_eq!(solr.summary_note_display, Some(vec!["Summary".to_owned()]))
1✔
227
    }
1✔
228

229
    #[test]
230
    fn it_is_senior_thesis() {
1✔
231
        let document = DataspaceDocument::builder().build();
1✔
232
        let solr = SolrDocument::from(&document);
1✔
233
        assert_eq!(solr.format, Some(vec![FormatFacet::SeniorThesis]));
1✔
234
    }
1✔
235

236
    #[test]
237
    fn integer_in_classyear_field() {
1✔
238
        let document = DataspaceDocument::builder()
1✔
239
            .with_date_classyear(metadatum_vec_from_string("2014"))
1✔
240
            .build();
1✔
241
        let solr = SolrDocument::from(&document);
1✔
242
        assert_eq!(solr.class_year_s.unwrap(), vec![2014]);
1✔
243
        assert_eq!(solr.pub_date_start_sort.unwrap(), 2014);
1✔
244
        assert_eq!(solr.pub_date_end_sort.unwrap(), 2014);
1✔
245
    }
1✔
246

247
    #[test]
248
    fn non_integer_in_classyear_field() {
1✔
249
        let document = DataspaceDocument::builder()
1✔
250
            .with_date_classyear(metadatum_vec_from_string("Undated"))
1✔
251
            .build();
1✔
252
        let solr = SolrDocument::from(&document);
1✔
253
        assert!(solr.class_year_s.is_none());
1✔
254
        assert!(solr.pub_date_start_sort.is_none());
1✔
255
        assert!(solr.pub_date_end_sort.is_none());
1✔
256
    }
1✔
257

258
    #[test]
259
    fn no_classyear() {
1✔
260
        let document = DataspaceDocument::builder().build();
1✔
261
        let solr = SolrDocument::from(&document);
1✔
262
        assert!(solr.class_year_s.is_none());
1✔
263
        assert!(solr.pub_date_start_sort.is_none());
1✔
264
        assert!(solr.pub_date_end_sort.is_none());
1✔
265
    }
1✔
266

267
    #[test]
268
    fn with_access_rights() {
1✔
269
        let document = DataspaceDocument::builder()
1✔
270
            .with_rights_access_rights(metadatum_vec_from_string("Walk-in Access..."))
1✔
271
            .build();
1✔
272
        let solr = SolrDocument::from(&document);
1✔
273
        assert_eq!(solr.access_facet.unwrap(), AccessFacet::Online);
1✔
274
        assert!(solr.advanced_location_s.is_none());
1✔
275
    }
1✔
276

277
    #[test]
278
    fn with_embargo() {
1✔
279
        let document = DataspaceDocument::builder()
1✔
280
            .with_rights_access_rights(metadatum_vec_from_string("Walk-in Access..."))
1✔
281
            .with_embargo_terms(metadatum_vec_from_string("2100-01-01"))
1✔
282
            .build();
1✔
283
        let solr = SolrDocument::from(&document);
1✔
284
        assert!(solr.access_facet.is_none());
1✔
285
        assert_eq!(
1✔
286
            solr.advanced_location_s.unwrap(),
1✔
287
            vec![
1✔
288
                "mudd$stacks".to_owned(),
1✔
289
                "Mudd Manuscript Library".to_owned()
1✔
290
            ]
291
        );
292
    }
1✔
293

294
    #[test]
295
    fn it_has_electronic_portfolio_s_by_default() {
1✔
296
        let document = DataspaceDocument::builder().build();
1✔
297
        let solr = SolrDocument::from(&document);
1✔
298
        assert_eq!(solr.access_facet.unwrap(), AccessFacet::Online);
1✔
299
        assert!(solr.electronic_portfolio_s.unwrap().contains("thesis"));
1✔
300
    }
1✔
301

302
    #[test]
303
    fn it_has_no_electronic_portfolio_s_if_location_specified_and_older_thesis() {
1✔
304
        let document = DataspaceDocument::builder()
1✔
305
            .with_date_classyear(metadatum_vec_from_string("1955"))
1✔
306
            .with_location(metadatum_vec_from_string(r#"This thesis can be viewed in person at the <a href=http://mudd.princeton.edu>Mudd Manuscript Library</a>.  \nTo order a copy complete the <a href=\"http://rbsc.princeton.edu/senior-thesis-order-form\" target=\"_blank\">Senior Thesis Request Form</a>.  \nFor more information contact <a href=mailto:mudd@princeton.edu>mudd@princeton.edu</a>."#))
1✔
307
            .build();
1✔
308
        let solr = SolrDocument::from(&document);
1✔
309
        assert!(solr.electronic_portfolio_s.is_none());
1✔
310
    }
1✔
311

312
    #[test]
313
    fn with_allowed_department_name() {
1✔
314
        let document = DataspaceDocument::builder()
1✔
315
            .with_department(metadatum_vec_from_string("English"))
1✔
316
            .build();
1✔
317
        let solr = SolrDocument::from(&document);
1✔
318
        assert_eq!(
1✔
319
            solr.department_display.unwrap(),
1✔
320
            vec!["Princeton University. Department of English"],
1✔
NEW
321
            "it should map to the LC authorized name for the department"
×
322
        );
323
    }
1✔
324

325
    #[test]
326
    fn with_disallowed_department_name() {
1✔
327
        let document = DataspaceDocument::builder().with_department(metadatum_vec_from_string("NA")).build();
1✔
328
        let solr = SolrDocument::from(&document);
1✔
329
        assert!(
1✔
330
            solr.department_display.unwrap().is_empty(),
1✔
NEW
331
            "it should not include department names that are not in the authorized list"
×
332
        );
333
    }
1✔
334

335
    #[test]
336
    fn with_multiple_allowed_department_names() {
1✔
337
        let document = DataspaceDocument::builder()
1✔
338
            .with_department(metadatum_vec_from_string("English"))
1✔
339
            .with_department(metadatum_vec_from_string("German"))
1✔
340
            .build();
1✔
341
        let solr = SolrDocument::from(&document);
1✔
342
        assert_eq!(
1✔
343
            solr.department_display.unwrap(),
1✔
344
            vec![
1✔
345
                "Princeton University. Department of English",
346
                "Princeton University. Department of Germanic Languages and Literatures"
1✔
347
            ],
NEW
348
            "it should map to all LC authorized department names"
×
349
        );
350
    }
1✔
351

352
    #[test]
353
    fn with_allowed_certificate_name() {
1✔
354
        let document = DataspaceDocument::builder()
1✔
355
            .with_certificate(metadatum_vec_from_string("Creative Writing Program"))
1✔
356
            .build();
1✔
357
        let solr = SolrDocument::from(&document);
1✔
358
        assert_eq!(
1✔
359
            solr.certificate_display.unwrap(),
1✔
360
            vec!["Princeton University. Creative Writing Program"],
1✔
NEW
361
            "it should map to the LC authorized name for the program"
×
362
        );
363
    }
1✔
364

365
    #[test]
366
    fn with_disallowed_certificate_name() {
1✔
367
        let document = DataspaceDocument::builder().with_certificate(metadatum_vec_from_string("NA")).build();
1✔
368
        let solr = SolrDocument::from(&document);
1✔
369
        assert!(
1✔
370
            solr.certificate_display.unwrap().is_empty(),
1✔
NEW
371
            "it should not include program names that are not in the authorized list"
×
372
        );
373
    }
1✔
374

375
    #[test]
376
    fn with_multiple_allowed_certificate_names() {
1✔
377
        let document = DataspaceDocument::builder()
1✔
378
            .with_certificate(metadatum_vec_from_string("Environmental Studies Program"))
1✔
379
            .with_certificate(metadatum_vec_from_string("African Studies Program"))
1✔
380
            .build();
1✔
381
        let solr = SolrDocument::from(&document);
1✔
382
        assert_eq!(
1✔
383
            solr.certificate_display.unwrap(),
1✔
384
            vec![
1✔
385
                "Princeton University. Program in Environmental Studies",
386
                "Princeton University. Program in African Studies"
1✔
387
            ],
NEW
388
            "it should map to all LC authorized program names"
×
389
        );
390
    }
1✔
391

392
    #[test]
393
    fn location_code_s() {
1✔
394
        let document = DataspaceDocument::builder()
1✔
395
            .with_date_classyear(metadatum_vec_from_string("2020"))
1✔
396
            .build();
1✔
397
        let solr = SolrDocument::from(&document);
1✔
398
        assert_eq!(solr.location_code_s, None);
1✔
399

400
        let document = DataspaceDocument::builder()
1✔
401
            .with_date_classyear(metadatum_vec_from_string("1980"))
1✔
402
            .with_rights_access_rights(metadatum_vec_from_string("Limited access"))
1✔
403
            .build();
1✔
404
        let solr = SolrDocument::from(&document);
1✔
405
        assert_eq!(solr.location_code_s.unwrap(), "mudd$stacks");
1✔
406
    }
1✔
407

408
    #[test]
409
    fn location_display() {
1✔
410
        let document = DataspaceDocument::builder()
1✔
411
            .with_mudd_walkin(metadatum_vec_from_string("yes"))
1✔
412
            .with_date_classyear(metadatum_vec_from_string("1995"))
1✔
413
            .build();
1✔
414
        let solr = SolrDocument::from(&document);
1✔
415
        assert_eq!(solr.location_display.unwrap(), "Mudd Manuscript Library");
1✔
416
    }
1✔
417

418
    #[test]
419
    fn holdings_1display() {
1✔
420
        let document = DataspaceDocument::builder()
1✔
421
            .with_rights_access_rights(metadatum_vec_from_string("Limited access"))
1✔
422
            .with_date_classyear(metadatum_vec_from_string("2005"))
1✔
423
            .build();
1✔
424
        let solr = SolrDocument::from(&document);
1✔
425
        assert_eq!(
1✔
426
            solr.holdings_1display.unwrap(),
1✔
427
            "{\"thesis\":{\"location\":\"Mudd Manuscript Library\",\"library\":\"Mudd Manuscript Library\",\"location_code\":\"mudd$stacks\",\"call_number\":\"AC102\",\"call_number_browse\":\"AC102\",\"dspace\":true}}",
NEW
428
            "holdings_1display should be present when physical thesis has limited access"
×
429
        );
430

431
        let document = DataspaceDocument::builder()
1✔
432
            .with_identifier_uri(metadatum_vec_from_string("http://arks.princeton.edu/ark:/88435/dsp0141687h67f"))
1✔
433
            .build();
1✔
434
        let solr = SolrDocument::from(&document);
1✔
435
        assert!(
1✔
436
            solr.holdings_1display.is_none(),
1✔
NEW
437
            "holdings_1display should not be present when newer thesis has no location information"
×
438
        );
439
    }
1✔
440

441
    #[test]
442
    fn call_number_browse_s() {
1✔
443
        let document = DataspaceDocument::builder()
1✔
444
            .with_rights_access_rights(metadatum_vec_from_string("Limited access"))
1✔
445
            .with_date_classyear(metadatum_vec_from_string("2005"))
1✔
446
            .build();
1✔
447
        let solr = SolrDocument::from(&document);
1✔
448
        assert_eq!(solr.call_number_browse_s, "AC102");
1✔
449
    }
1✔
450

451
    #[test]
452
    fn language_facet() {
1✔
453
        let document = DataspaceDocument::builder().with_language_iso(metadatum_vec_from_string("it")).build();
1✔
454
        let solr = SolrDocument::from(&document);
1✔
455
        assert_eq!(solr.language_facet, vec!["Italian".to_owned()]);
1✔
456
    }
1✔
457

458
    mod restrictions_note_display {
459
        use super::*;
460

461
        #[test]
462
        fn when_lift_date_is_invalid() {
1✔
463
            let document = DataspaceDocument::builder()
1✔
464
                .with_id("test-id")
1✔
465
                .with_embargo_lift(metadatum_vec_from_string("invalid"))
1✔
466
                .build();
1✔
467
            let solr = SolrDocument::from(&document);
1✔
468
            assert_eq!(solr.restrictions_note_display, Some(vec!["This content is currently under embargo. For more information contact the <a href=\"mailto:dspadmin@princeton.edu?subject=Regarding embargoed DataSpace Item 88435/test-id\"> Mudd Manuscript Library</a>.".to_string()]));
1✔
469
        }
1✔
470

471
        #[test]
472
        fn when_terms_date_is_invalid() {
1✔
473
            let document = DataspaceDocument::builder()
1✔
474
                .with_id("test-id")
1✔
475
                .with_embargo_terms(metadatum_vec_from_string("invalid"))
1✔
476
                .build();
1✔
477
            let solr = SolrDocument::from(&document);
1✔
478
            assert_eq!(solr.restrictions_note_display.unwrap(), vec!["This content is currently under embargo. For more information contact the <a href=\"mailto:dspadmin@princeton.edu?subject=Regarding embargoed DataSpace Item 88435/test-id\"> Mudd Manuscript Library</a>."]);
1✔
479
        }
1✔
480

481
        #[test]
482
        fn when_there_are_access_rights() {
1✔
483
            let document = DataspaceDocument::builder()
1✔
484
                .with_id("test-id")
1✔
485
                .with_rights_access_rights(metadatum_vec_from_string("Walk-in Access. This thesis can only be viewed on computer terminals at the <a href=http://mudd.princeton.edu>Mudd Manuscript Library</a>."))
1✔
486
                .build();
1✔
487
            let solr = SolrDocument::from(&document);
1✔
488
            assert_eq!(solr.restrictions_note_display.unwrap(), vec!["Walk-in Access. This thesis can only be viewed on computer terminals at the <a href=http://mudd.princeton.edu>Mudd Manuscript Library</a>."]);
1✔
489
        }
1✔
490
    }
491

492
    mod title_sort {
493
        use super::*;
494

495
        #[test]
496
        fn it_can_create_sortable_version_of_title() {
1✔
497
            assert_eq!(
1✔
498
                title_sort(Some(&vec!["\"Some quote\" : Blah blah".to_owned()])).unwrap(),
1✔
499
                "somequoteblahblah",
NEW
500
                "it should strip punctuation"
×
501
            );
502
            assert_eq!(
1✔
503
                title_sort(Some(&vec!["A title : blah blah".to_owned()])).unwrap(),
1✔
504
                "titleblahblah",
NEW
505
                "it should strip articles"
×
506
            );
507
            assert_eq!(
1✔
508
                title_sort(Some(&vec!["\"A quote\" : Blah blah".to_owned()])).unwrap(),
1✔
509
                "quoteblahblah",
NEW
510
                "it should strip punctuation and articles"
×
511
            );
512
            assert_eq!(
1✔
513
                title_sort(Some(&vec!["thesis".to_owned()])).unwrap(),
1✔
514
                "thesis",
NEW
515
                "it should leave words that start with articles alone"
×
516
            );
517
        }
1✔
518
    }
519
}
520

521
#[cfg(test)]
522
mod legacy_tests {
523
    use crate::solr::{AccessFacet, FormatFacet};
524

525
    use super::*;
526

527
    #[test]
528
    fn it_can_convert_into_solr_document() {
1✔
529
        let metadata = LegacyDataspaceDocument::builder()
1✔
530
            .with_id("dsp01b2773v788")
1✔
531
            .with_description_abstract("Summary")
1✔
532
            .with_contributor("Wolff, Tamsen".to_string())
1✔
533
            .with_contributor_advisor("Sandberg, Robert".to_string())
1✔
534
            .with_contributor_author("Clark, Hillary".to_string())
1✔
535
            .with_date_classyear("2014")
1✔
536
            .with_department("Princeton University. Department of English")
1✔
537
            .with_department("Princeton University. Program in Theater")
1✔
538
            .with_format_extent("102 pages")
1✔
539
            .with_language_iso("en_US")
1✔
540
            .with_title("Dysfunction: A Play in One Act".to_string())
1✔
541
            .build();
1✔
542

543
        let solr = SolrDocument::from(&metadata);
1✔
544

545
        assert_eq!(solr.id, "dsp01b2773v788");
1✔
546
        assert_eq!(
1✔
547
            solr.title_t.unwrap(),
1✔
548
            vec!["Dysfunction: A Play in One Act"]
1✔
549
        );
550
        assert_eq!(
1✔
551
            solr.title_citation_display.unwrap(),
1✔
552
            "Dysfunction: A Play in One Act"
553
        );
554
        assert_eq!(
1✔
555
            solr.title_display.unwrap(),
1✔
556
            "Dysfunction: A Play in One Act"
557
        );
558
        assert_eq!(solr.title_sort.unwrap(), "dysfunctionaplayinoneact");
1✔
559
    }
1✔
560

561
    #[test]
562
    fn it_adds_the_expected_fields() {
1✔
563
        let document = LegacyDataspaceDocument::builder()
1✔
564
            .with_id("dsp01b2773v788")
1✔
565
            .with_description_abstract("Summary")
1✔
566
            .with_contributor("Wolff, Tamsen")
1✔
567
            .with_contributor_advisor("Sandberg, Robert")
1✔
568
            .with_contributor_author("Clark, Hillary")
1✔
569
            .with_identifier_uri("http://arks.princeton.edu/ark:/88435/dsp01b2773v788")
1✔
570
            .with_format_extent("102 pages")
1✔
571
            .with_language_iso("en_US")
1✔
572
            .with_title("Dysfunction: A Play in One Act")
1✔
573
            .with_date_classyear("2014")
1✔
574
            .with_department("Princeton University. Department of English")
1✔
575
            .with_department("Princeton University. Program in Theater")
1✔
576
            .with_rights_access_rights("Walk-in Access...")
1✔
577
            .build();
1✔
578
        let solr = SolrDocument::from(&document);
1✔
579
        assert_eq!(solr.author_display, Some(vec!["Clark, Hillary".to_owned()]));
1✔
580
        assert_eq!(
1✔
581
            solr.author_s.unwrap().sort(),
1✔
582
            [
1✔
583
                "Clark, Hillary".to_owned(),
1✔
584
                "Sandberg, Robert".to_owned(),
1✔
585
                "Wolff, Tamsen".to_owned()
1✔
586
            ]
1✔
587
            .sort()
1✔
588
        );
589
        assert_eq!(solr.summary_note_display, Some(vec!["Summary".to_owned()]))
1✔
590
    }
1✔
591

592
    #[test]
593
    fn it_is_senior_thesis() {
1✔
594
        let document = LegacyDataspaceDocument::builder().build();
1✔
595
        let solr = SolrDocument::from(&document);
1✔
596
        assert_eq!(solr.format, Some(vec![FormatFacet::SeniorThesis]));
1✔
597
    }
1✔
598

599
    #[test]
600
    fn integer_in_classyear_field() {
1✔
601
        let document = LegacyDataspaceDocument::builder()
1✔
602
            .with_date_classyear("2014")
1✔
603
            .build();
1✔
604
        let solr = SolrDocument::from(&document);
1✔
605
        assert_eq!(solr.class_year_s.unwrap(), vec![2014]);
1✔
606
        assert_eq!(solr.pub_date_start_sort.unwrap(), 2014);
1✔
607
        assert_eq!(solr.pub_date_end_sort.unwrap(), 2014);
1✔
608
    }
1✔
609

610
    #[test]
611
    fn non_integer_in_classyear_field() {
1✔
612
        let document = LegacyDataspaceDocument::builder()
1✔
613
            .with_date_classyear("Undated")
1✔
614
            .build();
1✔
615
        let solr = SolrDocument::from(&document);
1✔
616
        assert!(solr.class_year_s.is_none());
1✔
617
        assert!(solr.pub_date_start_sort.is_none());
1✔
618
        assert!(solr.pub_date_end_sort.is_none());
1✔
619
    }
1✔
620

621
    #[test]
622
    fn no_classyear() {
1✔
623
        let document = LegacyDataspaceDocument::builder().build();
1✔
624
        let solr = SolrDocument::from(&document);
1✔
625
        assert!(solr.class_year_s.is_none());
1✔
626
        assert!(solr.pub_date_start_sort.is_none());
1✔
627
        assert!(solr.pub_date_end_sort.is_none());
1✔
628
    }
1✔
629

630
    #[test]
631
    fn with_access_rights() {
1✔
632
        let document = LegacyDataspaceDocument::builder()
1✔
633
            .with_rights_access_rights("Walk-in Access...")
1✔
634
            .build();
1✔
635
        let solr = SolrDocument::from(&document);
1✔
636
        assert_eq!(solr.access_facet.unwrap(), AccessFacet::Online);
1✔
637
        assert!(solr.advanced_location_s.is_none());
1✔
638
    }
1✔
639

640
    #[test]
641
    fn with_embargo() {
1✔
642
        let document = LegacyDataspaceDocument::builder()
1✔
643
            .with_rights_access_rights("Walk-in Access...")
1✔
644
            .with_embargo_terms("2100-01-01")
1✔
645
            .build();
1✔
646
        let solr = SolrDocument::from(&document);
1✔
647
        assert!(solr.access_facet.is_none());
1✔
648
        assert_eq!(
1✔
649
            solr.advanced_location_s.unwrap(),
1✔
650
            vec![
1✔
651
                "mudd$stacks".to_owned(),
1✔
652
                "Mudd Manuscript Library".to_owned()
1✔
653
            ]
654
        );
655
    }
1✔
656

657
    #[test]
658
    fn it_has_electronic_portfolio_s_by_default() {
1✔
659
        let document = LegacyDataspaceDocument::builder().build();
1✔
660
        let solr = SolrDocument::from(&document);
1✔
661
        assert_eq!(solr.access_facet.unwrap(), AccessFacet::Online);
1✔
662
        assert!(solr.electronic_portfolio_s.unwrap().contains("thesis"));
1✔
663
    }
1✔
664

665
    #[test]
666
    fn it_has_no_electronic_portfolio_s_if_location_specified_and_older_thesis() {
1✔
667
        let document = LegacyDataspaceDocument::builder()
1✔
668
            .with_date_classyear("1955")
1✔
669
            .with_location(r#"This thesis can be viewed in person at the <a href=http://mudd.princeton.edu>Mudd Manuscript Library</a>.  \nTo order a copy complete the <a href=\"http://rbsc.princeton.edu/senior-thesis-order-form\" target=\"_blank\">Senior Thesis Request Form</a>.  \nFor more information contact <a href=mailto:mudd@princeton.edu>mudd@princeton.edu</a>."#)
1✔
670
            .build();
1✔
671
        let solr = SolrDocument::from(&document);
1✔
672
        assert!(solr.electronic_portfolio_s.is_none());
1✔
673
    }
1✔
674

675
    #[test]
676
    fn with_allowed_department_name() {
1✔
677
        let document = LegacyDataspaceDocument::builder()
1✔
678
            .with_department("English")
1✔
679
            .build();
1✔
680
        let solr = SolrDocument::from(&document);
1✔
681
        assert_eq!(
1✔
682
            solr.department_display.unwrap(),
1✔
683
            vec!["Princeton University. Department of English"],
1✔
684
            "it should map to the LC authorized name for the department"
×
685
        );
686
    }
1✔
687

688
    #[test]
689
    fn with_disallowed_department_name() {
1✔
690
        let document = LegacyDataspaceDocument::builder().with_department("NA").build();
1✔
691
        let solr = SolrDocument::from(&document);
1✔
692
        assert!(
1✔
693
            solr.department_display.unwrap().is_empty(),
1✔
694
            "it should not include department names that are not in the authorized list"
×
695
        );
696
    }
1✔
697

698
    #[test]
699
    fn with_multiple_allowed_department_names() {
1✔
700
        let document = LegacyDataspaceDocument::builder()
1✔
701
            .with_department("English")
1✔
702
            .with_department("German")
1✔
703
            .build();
1✔
704
        let solr = SolrDocument::from(&document);
1✔
705
        assert_eq!(
1✔
706
            solr.department_display.unwrap(),
1✔
707
            vec![
1✔
708
                "Princeton University. Department of English",
709
                "Princeton University. Department of Germanic Languages and Literatures"
1✔
710
            ],
711
            "it should map to all LC authorized department names"
×
712
        );
713
    }
1✔
714

715
    #[test]
716
    fn with_allowed_certificate_name() {
1✔
717
        let document = LegacyDataspaceDocument::builder()
1✔
718
            .with_certificate("Creative Writing Program")
1✔
719
            .build();
1✔
720
        let solr = SolrDocument::from(&document);
1✔
721
        assert_eq!(
1✔
722
            solr.certificate_display.unwrap(),
1✔
723
            vec!["Princeton University. Creative Writing Program"],
1✔
724
            "it should map to the LC authorized name for the program"
×
725
        );
726
    }
1✔
727

728
    #[test]
729
    fn with_disallowed_certificate_name() {
1✔
730
        let document = LegacyDataspaceDocument::builder().with_certificate("NA").build();
1✔
731
        let solr = SolrDocument::from(&document);
1✔
732
        assert!(
1✔
733
            solr.certificate_display.unwrap().is_empty(),
1✔
734
            "it should not include program names that are not in the authorized list"
×
735
        );
736
    }
1✔
737

738
    #[test]
739
    fn with_multiple_allowed_certificate_names() {
1✔
740
        let document = LegacyDataspaceDocument::builder()
1✔
741
            .with_certificate("Environmental Studies Program")
1✔
742
            .with_certificate("African Studies Program")
1✔
743
            .build();
1✔
744
        let solr = SolrDocument::from(&document);
1✔
745
        assert_eq!(
1✔
746
            solr.certificate_display.unwrap(),
1✔
747
            vec![
1✔
748
                "Princeton University. Program in Environmental Studies",
749
                "Princeton University. Program in African Studies"
1✔
750
            ],
751
            "it should map to all LC authorized program names"
×
752
        );
753
    }
1✔
754

755
    #[test]
756
    fn location_code_s() {
1✔
757
        let document = LegacyDataspaceDocument::builder()
1✔
758
            .with_date_classyear("2020")
1✔
759
            .build();
1✔
760
        let solr = SolrDocument::from(&document);
1✔
761
        assert_eq!(solr.location_code_s, None);
1✔
762

763
        let document = LegacyDataspaceDocument::builder()
1✔
764
            .with_date_classyear("1980")
1✔
765
            .with_rights_access_rights("Limited access")
1✔
766
            .build();
1✔
767
        let solr = SolrDocument::from(&document);
1✔
768
        assert_eq!(solr.location_code_s.unwrap(), "mudd$stacks");
1✔
769
    }
1✔
770

771
    #[test]
772
    fn location_display() {
1✔
773
        let document = LegacyDataspaceDocument::builder()
1✔
774
            .with_mudd_walkin("yes")
1✔
775
            .with_date_classyear("1995")
1✔
776
            .build();
1✔
777
        let solr = SolrDocument::from(&document);
1✔
778
        assert_eq!(solr.location_display.unwrap(), "Mudd Manuscript Library");
1✔
779
    }
1✔
780

781
    #[test]
782
    fn holdings_1display() {
1✔
783
        let document = LegacyDataspaceDocument::builder()
1✔
784
            .with_rights_access_rights("Limited access")
1✔
785
            .with_date_classyear("2005")
1✔
786
            .build();
1✔
787
        let solr = SolrDocument::from(&document);
1✔
788
        assert_eq!(
1✔
789
            solr.holdings_1display.unwrap(),
1✔
790
            "{\"thesis\":{\"location\":\"Mudd Manuscript Library\",\"library\":\"Mudd Manuscript Library\",\"location_code\":\"mudd$stacks\",\"call_number\":\"AC102\",\"call_number_browse\":\"AC102\",\"dspace\":true}}",
791
            "holdings_1display should be present when physical thesis has limited access"
×
792
        );
793

794
        let document = LegacyDataspaceDocument::builder()
1✔
795
            .with_identifier_uri("http://arks.princeton.edu/ark:/88435/dsp0141687h67f")
1✔
796
            .build();
1✔
797
        let solr = SolrDocument::from(&document);
1✔
798
        assert!(
1✔
799
            solr.holdings_1display.is_none(),
1✔
800
            "holdings_1display should not be present when newer thesis has no location information"
×
801
        );
802
    }
1✔
803

804
    #[test]
805
    fn call_number_browse_s() {
1✔
806
        let document = LegacyDataspaceDocument::builder()
1✔
807
            .with_rights_access_rights("Limited access")
1✔
808
            .with_date_classyear("2005")
1✔
809
            .build();
1✔
810
        let solr = SolrDocument::from(&document);
1✔
811
        assert_eq!(solr.call_number_browse_s, "AC102");
1✔
812
    }
1✔
813

814
    #[test]
815
    fn language_facet() {
1✔
816
        let document = LegacyDataspaceDocument::builder().with_language_iso("it").build();
1✔
817
        let solr = SolrDocument::from(&document);
1✔
818
        assert_eq!(solr.language_facet, vec!["Italian".to_owned()]);
1✔
819
    }
1✔
820

821
    mod restrictions_note_display {
822
        use super::*;
823

824
        #[test]
825
        fn when_lift_date_is_invalid() {
1✔
826
            let document = LegacyDataspaceDocument::builder()
1✔
827
                .with_id("test-id")
1✔
828
                .with_embargo_lift("invalid")
1✔
829
                .build();
1✔
830
            let solr = SolrDocument::from(&document);
1✔
831
            assert_eq!(solr.restrictions_note_display.unwrap(), vec!["This content is currently under embargo. For more information contact the <a href=\"mailto:dspadmin@princeton.edu?subject=Regarding embargoed DataSpace Item 88435/test-id\"> Mudd Manuscript Library</a>."]);
1✔
832
        }
1✔
833

834
        #[test]
835
        fn when_terms_date_is_invalid() {
1✔
836
            let document = LegacyDataspaceDocument::builder()
1✔
837
                .with_id("test-id")
1✔
838
                .with_embargo_terms("invalid")
1✔
839
                .build();
1✔
840
            let solr = SolrDocument::from(&document);
1✔
841
            assert_eq!(solr.restrictions_note_display.unwrap(), vec!["This content is currently under embargo. For more information contact the <a href=\"mailto:dspadmin@princeton.edu?subject=Regarding embargoed DataSpace Item 88435/test-id\"> Mudd Manuscript Library</a>."]);
1✔
842
        }
1✔
843

844
        #[test]
845
        fn when_there_are_access_rights() {
1✔
846
            let document = LegacyDataspaceDocument::builder()
1✔
847
                .with_id("test-id")
1✔
848
                .with_rights_access_rights("Walk-in Access. This thesis can only be viewed on computer terminals at the <a href=http://mudd.princeton.edu>Mudd Manuscript Library</a>.")
1✔
849
                .build();
1✔
850
            let solr = SolrDocument::from(&document);
1✔
851
            assert_eq!(solr.restrictions_note_display.unwrap(), vec!["Walk-in Access. This thesis can only be viewed on computer terminals at the <a href=http://mudd.princeton.edu>Mudd Manuscript Library</a>."]);
1✔
852
        }
1✔
853
    }
854

855
    mod title_sort {
856
        use super::*;
857

858
        #[test]
859
        fn it_can_create_sortable_version_of_title() {
1✔
860
            assert_eq!(
1✔
861
                title_sort(Some(&vec!["\"Some quote\" : Blah blah".to_owned()])).unwrap(),
1✔
862
                "somequoteblahblah",
863
                "it should strip punctuation"
×
864
            );
865
            assert_eq!(
1✔
866
                title_sort(Some(&vec!["A title : blah blah".to_owned()])).unwrap(),
1✔
867
                "titleblahblah",
868
                "it should strip articles"
×
869
            );
870
            assert_eq!(
1✔
871
                title_sort(Some(&vec!["\"A quote\" : Blah blah".to_owned()])).unwrap(),
1✔
872
                "quoteblahblah",
873
                "it should strip punctuation and articles"
×
874
            );
875
            assert_eq!(
1✔
876
                title_sort(Some(&vec!["thesis".to_owned()])).unwrap(),
1✔
877
                "thesis",
878
                "it should leave words that start with articles alone"
×
879
            );
880
        }
1✔
881
    }
882
}
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