Skip to content

Commit 6fc8911

Browse files
lmamminoclaude
andauthored
fix: resolve Quote struct type mismatch and update tests (#103)
The rustfmt commit exposed an issue where the Quote struct in create-issue was using String for author_url, but fetch-quote was returning Option<String>. Changes: - Updated Quote struct in create-issue to use Option<String> for author_url - Fixed test template to use camelCase field names (authorUrl, authorDescription) instead of snake_case (author_url, author_description) to match serde renames - Removed outdated assertion checking for subscribe_form which was removed from the template in a previous commit All tests now pass. Co-authored-by: Claude <[email protected]>
1 parent 654719e commit 6fc8911

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

functions/create-issue/src/model.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ pub struct Quote {
4949
pub author: String,
5050
#[serde(rename = "authorDescription")]
5151
pub author_description: String,
52-
#[serde(rename = "authorUrl")]
53-
pub author_url: String,
52+
#[serde(rename = "authorUrl", skip_serializing_if = "Option::is_none")]
53+
pub author_url: Option<String>,
5454
}
5555

5656
#[derive(Deserialize, Serialize, Debug, Clone)]

functions/create-issue/src/template.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ mod tests {
219219
text: "Computers are useless. They can only give you answers".to_string(),
220220
author: "Pablo Picasso".to_string(),
221221
author_description: "Artist".to_string(),
222-
author_url: "https://en.wikipedia.org/wiki/Pablo_Picasso".to_string(),
222+
author_url: Some("https://en.wikipedia.org/wiki/Pablo_Picasso".to_string()),
223223
};
224224

225225
let book = Book {
@@ -519,28 +519,28 @@ Book: {{ book.title }}
519519
}
520520

521521
// Test both naming conventions to understand which one Tera uses
522-
let test_desc_rust = r#"{{ quote.author_description }}"#;
522+
let test_desc_rust = r#"{{ quote.authorDescription }}"#;
523523
let result_desc_rust = Tera::one_off(test_desc_rust, &full_context, false);
524524
match result_desc_rust {
525525
Ok(rendered) => println!("Rust field name works: {}", rendered),
526526
Err(e) => println!("Rust field name failed: {}", e),
527527
}
528528

529-
let test_desc_json = r#"{{ quote.author_description }}"#;
529+
let test_desc_json = r#"{{ quote.authorDescription }}"#;
530530
let result_desc = Tera::one_off(test_desc_json, &full_context, false);
531531
match result_desc {
532532
Ok(rendered) => println!("Description works: {}", rendered),
533533
Err(e) => println!("Description failed: {}", e),
534534
}
535535

536-
let test2b = r#"{{ quote.author_url }}"#;
536+
let test2b = r#"{{ quote.authorUrl }}"#;
537537
let result2b = Tera::one_off(test2b, &full_context, false);
538538
match result2b {
539539
Ok(rendered) => println!("Test 2b works: {}", rendered),
540540
Err(e) => println!("Test 2b failed: {}", e),
541541
}
542542

543-
let test2 = r#"> — [{{ quote.author }}]({{ quote.author_url }})"#;
543+
let test2 = r#"> — [{{ quote.author }}]({{ quote.authorUrl }})"#;
544544
let result2 = Tera::one_off(test2, &full_context, false);
545545
match result2 {
546546
Ok(rendered) => println!("Test 2 works:\n{}", rendered),
@@ -549,8 +549,8 @@ Book: {{ book.title }}
549549

550550
// Test just the beginning of our actual template
551551
let partial_template = r#"Hello World
552-
> "{{ quote.text }}"
553-
> — {{ quote.author }}, {{ quote.author_description }}"#;
552+
> "{{ quote.text }}"
553+
> — {{ quote.author }}, {{ quote.authorDescription }}"#;
554554

555555
let partial_result = Tera::one_off(partial_template, &full_context, false);
556556
match partial_result {
@@ -577,7 +577,6 @@ Book: {{ book.title }}
577577
assert!(rendered.contains("Building Microservices"));
578578
assert!(rendered.contains("An Interactive Guide to SVG Paths"));
579579
assert!(rendered.contains("{{ subscriber.metadata.first_name }}"));
580-
assert!(rendered.contains("{{ subscribe_form }}"));
581580
}
582581
Err(e) => {
583582
println!("Template rendering failed: {}", e);

0 commit comments

Comments
 (0)