refactor(db): DRY object SELECT columns, consistent date json; test date + all-none round-trip
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -75,3 +75,44 @@ async fn object_by_id_missing_is_none(pool: PgPool) {
|
||||
.is_none()
|
||||
);
|
||||
}
|
||||
|
||||
#[sqlx::test]
|
||||
async fn object_with_date_and_all_none_optionals_round_trips(pool: PgPool) {
|
||||
let db = Db::from_pool(pool);
|
||||
let date = time::Date::from_calendar_date(2020, time::Month::January, 28).unwrap();
|
||||
let input = ObjectInput {
|
||||
object_number: "LM-3".into(),
|
||||
object_name: "drawing".into(),
|
||||
number_of_objects: 1,
|
||||
brief_description: None,
|
||||
current_location: None,
|
||||
current_owner: None,
|
||||
recorder: None,
|
||||
recording_date: Some(date),
|
||||
visibility: Visibility::Internal,
|
||||
};
|
||||
|
||||
let mut tx = db.pool().begin().await.unwrap();
|
||||
let id = catalog::create_object(&mut tx, AuditActor::System, &input)
|
||||
.await
|
||||
.unwrap();
|
||||
tx.commit().await.unwrap();
|
||||
|
||||
let obj = catalog::object_by_id(db.pool(), id).await.unwrap().unwrap();
|
||||
assert_eq!(obj.recording_date, Some(date));
|
||||
assert_eq!(obj.brief_description, None);
|
||||
assert_eq!(obj.current_location, None);
|
||||
assert_eq!(obj.current_owner, None);
|
||||
assert_eq!(obj.recorder, None);
|
||||
assert_eq!(obj.visibility, Visibility::Internal);
|
||||
|
||||
let history = audit::history_for(db.pool(), "object", id.to_uuid())
|
||||
.await
|
||||
.unwrap();
|
||||
assert!(
|
||||
history[0]
|
||||
.changes
|
||||
.iter()
|
||||
.any(|c| c.field == "recording_date")
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user