From c9dc1fb479f47dbd061fec3684906d9c91953657 Mon Sep 17 00:00:00 2001 From: Akulij Date: Mon, 2 Jun 2025 12:03:28 +0500 Subject: [PATCH] create tests for BotNotification deserealization --- src/botscript.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/botscript.rs b/src/botscript.rs index cb9ede2..64e46b1 100644 --- a/src/botscript.rs +++ b/src/botscript.rs @@ -790,6 +790,7 @@ impl Runner { #[allow(clippy::print_stdout)] mod tests { use quickjs_rusty::{serde::from_js, OwnedJsObject}; + use serde_json::json; use super::*; @@ -868,4 +869,28 @@ mod tests { panic!("test returned an error, but the wrong one, {errstr}") } } + + #[test] + fn test_notification_struct() { + let botn = json!({ + "time": "18:00", + "filter": {"random": 2}, + "message": {"text": "some"}, + }); + let n: BotNotification = serde_json::from_value(botn).unwrap(); + println!("BotNotification: {n:#?}"); + assert!(matches!(n.time, NotificationTime::Specific(..))); + let time = if let NotificationTime::Specific(st) = n.time { + st + } else { + unreachable!() + }; + assert_eq!( + time, + SpecificTime { + hour: 18, + minutes: 00 + } + ); + } }