test(domain): pin audit serde contracts; loosen time version; note null caveat
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -44,6 +44,10 @@ pub enum AuditActor {
|
||||
}
|
||||
|
||||
/// One field's before/after values within a change.
|
||||
///
|
||||
/// Note: after a JSON round-trip, `Some(Value::Null)` is indistinguishable from
|
||||
/// `None`. Use `None` to mean "no value"; do not encode an absent value as
|
||||
/// `Some(Value::Null)`.
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct FieldChange {
|
||||
/// Field name (catalogue field key or column name).
|
||||
@@ -111,10 +115,33 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn actor_is_adjacently_tagged() {
|
||||
let v = serde_json::to_value(AuditActor::User(Uuid::nil())).unwrap();
|
||||
assert_eq!(v["kind"], "user");
|
||||
let v2 = serde_json::to_value(AuditActor::System).unwrap();
|
||||
assert_eq!(v2["kind"], "system");
|
||||
fn actor_serde_round_trips() {
|
||||
for actor in [AuditActor::User(Uuid::nil()), AuditActor::System] {
|
||||
let v = serde_json::to_value(actor).unwrap();
|
||||
let back: AuditActor = serde_json::from_value(v).unwrap();
|
||||
assert_eq!(back, actor);
|
||||
}
|
||||
assert_eq!(
|
||||
serde_json::to_value(AuditActor::User(Uuid::nil())).unwrap()["kind"],
|
||||
"user"
|
||||
);
|
||||
assert_eq!(
|
||||
serde_json::to_value(AuditActor::System).unwrap()["kind"],
|
||||
"system"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn action_serde_matches_as_str() {
|
||||
for a in [
|
||||
AuditAction::Created,
|
||||
AuditAction::Updated,
|
||||
AuditAction::Deleted,
|
||||
] {
|
||||
assert_eq!(
|
||||
serde_json::to_value(a).unwrap(),
|
||||
serde_json::Value::String(a.as_str().to_owned())
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user