summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorD. Scott Boggs <scott@tams.tech>2023-02-12 12:47:14 -0500
committerD. Scott Boggs <scott@tams.tech>2024-04-08 08:56:16 -0400
commitc45fe6892fd3bbda2665fcc71a549c3341c81386 (patch)
treee73f13a2e7995e4deca9b5b93da2048111b86d41
parent84f2f45efafc9969507a7a15cdd662f7a566b695 (diff)
Add email domain block example test
-rw-r--r--entities/src/admin/email_domain_block.rs69
1 files changed, 66 insertions, 3 deletions
diff --git a/entities/src/admin/email_domain_block.rs b/entities/src/admin/email_domain_block.rs
index ca6094b..d6b6a73 100644
--- a/entities/src/admin/email_domain_block.rs
+++ b/entities/src/admin/email_domain_block.rs
@@ -1,5 +1,5 @@
use serde::{Deserialize, Serialize};
-use time::{serde::iso8601, OffsetDateTime};
+use time::{serde::iso8601, OffsetDateTime, Date};
use crate::{conversion, EmailDomainBlockId};
@@ -22,8 +22,8 @@ pub struct EmailDomainBlock {
/// Usage history for a given day
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct History {
- #[serde(with = "iso8601")]
- pub day: OffsetDateTime,
+ #[serde(with = "conversion::date_from_timestamp")]
+ pub day: Date,
/// The counted accounts signup attempts using that email domain within that day.
#[serde(with = "conversion::string_to_u64")]
pub accounts: u64,
@@ -31,3 +31,66 @@ pub struct History {
#[serde(with = "conversion::string_to_u64")]
pub uses: u64,
}
+
+#[cfg(test)]
+mod tests {
+ use time::Month;
+
+ use super::*;
+
+ #[test]
+ fn test_example() {
+ let example = r#"{
+ "id": "1",
+ "domain": "foo",
+ "created_at": "2022-11-16T06:09:36.176Z",
+ "history": [
+ {
+ "day": "1668556800",
+ "accounts": "0",
+ "uses": "0"
+ },
+ {
+ "day": "1668470400",
+ "accounts": "0",
+ "uses": "0"
+ },
+ {
+ "day": "1668384000",
+ "accounts": "0",
+ "uses": "0"
+ },
+ {
+ "day": "1668297600",
+ "accounts": "0",
+ "uses": "0"
+ },
+ {
+ "day": "1668211200",
+ "accounts": "0",
+ "uses": "0"
+ },
+ {
+ "day": "1668124800",
+ "accounts": "0",
+ "uses": "0"
+ },
+ {
+ "day": "1668038400",
+ "accounts": "0",
+ "uses": "0"
+ }
+ ]
+ }"#;
+ let subject: EmailDomainBlock = serde_json::from_str(example).unwrap();
+ assert_eq!(subject.id, EmailDomainBlockId::new("1"));
+ assert_eq!(subject.domain, "foo");
+ for (i, entry) in subject.history.iter().enumerate() {
+ assert_eq!(entry.accounts, 0);
+ assert_eq!(entry.uses, 0);
+ assert_eq!(entry.day.year(), 2022);
+ assert_eq!(entry.day.month(), Month::November);
+ assert_eq!(entry.day.day(), (16 - i) as u8);
+ }
+ }
+} \ No newline at end of file