test(db): cover zero-label term and duplicate vocabulary key; use try_get in vocabulary_by_key

This commit is contained in:
2026-06-02 08:52:58 +02:00
parent 5dc07ddf4c
commit 345073b130
2 changed files with 50 additions and 4 deletions
+42
View File
@@ -73,6 +73,48 @@ async fn term_with_multilingual_labels_round_trips(pool: PgPool) {
assert_eq!(listed[0].id, term_id);
}
#[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")
.await
.unwrap();
let mut tx = db.pool().begin().await.unwrap();
let term_id = vocab::add_term(
&mut *tx,
&NewTerm {
vocabulary_id: v.id,
external_uri: None,
labels: vec![],
},
)
.await
.unwrap();
tx.commit().await.unwrap();
let term = vocab::term_by_id(db.pool(), term_id)
.await
.unwrap()
.unwrap();
assert!(term.labels.is_empty());
}
#[sqlx::test]
async fn duplicate_vocabulary_key_is_rejected(pool: PgPool) {
let db = Db::from_pool(pool);
vocab::create_vocabulary(db.pool(), "material")
.await
.unwrap();
let err = vocab::create_vocabulary(db.pool(), "material")
.await
.unwrap_err();
assert!(
matches!(err, sqlx::Error::Database(_)),
"expected a unique-violation DB error, got: {err:?}"
);
}
#[sqlx::test]
async fn resolve_term_checks_vocabulary_membership(pool: PgPool) {
let db = Db::from_pool(pool);