-
Notifications
You must be signed in to change notification settings - Fork 2
/
notification.rs
56 lines (52 loc) · 1.72 KB
/
notification.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
use crate::notifications::{NotificationContent, NotificationDestination, NotificationId};
use time::OffsetDateTime;
/// Defines a notification.
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Notification {
/// Unique id of the notification.
pub id: NotificationId,
/// The destination of the notification.
pub destination: NotificationDestination,
/// The content of the notification.
pub content: NotificationContent,
/// The time at which the notification is scheduled to be sent, in UTC.
pub scheduled_at: OffsetDateTime,
}
impl Notification {
/// Creates a new notification.
pub fn new(
destination: NotificationDestination,
content: NotificationContent,
scheduled_at: OffsetDateTime,
) -> Self {
Self {
id: NotificationId::empty(),
destination,
content,
scheduled_at,
}
}
}
#[cfg(test)]
mod tests {
use super::{Notification, NotificationContent, NotificationDestination};
use crate::notifications::NotificationId;
use time::OffsetDateTime;
#[test]
fn new_notification() -> anyhow::Result<()> {
assert_eq!(
Notification::new(
NotificationDestination::User(123.try_into()?),
NotificationContent::Text("abc".to_string()),
OffsetDateTime::from_unix_timestamp(946720800)?
),
Notification {
id: NotificationId::empty(),
destination: NotificationDestination::User(123.try_into()?),
content: NotificationContent::Text("abc".to_string()),
scheduled_at: OffsetDateTime::from_unix_timestamp(946720800)?,
}
);
Ok(())
}
}