1#![warn(missing_docs)]
2use chrono::{DateTime, Utc};
8use serde::Serialize;
9
10#[derive(Debug, Clone, Serialize)]
14#[non_exhaustive]
15pub struct AuditEvent {
16 pub timestamp: DateTime<Utc>,
18 pub event_type: String,
20 pub description: String,
22}
23
24impl AuditEvent {
25 pub fn new(event_type: impl Into<String>, description: impl Into<String>) -> Self {
27 Self {
28 timestamp: Utc::now(),
29 event_type: event_type.into(),
30 description: description.into(),
31 }
32 }
33}
34
35#[cfg(test)]
36mod tests {
37 use super::*;
38
39 #[test]
40 fn serializes_to_json_without_panic() {
41 let event = AuditEvent::new("test_event", "a test audit event");
42 let json = serde_json::to_string(&event).expect("should serialize");
43 assert!(json.contains("test_event"));
44 assert!(json.contains("a test audit event"));
45 assert!(json.contains("timestamp"));
46 }
47}