feat: rename + delete vocabularies, blocked when in use (#30)
This commit is contained in:
@@ -313,3 +313,75 @@ async fn delete_term_blocks_when_referenced_then_succeeds(pool: PgPool) {
|
||||
.unwrap();
|
||||
assert_eq!(gone, DeleteOutcome::NotFound);
|
||||
}
|
||||
|
||||
#[sqlx::test(migrations = "../db/migrations")]
|
||||
async fn rename_vocabulary_changes_key(pool: PgPool) {
|
||||
let db = Db::from_pool(pool);
|
||||
let mut tx = db.pool().begin().await.unwrap();
|
||||
let v = vocab::create_vocabulary(&mut tx, AuditActor::System, "old")
|
||||
.await
|
||||
.unwrap();
|
||||
let existed = vocab::rename_vocabulary(&mut tx, AuditActor::System, v.id, "new")
|
||||
.await
|
||||
.unwrap();
|
||||
assert!(existed);
|
||||
tx.commit().await.unwrap();
|
||||
|
||||
assert!(
|
||||
vocab::vocabulary_by_key(db.pool(), "new")
|
||||
.await
|
||||
.unwrap()
|
||||
.is_some()
|
||||
);
|
||||
assert!(
|
||||
vocab::vocabulary_by_key(db.pool(), "old")
|
||||
.await
|
||||
.unwrap()
|
||||
.is_none()
|
||||
);
|
||||
}
|
||||
|
||||
#[sqlx::test(migrations = "../db/migrations")]
|
||||
async fn delete_vocabulary_blocks_when_it_has_terms(pool: PgPool) {
|
||||
use db::DeleteOutcome;
|
||||
|
||||
let db = Db::from_pool(pool);
|
||||
let mut tx = db.pool().begin().await.unwrap();
|
||||
let v = vocab::create_vocabulary(&mut tx, AuditActor::System, "material")
|
||||
.await
|
||||
.unwrap();
|
||||
vocab::add_term(
|
||||
&mut tx,
|
||||
AuditActor::System,
|
||||
&NewTerm {
|
||||
vocabulary_id: v.id,
|
||||
external_uri: None,
|
||||
labels: vec![LocalizedLabel {
|
||||
lang: "sv".into(),
|
||||
label: "Trä".into(),
|
||||
}],
|
||||
},
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let blocked = vocab::delete_vocabulary(&mut tx, AuditActor::System, v.id)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(blocked, DeleteOutcome::InUse { count: 1 });
|
||||
|
||||
let empty = vocab::create_vocabulary(&mut tx, AuditActor::System, "empty")
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
vocab::delete_vocabulary(&mut tx, AuditActor::System, empty.id)
|
||||
.await
|
||||
.unwrap(),
|
||||
DeleteOutcome::Deleted
|
||||
);
|
||||
|
||||
let gone = vocab::delete_vocabulary(&mut tx, AuditActor::System, empty.id)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(gone, DeleteOutcome::NotFound);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user