test+refactor: audit-row assertions + uniform PATCH rollback (review follow-ups)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -296,6 +296,8 @@ pub(crate) async fn update_term(
|
||||
|
||||
Ok(StatusCode::NO_CONTENT)
|
||||
} else {
|
||||
let _ = tx.rollback().await;
|
||||
|
||||
Err(StatusCode::NOT_FOUND)
|
||||
}
|
||||
}
|
||||
@@ -410,6 +412,8 @@ pub(crate) async fn rename_vocabulary(
|
||||
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
|
||||
Ok(StatusCode::NO_CONTENT)
|
||||
} else {
|
||||
let _ = tx.rollback().await;
|
||||
|
||||
Err(StatusCode::NOT_FOUND)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use db::{Db, DeleteOutcome, catalog, fields, vocab};
|
||||
use db::{Db, DeleteOutcome, audit, catalog, fields, vocab};
|
||||
use domain::{
|
||||
AuditActor, AuthorityKind, FieldType, LocalizedLabel, NewFieldDefinition, ObjectInput,
|
||||
Visibility,
|
||||
AuditAction, AuditActor, AuthorityKind, FieldType, LocalizedLabel, NewFieldDefinition,
|
||||
ObjectInput, Visibility,
|
||||
};
|
||||
use sqlx::PgPool;
|
||||
|
||||
@@ -257,6 +257,13 @@ async fn delete_field_definition_blocks_when_objects_use_it(pool: PgPool) {
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let field_def_id = fields::field_definition_by_key(&mut *tx, "weight")
|
||||
.await
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.id
|
||||
.to_uuid();
|
||||
|
||||
let obj = catalog::create_object(&mut tx, AuditActor::System, &sample_object_input())
|
||||
.await
|
||||
.unwrap();
|
||||
@@ -285,6 +292,14 @@ async fn delete_field_definition_blocks_when_objects_use_it(pool: PgPool) {
|
||||
DeleteOutcome::Deleted
|
||||
);
|
||||
|
||||
let history = audit::history_for(&mut *tx, "field_definition", field_def_id)
|
||||
.await
|
||||
.unwrap();
|
||||
assert!(
|
||||
history.iter().any(|e| e.action == AuditAction::Deleted),
|
||||
"expected a Deleted audit entry for the field_definition"
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
fields::delete_field_definition(&mut tx, AuditActor::System, "weight")
|
||||
.await
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use db::{Db, catalog, fields, vocab};
|
||||
use db::{Db, audit, catalog, fields, vocab};
|
||||
use domain::{
|
||||
AuditActor, FieldType, LocalizedLabel, NewFieldDefinition, NewTerm, ObjectInput, Visibility,
|
||||
AuditAction, AuditActor, FieldType, LocalizedLabel, NewFieldDefinition, NewTerm, ObjectInput,
|
||||
Visibility,
|
||||
};
|
||||
use sqlx::PgPool;
|
||||
|
||||
@@ -222,6 +223,15 @@ async fn update_term_changes_labels_and_uri(pool: PgPool) {
|
||||
.await
|
||||
.unwrap();
|
||||
assert!(existed);
|
||||
|
||||
let history = audit::history_for(&mut *tx, "term", term_id.to_uuid())
|
||||
.await
|
||||
.unwrap();
|
||||
assert!(
|
||||
history.iter().any(|e| e.action == AuditAction::Updated),
|
||||
"expected an Updated audit entry for the term"
|
||||
);
|
||||
|
||||
tx.commit().await.unwrap();
|
||||
|
||||
let term = vocab::term_by_id(db.pool(), term_id)
|
||||
@@ -308,6 +318,14 @@ async fn delete_term_blocks_when_referenced_then_succeeds(pool: PgPool) {
|
||||
.is_none()
|
||||
);
|
||||
|
||||
let history = audit::history_for(&mut *tx, "term", term_id.to_uuid())
|
||||
.await
|
||||
.unwrap();
|
||||
assert!(
|
||||
history.iter().any(|e| e.action == AuditAction::Deleted),
|
||||
"expected a Deleted audit entry for the term"
|
||||
);
|
||||
|
||||
let gone = vocab::delete_term(&mut tx, AuditActor::System, vocab.id, term_id)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
Reference in New Issue
Block a user