From 89d24de30234bffd175e6768f780f64b9a240a48 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Fri, 20 Sep 2019 01:41:30 +0200 Subject: [PATCH] receipts: Update to XEP-0184 version 1.4.0. --- doap.xml | 2 +- src/avatar.rs | 1 + src/receipts.rs | 19 ++++++++++++++----- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/doap.xml b/doap.xml index f591bfff..3320bfa7 100644 --- a/doap.xml +++ b/doap.xml @@ -235,7 +235,7 @@ complete - 1.3.0 + 1.4.0 0.1.0 diff --git a/src/avatar.rs b/src/avatar.rs index e5c09d2a..0940c33a 100644 --- a/src/avatar.rs +++ b/src/avatar.rs @@ -58,6 +58,7 @@ impl PubSubPayload for Data {} mod tests { use super::*; use crate::hashes::Algo; + #[cfg(not(feature = "disable-validation"))] use crate::util::error::Error; use minidom::Element; use std::convert::TryFrom; diff --git a/src/receipts.rs b/src/receipts.rs index 3b54d3cd..af40f641 100644 --- a/src/receipts.rs +++ b/src/receipts.rs @@ -22,7 +22,7 @@ generate_element!( Received, "received", RECEIPTS, attributes: [ /// The 'id' attribute of the received message. - id: Option = "id", + id: Required = "id", ] ); @@ -34,6 +34,7 @@ mod tests { use crate::ns; use minidom::Element; use std::convert::TryFrom; + use crate::util::error::Error; #[cfg(target_pointer_width = "32")] #[test] @@ -54,15 +55,23 @@ mod tests { let elem: Element = "".parse().unwrap(); Request::try_from(elem).unwrap(); - let elem: Element = "".parse().unwrap(); - Received::try_from(elem).unwrap(); - let elem: Element = "" .parse() .unwrap(); Received::try_from(elem).unwrap(); } + #[test] + fn test_missing_id() { + let elem: Element = "".parse().unwrap(); + let error = Received::try_from(elem).unwrap_err(); + let message = match error { + Error::ParseError(string) => string, + _ => panic!(), + }; + assert_eq!(message, "Required attribute 'id' missing."); + } + #[test] fn test_serialise() { let receipt = Request; @@ -71,7 +80,7 @@ mod tests { assert_eq!(elem.attrs().count(), 0); let receipt = Received { - id: Some(String::from("coucou")), + id: String::from("coucou"), }; let elem: Element = receipt.into(); assert!(elem.is("received", ns::RECEIPTS));