From 067e9784b54e4645412e5e7d8d7d2bc70bdcf646 Mon Sep 17 00:00:00 2001 From: Kevin J Hoerr Date: Tue, 29 Oct 2019 00:21:26 -0400 Subject: Split messages into separate module; add unit tests for each message type --- src/routes/messages/not_understood.rs | 48 +++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/routes/messages/not_understood.rs (limited to 'src/routes/messages/not_understood.rs') diff --git a/src/routes/messages/not_understood.rs b/src/routes/messages/not_understood.rs new file mode 100644 index 0000000..6c2c3ae --- /dev/null +++ b/src/routes/messages/not_understood.rs @@ -0,0 +1,48 @@ +use messages::Message; + +#[derive(Debug, Serialize)] +pub struct NotUnderstood { + pub path: Vec, +} + +impl Message for NotUnderstood { + fn name(&self) -> String { + String::from("NOT_UNDERSTOOD") + } +} + +impl PartialEq for NotUnderstood { + fn eq(&self, other: &Self) -> bool { + self.path == other.path + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_name() { + // Arrange + let message = NotUnderstood { path: vec![] }; + + // Act + let name = message.name(); + + // Assert + assert_eq!(name, "NOT_UNDERSTOOD"); + } + + #[test] + fn test_asoutgoing() { + // Arrange + let message = NotUnderstood { path: vec![] }; + + // Act + let outgoing = message.as_outgoing(); + + // Assert + assert_eq!(outgoing.result_type, "NOT_UNDERSTOOD"); + assert_eq!(outgoing.content, NotUnderstood { path: vec![] }); + } +} -- cgit