Skip to content

Commit 1b92b14

Browse files
committed
Extend jats support
1 parent c523203 commit 1b92b14

3 files changed

Lines changed: 1055 additions & 371 deletions

File tree

thoth-api/src/graphql/tests.rs

Lines changed: 76 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2565,10 +2565,12 @@ fn graphql_markup_mutations_accept_plain_text_when_markup_is_jats_xml() {
25652565
title_id: title.title_id,
25662566
work_id: title.work_id,
25672567
locale_code: title.locale_code,
2568-
full_title: "Foundations for Moral <italic>Relativism</italic> Second Expanded Edition"
2568+
full_title: "Foundations for Moral <italic>Relativism</italic> <underline>Second</underline> <strike>Expanded</strike> <inline-formula><tex-math>E=mc^2</tex-math></inline-formula> <email>editor@example.org</email> <uri>https://example.org</uri> Edition"
25692569
.to_string(),
2570-
title: "Foundations for Moral <italic>Relativism</italic>".to_string(),
2571-
subtitle: Some("Second Expanded Edition".to_string()),
2570+
title: "Foundations for Moral <italic>Relativism</italic> <inline-formula><tex-math>E=mc^2</tex-math></inline-formula>".to_string(),
2571+
subtitle: Some(
2572+
"<underline>Second</underline> <strike>Expanded</strike> <email>editor@example.org</email> <uri>https://example.org</uri> Edition".to_string(),
2573+
),
25722574
canonical: title.canonical,
25732575
},
25742576
MarkupFormat::JatsXml,
@@ -2577,15 +2579,17 @@ fn graphql_markup_mutations_accept_plain_text_when_markup_is_jats_xml() {
25772579
let stored_title = Title::from_id(pool.as_ref(), &seed.title_id).unwrap();
25782580
assert_eq!(
25792581
stored_title.full_title,
2580-
"Foundations for Moral <italic>Relativism</italic> Second Expanded Edition"
2582+
"Foundations for Moral <italic>Relativism</italic> <underline>Second</underline> <strike>Expanded</strike> <inline-formula><tex-math>E=mc^2</tex-math></inline-formula> <email>editor@example.org</email> <uri>https://example.org</uri> Edition"
25812583
);
25822584
assert_eq!(
25832585
stored_title.title,
2584-
"Foundations for Moral <italic>Relativism</italic>"
2586+
"Foundations for Moral <italic>Relativism</italic> <inline-formula><tex-math>E=mc^2</tex-math></inline-formula>"
25852587
);
25862588
assert_eq!(
25872589
stored_title.subtitle.as_deref(),
2588-
Some("Second Expanded Edition")
2590+
Some(
2591+
"<underline>Second</underline> <strike>Expanded</strike> <email>editor@example.org</email> <uri>https://example.org</uri> Edition"
2592+
)
25892593
);
25902594

25912595
let abstract_item = Abstract::from_id(pool.as_ref(), &seed.abstract_short_id).unwrap();
@@ -2598,19 +2602,82 @@ fn graphql_markup_mutations_accept_plain_text_when_markup_is_jats_xml() {
25982602
PatchAbstract {
25992603
abstract_id: abstract_item.abstract_id,
26002604
work_id: abstract_item.work_id,
2601-
content: "Plain abstract content updated".to_string(),
2605+
content:
2606+
"First line\nSecond line with $E=mc^2$ and user@example.org and https://example.org"
2607+
.to_string(),
26022608
locale_code: abstract_item.locale_code,
26032609
abstract_type: abstract_item.abstract_type,
26042610
canonical: abstract_item.canonical,
26052611
},
2606-
MarkupFormat::JatsXml,
2612+
MarkupFormat::PlainText,
26072613
);
26082614

26092615
let stored_abstract = Abstract::from_id(pool.as_ref(), &seed.abstract_short_id).unwrap();
26102616
assert_eq!(
26112617
stored_abstract.content,
2612-
"<p>Plain abstract content updated</p>"
2618+
"<p>First line<break/>Second line with <inline-formula><tex-math>E=mc^2</tex-math></inline-formula> and <email>user@example.org</email> and <uri>https://example.org</uri></p>"
2619+
);
2620+
2621+
let biography = Biography::from_id(pool.as_ref(), &seed.biography_id).unwrap();
2622+
update_with_data_and_markup(
2623+
&schema,
2624+
&context,
2625+
"updateBiography",
2626+
"PatchBiography",
2627+
"biographyId",
2628+
PatchBiography {
2629+
biography_id: biography.biography_id,
2630+
contribution_id: biography.contribution_id,
2631+
content: "<p>Bio line<break/><inline-formula><tex-math>x^2</tex-math></inline-formula> <email>bio@example.org</email> <uri>https://bio.example.org</uri></p>".to_string(),
2632+
canonical: biography.canonical,
2633+
locale_code: biography.locale_code,
2634+
},
2635+
MarkupFormat::JatsXml,
2636+
);
2637+
2638+
let stored_biography = Biography::from_id(pool.as_ref(), &seed.biography_id).unwrap();
2639+
assert_eq!(
2640+
stored_biography.content,
2641+
"<p>Bio line<break/><inline-formula><tex-math>x^2</tex-math></inline-formula> <email>bio@example.org</email> <uri>https://bio.example.org</uri></p>"
2642+
);
2643+
}
2644+
2645+
#[test]
2646+
fn graphql_update_title_rejects_break_elements_for_jats_xml() {
2647+
let (_guard, pool) = test_db::setup_test_db();
2648+
let schema = create_schema();
2649+
let superuser = test_db::test_superuser("user-jats-title-break-rejection");
2650+
let context = test_db::test_context_with_user(pool.clone(), superuser);
2651+
let seed = seed_data(&schema, &context);
2652+
let title = Title::from_id(pool.as_ref(), &seed.title_id).unwrap();
2653+
2654+
let query = r#"
2655+
mutation UpdateTitle($data: PatchTitle!, $markup: MarkupFormat!) {
2656+
updateTitle(data: $data, markupFormat: $markup) {
2657+
titleId
2658+
}
2659+
}
2660+
"#;
2661+
let mut vars = Variables::new();
2662+
insert_var(
2663+
&mut vars,
2664+
"data",
2665+
PatchTitle {
2666+
title_id: title.title_id,
2667+
work_id: title.work_id,
2668+
locale_code: title.locale_code,
2669+
full_title: "Broken<break/>Title".to_string(),
2670+
title: "Broken<break/>Title".to_string(),
2671+
subtitle: title.subtitle.clone(),
2672+
canonical: title.canonical,
2673+
},
26132674
);
2675+
insert_var(&mut vars, "markup", MarkupFormat::JatsXml);
2676+
2677+
let (_, errors) = juniper::execute_sync(query, None, &schema, &vars, &context)
2678+
.expect("GraphQL execution should succeed with validation errors");
2679+
assert!(!errors.is_empty(), "Expected GraphQL validation error");
2680+
assert!(!errors[0].error().message().is_empty());
26142681
}
26152682

26162683
#[test]

0 commit comments

Comments
 (0)