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)
|
Ok(StatusCode::NO_CONTENT)
|
||||||
} else {
|
} else {
|
||||||
|
let _ = tx.rollback().await;
|
||||||
|
|
||||||
Err(StatusCode::NOT_FOUND)
|
Err(StatusCode::NOT_FOUND)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -410,6 +412,8 @@ pub(crate) async fn rename_vocabulary(
|
|||||||
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
|
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
|
||||||
Ok(StatusCode::NO_CONTENT)
|
Ok(StatusCode::NO_CONTENT)
|
||||||
} else {
|
} else {
|
||||||
|
let _ = tx.rollback().await;
|
||||||
|
|
||||||
Err(StatusCode::NOT_FOUND)
|
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::{
|
use domain::{
|
||||||
AuditActor, AuthorityKind, FieldType, LocalizedLabel, NewFieldDefinition, ObjectInput,
|
AuditAction, AuditActor, AuthorityKind, FieldType, LocalizedLabel, NewFieldDefinition,
|
||||||
Visibility,
|
ObjectInput, Visibility,
|
||||||
};
|
};
|
||||||
use sqlx::PgPool;
|
use sqlx::PgPool;
|
||||||
|
|
||||||
@@ -257,6 +257,13 @@ async fn delete_field_definition_blocks_when_objects_use_it(pool: PgPool) {
|
|||||||
.await
|
.await
|
||||||
.unwrap();
|
.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())
|
let obj = catalog::create_object(&mut tx, AuditActor::System, &sample_object_input())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@@ -285,6 +292,14 @@ async fn delete_field_definition_blocks_when_objects_use_it(pool: PgPool) {
|
|||||||
DeleteOutcome::Deleted
|
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!(
|
assert_eq!(
|
||||||
fields::delete_field_definition(&mut tx, AuditActor::System, "weight")
|
fields::delete_field_definition(&mut tx, AuditActor::System, "weight")
|
||||||
.await
|
.await
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use db::{Db, catalog, fields, vocab};
|
use db::{Db, audit, catalog, fields, vocab};
|
||||||
use domain::{
|
use domain::{
|
||||||
AuditActor, FieldType, LocalizedLabel, NewFieldDefinition, NewTerm, ObjectInput, Visibility,
|
AuditAction, AuditActor, FieldType, LocalizedLabel, NewFieldDefinition, NewTerm, ObjectInput,
|
||||||
|
Visibility,
|
||||||
};
|
};
|
||||||
use sqlx::PgPool;
|
use sqlx::PgPool;
|
||||||
|
|
||||||
@@ -222,6 +223,15 @@ async fn update_term_changes_labels_and_uri(pool: PgPool) {
|
|||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(existed);
|
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();
|
tx.commit().await.unwrap();
|
||||||
|
|
||||||
let term = vocab::term_by_id(db.pool(), term_id)
|
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()
|
.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)
|
let gone = vocab::delete_term(&mut tx, AuditActor::System, vocab.id, term_id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|||||||
Reference in New Issue
Block a user