From ecead91492de11e7b55f08d4bd0239eb4fd0c3c3 Mon Sep 17 00:00:00 2001 From: rhigman <73792779+rhigman@users.noreply.github.com> Date: Tue, 27 Feb 2024 16:02:21 +0000 Subject: [PATCH] Add Locations to tests --- thoth-export-server/src/xml/onix3_thoth.rs | 110 +++++++++++++++++---- 1 file changed, 92 insertions(+), 18 deletions(-) diff --git a/thoth-export-server/src/xml/onix3_thoth.rs b/thoth-export-server/src/xml/onix3_thoth.rs index 1fec848f..736a433a 100644 --- a/thoth-export-server/src/xml/onix3_thoth.rs +++ b/thoth-export-server/src/xml/onix3_thoth.rs @@ -814,7 +814,7 @@ impl XmlElementBlock for Work { publication.locations.clone(); if locations.is_empty() { // Create single Supplier based on Work Landing Page - // to ensure child elements such as Price are not omitted + // so that we can output a SupplyDetail block (inc. Price info) // (if Landing Page is None, Supplier will be complete apart from Website) locations = vec![WorkPublicationsLocations { landing_page: self.landing_page.clone(), @@ -2147,12 +2147,21 @@ mod tests { unit_price: 8.0, }, ], - locations: vec![WorkPublicationsLocations { - landing_page: Some("https://www.book.com/pb_landing".to_string()), - full_text_url: None, - location_platform: LocationPlatform::PUBLISHER_WEBSITE, - canonical: true, - }], + locations: vec![ + WorkPublicationsLocations { + landing_page: Some("https://www.book.com/pb_landing".to_string()), + full_text_url: None, + location_platform: LocationPlatform::PUBLISHER_WEBSITE, + canonical: true, + }, + WorkPublicationsLocations { + landing_page: Some("https://www.jstor.com/pb_landing".to_string()), + // Note a paperback can't technically have a Full Text URL - test purposes only + full_text_url: Some("https://www.jstor.com/pb_fulltext".to_string()), + location_platform: LocationPlatform::JSTOR, + canonical: false, + }, + ], }], subjects: vec![ WorkSubjects { @@ -2749,7 +2758,10 @@ mod tests { WORLD - + "# + )); + assert!(output.contains( + r#" 09 @@ -2768,6 +2780,29 @@ mod tests { )); assert!(output.contains( r#" + + + 11 + JSTOR"# + )); + assert!(output.contains( + r#" + + 36 + JSTOR: webpage for this product + https://www.jstor.com/pb_landing + "# + )); + assert!(output.contains( + r#" + + 29 + JSTOR: download the title + https://www.jstor.com/pb_fulltext + "# + )); + assert!(output.contains( + r#" 02 5.95 @@ -2886,7 +2921,7 @@ mod tests { test_work.copyright_holder = None; test_work.publications[0].isbn = None; test_work.publications[0].height_mm = None; - test_work.publications[0].locations.clear(); + test_work.publications[0].locations.pop(); test_work.publications[0].prices.pop(); test_work.relations[0].related_work.last_page = None; test_work.relations[0].related_work.page_count = None; @@ -3106,20 +3141,27 @@ mod tests { "# )); - // Supplier block still present but Website absent - assert!(output.contains( + assert!(!output.contains( r#" + - 09 - OA Editions - "# + 11 + JSTOR"# )); assert!(!output.contains( r#" - 02 - Publisher's website: webpage for this product - https://www.book.com/pb_landing + 36 + JSTOR: webpage for this product + https://www.jstor.com/pb_landing + "# + )); + assert!(!output.contains( + r#" + + 29 + JSTOR: download the title + https://www.jstor.com/pb_fulltext "# )); assert!(!output.contains( @@ -3156,6 +3198,7 @@ mod tests { test_work.publications[0].weight_g = None; test_work.publications[0].weight_oz = None; test_work.publications[0].prices.clear(); + test_work.publications[0].locations.clear(); let output = generate_test_output(true, &test_work); println!("{output}"); // Still no Edition, same as when value was 1 @@ -3197,6 +3240,22 @@ mod tests { "# )); assert!(!output.contains(r#" "#)); + // Supplier block for publisher still present but Website absent + assert!(output.contains( + r#" + + 09 + OA Editions + "# + )); + assert!(!output.contains( + r#" + + 02 + Publisher's website: webpage for this product + https://www.book.com/pb_landing + "# + )); // UnpricedItemType block instead of any Prices assert!(output.contains(r#" 04"#)); assert!(!output.contains(r#" "#)); @@ -3207,6 +3266,8 @@ mod tests { test_work.relations[1].related_work.doi = None; // Test truncation of short abstract test_work.short_abstract = Some("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum vel libero eleifend, ultrices purus vitae, suscipit ligula. Aliquam ornare quam et nulla vestibulum, id euismod tellus malesuada. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nullam ornare bibendum ex nec dapibus. Proin porta risus elementum odio feugiat tempus. Etiam eu felis ac metus viverra ornare. In consectetur neque sed feugiat ornare. Mauris at purus fringilla orci tincidunt pulvinar sed a massa. Nullam vestibulum posuere augue, sit amet tincidunt nisl pulvinar ac.".to_string()); + // Reinstate landing page: supplier block for publisher now contains it + test_work.landing_page = Some("https://www.book.com".to_string()); let output = generate_test_output(true, &test_work); println!("{output}"); assert!(!output.contains(r#" "#)); @@ -3220,7 +3281,20 @@ mod tests { Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum vel libero eleifend, ultrices purus vitae, suscipit ligula. Aliquam ornare quam et nulla vestibulum, id euismod tellus malesuada. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nullam ornare bibendum ex nec dapibus. Proin porta risus elementu "# )); - test_work.short_abstract = None; + assert!(output.contains( + r#" + + 09 + OA Editions + + 02 + Publisher's website: webpage for this product + https://www.book.com + + "# + )); + assert!(!output + .contains(r#" https://www.book.com/pb_landing"#)); // Add second publication, and test that two records are produced test_work.publications.push(WorkPublications {