diff --git a/src/models/readarr_models.rs b/src/models/readarr_models.rs index 0f4cf4ac..c43963b6 100644 --- a/src/models/readarr_models.rs +++ b/src/models/readarr_models.rs @@ -280,6 +280,7 @@ pub struct Book { pub ratings: Option, pub release_date: Option>, pub statistics: Option, + #[serde(default)] pub grabbed: bool, } diff --git a/src/models/readarr_models_tests.rs b/src/models/readarr_models_tests.rs index 0fd62ebf..5a0512fa 100644 --- a/src/models/readarr_models_tests.rs +++ b/src/models/readarr_models_tests.rs @@ -939,6 +939,22 @@ mod tests { assert_none!(&book.statistics); } + #[test] + fn test_book_deserialization_defaults_grabbed_when_absent() { + let book_json = json!({ + "id": 1, + "title": "The Name of the Wind", + "authorId": 3, + "foreignBookId": "test-foreign-book-id", + "monitored": true + }); + + let book: Book = serde_json::from_value(book_json).unwrap(); + + assert!(!book.grabbed); + assert!(book.monitored); + } + #[test] fn test_edition_deserialization() { let edition_json = json!({