feat: audit vocabulary/term/authority creation, attributing the acting user (#21)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
use db::{Db, vocab};
|
||||
use domain::{LocalizedLabel, NewTerm};
|
||||
use domain::{AuditActor, LocalizedLabel, NewTerm};
|
||||
use sqlx::PgPool;
|
||||
|
||||
#[sqlx::test]
|
||||
async fn vocabulary_create_and_lookup(pool: PgPool) {
|
||||
let db = Db::from_pool(pool);
|
||||
let v = vocab::create_vocabulary(db.pool(), "material")
|
||||
let mut tx = db.pool().begin().await.unwrap();
|
||||
let v = vocab::create_vocabulary(&mut tx, AuditActor::System, "material")
|
||||
.await
|
||||
.unwrap();
|
||||
tx.commit().await.unwrap();
|
||||
|
||||
let found = vocab::vocabulary_by_key(db.pool(), "material")
|
||||
.await
|
||||
@@ -27,13 +29,16 @@ async fn vocabulary_create_and_lookup(pool: PgPool) {
|
||||
#[sqlx::test]
|
||||
async fn term_with_multilingual_labels_round_trips(pool: PgPool) {
|
||||
let db = Db::from_pool(pool);
|
||||
let v = vocab::create_vocabulary(db.pool(), "material")
|
||||
let mut tx = db.pool().begin().await.unwrap();
|
||||
let v = vocab::create_vocabulary(&mut tx, AuditActor::System, "material")
|
||||
.await
|
||||
.unwrap();
|
||||
tx.commit().await.unwrap();
|
||||
|
||||
let mut tx = db.pool().begin().await.unwrap();
|
||||
let term_id = vocab::add_term(
|
||||
&mut tx,
|
||||
AuditActor::System,
|
||||
&NewTerm {
|
||||
vocabulary_id: v.id,
|
||||
external_uri: Some("http://vocab.getty.edu/aat/300011914".into()),
|
||||
@@ -76,13 +81,16 @@ async fn term_with_multilingual_labels_round_trips(pool: PgPool) {
|
||||
#[sqlx::test]
|
||||
async fn term_with_no_labels_round_trips_empty(pool: PgPool) {
|
||||
let db = Db::from_pool(pool);
|
||||
let v = vocab::create_vocabulary(db.pool(), "material")
|
||||
let mut tx = db.pool().begin().await.unwrap();
|
||||
let v = vocab::create_vocabulary(&mut tx, AuditActor::System, "material")
|
||||
.await
|
||||
.unwrap();
|
||||
tx.commit().await.unwrap();
|
||||
|
||||
let mut tx = db.pool().begin().await.unwrap();
|
||||
let term_id = vocab::add_term(
|
||||
&mut tx,
|
||||
AuditActor::System,
|
||||
&NewTerm {
|
||||
vocabulary_id: v.id,
|
||||
external_uri: None,
|
||||
@@ -103,10 +111,14 @@ async fn term_with_no_labels_round_trips_empty(pool: PgPool) {
|
||||
#[sqlx::test]
|
||||
async fn duplicate_vocabulary_key_is_rejected(pool: PgPool) {
|
||||
let db = Db::from_pool(pool);
|
||||
vocab::create_vocabulary(db.pool(), "material")
|
||||
let mut tx = db.pool().begin().await.unwrap();
|
||||
vocab::create_vocabulary(&mut tx, AuditActor::System, "material")
|
||||
.await
|
||||
.unwrap();
|
||||
let err = vocab::create_vocabulary(db.pool(), "material")
|
||||
tx.commit().await.unwrap();
|
||||
|
||||
let mut tx = db.pool().begin().await.unwrap();
|
||||
let err = vocab::create_vocabulary(&mut tx, AuditActor::System, "material")
|
||||
.await
|
||||
.unwrap_err();
|
||||
assert!(
|
||||
@@ -118,16 +130,19 @@ async fn duplicate_vocabulary_key_is_rejected(pool: PgPool) {
|
||||
#[sqlx::test]
|
||||
async fn resolve_term_checks_vocabulary_membership(pool: PgPool) {
|
||||
let db = Db::from_pool(pool);
|
||||
let material = vocab::create_vocabulary(db.pool(), "material")
|
||||
let mut tx = db.pool().begin().await.unwrap();
|
||||
let material = vocab::create_vocabulary(&mut tx, AuditActor::System, "material")
|
||||
.await
|
||||
.unwrap();
|
||||
let technique = vocab::create_vocabulary(db.pool(), "technique")
|
||||
let technique = vocab::create_vocabulary(&mut tx, AuditActor::System, "technique")
|
||||
.await
|
||||
.unwrap();
|
||||
tx.commit().await.unwrap();
|
||||
|
||||
let mut tx = db.pool().begin().await.unwrap();
|
||||
let term_id = vocab::add_term(
|
||||
&mut tx,
|
||||
AuditActor::System,
|
||||
&NewTerm {
|
||||
vocabulary_id: material.id,
|
||||
external_uri: None,
|
||||
|
||||
Reference in New Issue
Block a user