diff --git a/src/core/pay.rs b/src/core/pay.rs index d67fc17..a2003d5 100644 --- a/src/core/pay.rs +++ b/src/core/pay.rs @@ -9,7 +9,7 @@ pub struct Query { pub email: Option, pub jpeg: Option>, pub png: Option>, - pub comment_size: u64, + pub comment_size: Option, pub min: u64, pub max: u64, } @@ -23,8 +23,6 @@ impl std::str::FromStr for Query { let p: de::Query = miniserde::json::from_str(s).map_err(|_| "deserialize failed")?; - let comment_size = p.comment_allowed.unwrap_or(0); - let metadata = miniserde::json::from_str::>(&p.metadata) .map_err(|_| "deserialize metadata failed")?; @@ -79,11 +77,11 @@ impl std::str::FromStr for Query { Ok(Query { callback: p.callback.0.into_owned(), + comment_size: p.comment_allowed, min: p.min_sendable, max: p.max_sendable, short_description, long_description, - comment_size, identifier, email, jpeg, @@ -124,7 +122,7 @@ impl std::fmt::Display for Query { callback: crate::serde::Url(std::borrow::Cow::Borrowed(&self.callback)), min_sendable: self.min, max_sendable: self.max, - comment_allowed: self.comment_size, + comment_allowed: self.comment_size.unwrap_or(0), })) } } @@ -290,7 +288,7 @@ mod tests { assert_eq!(parsed.min, 314); assert_eq!(parsed.max, 315); - assert_eq!(parsed.comment_size, 0); + assert!(parsed.comment_size.is_none()); assert!(parsed.long_description.is_none()); assert!(parsed.jpeg.is_none()); assert!(parsed.png.is_none()); @@ -311,7 +309,7 @@ mod tests { "#; let parsed = input.parse::().expect("parse"); - assert_eq!(parsed.comment_size, 140); + assert_eq!(parsed.comment_size.unwrap(), 140); } #[test] @@ -386,7 +384,7 @@ mod tests { long_description: None, jpeg: None, png: None, - comment_size: 0, + comment_size: None, min: 314, max: 315, identifier: None, @@ -407,7 +405,7 @@ mod tests { long_description: None, jpeg: None, png: None, - comment_size: 140, + comment_size: Some(140), min: 314, max: 315, identifier: None, @@ -428,7 +426,7 @@ mod tests { long_description: Some(String::from("mochila a jato brutal incluida")), jpeg: None, png: None, - comment_size: 0, + comment_size: None, min: 314, max: 315, identifier: None, @@ -449,7 +447,7 @@ mod tests { long_description: None, jpeg: Some(b"imagembrutal".to_vec()), png: Some(b"fotobrutal".to_vec()), - comment_size: 0, + comment_size: None, min: 314, max: 315, identifier: None, @@ -470,7 +468,7 @@ mod tests { long_description: None, jpeg: Some(b"imagembrutal".to_vec()), png: Some(b"fotobrutal".to_vec()), - comment_size: 0, + comment_size: None, min: 314, max: 315, identifier: Some(String::from("steve@magal.brutal")), @@ -491,7 +489,7 @@ mod tests { long_description: None, jpeg: Some(b"imagembrutal".to_vec()), png: Some(b"fotobrutal".to_vec()), - comment_size: 0, + comment_size: None, min: 314, max: 315, identifier: None, diff --git a/tests/lud06.rs b/tests/lud06.rs index 50af8c1..371cd69 100644 --- a/tests/lud06.rs +++ b/tests/lud06.rs @@ -20,7 +20,7 @@ async fn test() { long_description: Some(String::from("the destroyer of worlds")), jpeg: None, png: None, - comment_size: 0, + comment_size: None, min: 314, max: 315, identifier: None, diff --git a/tests/lud09.rs b/tests/lud09.rs index 5fac6ae..ed700c7 100644 --- a/tests/lud09.rs +++ b/tests/lud09.rs @@ -20,7 +20,7 @@ async fn test() { long_description: None, jpeg: None, png: None, - comment_size: 0, + comment_size: None, min: 314, max: 315, identifier: None, diff --git a/tests/lud11.rs b/tests/lud11.rs index e33b77a..4f6506d 100644 --- a/tests/lud11.rs +++ b/tests/lud11.rs @@ -20,7 +20,7 @@ async fn test() { long_description: None, jpeg: None, png: None, - comment_size: 0, + comment_size: None, min: 314, max: 315, identifier: None, diff --git a/tests/lud12.rs b/tests/lud12.rs index 27253a8..280a456 100644 --- a/tests/lud12.rs +++ b/tests/lud12.rs @@ -20,7 +20,7 @@ async fn test() { long_description: None, jpeg: None, png: None, - comment_size: 140, + comment_size: Some(140), min: 314, max: 315, identifier: None, @@ -56,7 +56,7 @@ async fn test() { panic!("not pay request"); }; - assert_eq!(pr.core.comment_size, 140); + assert_eq!(pr.core.comment_size.unwrap(), 140); let invoice = pr.clone().callback("", 314).await.expect("callback"); assert_eq!(invoice.pr, "pierre:None"); diff --git a/tests/lud16.rs b/tests/lud16.rs index 66c5242..7514cb1 100644 --- a/tests/lud16.rs +++ b/tests/lud16.rs @@ -19,7 +19,7 @@ async fn test() { long_description: Some(String::from("the destroyer of worlds")), jpeg: None, png: None, - comment_size: 0, + comment_size: None, min: 314, max: 315, identifier: identifier.clone().filter(|i| i.starts_with('n')), diff --git a/tests/real.rs b/tests/real.rs index df4f82f..8f571ef 100644 --- a/tests/real.rs +++ b/tests/real.rs @@ -14,7 +14,7 @@ mod pay_request { assert_eq!(pr.short_description, "Sats for lorenzo"); assert!(pr.long_description.is_none()); - assert_eq!(pr.comment_size, 255); + assert_eq!(pr.comment_size, Some(255)); assert_eq!(pr.max, 500_000_000); assert_eq!(pr.min, 1000); @@ -37,7 +37,7 @@ mod pay_request { assert_eq!(pr.short_description, "Payment to lorenzo"); assert!(pr.long_description.is_none()); - assert_eq!(pr.comment_size, 2000); + assert_eq!(pr.comment_size, Some(2000)); assert_eq!(pr.max, 100_000_000_000); assert_eq!(pr.min, 1000); @@ -57,7 +57,7 @@ mod pay_request { assert_eq!(pr.short_description, "$kenu ⚡ bipa.app"); assert!(pr.long_description.is_none()); - assert_eq!(pr.comment_size, 140); + assert_eq!(pr.comment_size, Some(140)); assert_eq!(pr.max, 1_000_000_000); assert_eq!(pr.min, 1000); @@ -80,7 +80,7 @@ mod pay_request { assert_eq!(pr.short_description, "Lightning payment to ethan@pouch.ph"); assert!(pr.long_description.is_none()); - assert_eq!(pr.comment_size, 150); + assert_eq!(pr.comment_size, Some(150)); assert_eq!(pr.max, 10_000_000_000); assert_eq!(pr.min, 1000); @@ -103,7 +103,7 @@ mod pay_request { ); assert!(pr.long_description.is_none()); - assert_eq!(pr.comment_size, 255); + assert_eq!(pr.comment_size, Some(255)); assert_eq!(pr.max, 100_000_000_000); assert_eq!(pr.min, 1000); @@ -126,7 +126,7 @@ mod pay_request { assert_eq!(pr.short_description, "luhack - Welcome to my zbd.gg page!"); assert!(pr.long_description.is_none()); - assert_eq!(pr.comment_size, 150); + assert_eq!(pr.comment_size, Some(150)); assert_eq!(pr.max, 500_000_000); assert_eq!(pr.min, 1000);