test(db): zero-label authority round-trip; doc the labels-json constant
Also fix pre-existing clippy::explicit_auto_deref in all db test files (&mut *tx → &mut tx across authority.rs and vocab.rs).
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
use domain::{Authority, AuthorityId, AuthorityKind, AuthorityRef, LocalizedLabel, NewAuthority};
|
use domain::{Authority, AuthorityId, AuthorityKind, AuthorityRef, LocalizedLabel, NewAuthority};
|
||||||
use sqlx::Row;
|
use sqlx::Row;
|
||||||
|
|
||||||
|
/// Labels aggregated per row as JSON, to read an authority and its labels in one query.
|
||||||
const LABELS_JSON: &str = "COALESCE(json_agg(json_build_object('lang', al.lang, 'label', al.label) \
|
const LABELS_JSON: &str = "COALESCE(json_agg(json_build_object('lang', al.lang, 'label', al.label) \
|
||||||
ORDER BY al.lang) FILTER (WHERE al.authority_id IS NOT NULL), '[]'::json)";
|
ORDER BY al.lang) FILTER (WHERE al.authority_id IS NOT NULL), '[]'::json)";
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ async fn authority_round_trips_with_labels(pool: PgPool) {
|
|||||||
let db = Db::from_pool(pool);
|
let db = Db::from_pool(pool);
|
||||||
|
|
||||||
let mut tx = db.pool().begin().await.unwrap();
|
let mut tx = db.pool().begin().await.unwrap();
|
||||||
let id = authority::create_authority(&mut *tx, &new_person("Carl Larsson", "Carl Larsson"))
|
let id = authority::create_authority(&mut tx, &new_person("Carl Larsson", "Carl Larsson"))
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
tx.commit().await.unwrap();
|
tx.commit().await.unwrap();
|
||||||
@@ -47,11 +47,11 @@ async fn list_by_kind_filters(pool: PgPool) {
|
|||||||
let db = Db::from_pool(pool);
|
let db = Db::from_pool(pool);
|
||||||
|
|
||||||
let mut tx = db.pool().begin().await.unwrap();
|
let mut tx = db.pool().begin().await.unwrap();
|
||||||
authority::create_authority(&mut *tx, &new_person("A", "A"))
|
authority::create_authority(&mut tx, &new_person("A", "A"))
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
authority::create_authority(
|
authority::create_authority(
|
||||||
&mut *tx,
|
&mut tx,
|
||||||
&NewAuthority {
|
&NewAuthority {
|
||||||
kind: AuthorityKind::Place,
|
kind: AuthorityKind::Place,
|
||||||
external_uri: None,
|
external_uri: None,
|
||||||
@@ -83,7 +83,7 @@ async fn resolve_authority_returns_kind(pool: PgPool) {
|
|||||||
let db = Db::from_pool(pool);
|
let db = Db::from_pool(pool);
|
||||||
|
|
||||||
let mut tx = db.pool().begin().await.unwrap();
|
let mut tx = db.pool().begin().await.unwrap();
|
||||||
let id = authority::create_authority(&mut *tx, &new_person("X", "X"))
|
let id = authority::create_authority(&mut tx, &new_person("X", "X"))
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
tx.commit().await.unwrap();
|
tx.commit().await.unwrap();
|
||||||
@@ -100,3 +100,28 @@ async fn resolve_authority_returns_kind(pool: PgPool) {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
assert!(missing.is_none());
|
assert!(missing.is_none());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[sqlx::test]
|
||||||
|
async fn authority_with_no_labels_round_trips_empty(pool: PgPool) {
|
||||||
|
let db = Db::from_pool(pool);
|
||||||
|
|
||||||
|
let mut tx = db.pool().begin().await.unwrap();
|
||||||
|
let id = authority::create_authority(
|
||||||
|
&mut tx,
|
||||||
|
&NewAuthority {
|
||||||
|
kind: AuthorityKind::Organisation,
|
||||||
|
external_uri: None,
|
||||||
|
labels: vec![],
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
tx.commit().await.unwrap();
|
||||||
|
|
||||||
|
let got = authority::authority_by_id(db.pool(), id)
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.unwrap();
|
||||||
|
assert_eq!(got.kind, AuthorityKind::Organisation);
|
||||||
|
assert!(got.labels.is_empty());
|
||||||
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ async fn term_with_multilingual_labels_round_trips(pool: PgPool) {
|
|||||||
|
|
||||||
let mut tx = db.pool().begin().await.unwrap();
|
let mut tx = db.pool().begin().await.unwrap();
|
||||||
let term_id = vocab::add_term(
|
let term_id = vocab::add_term(
|
||||||
&mut *tx,
|
&mut tx,
|
||||||
&NewTerm {
|
&NewTerm {
|
||||||
vocabulary_id: v.id,
|
vocabulary_id: v.id,
|
||||||
external_uri: Some("http://vocab.getty.edu/aat/300011914".into()),
|
external_uri: Some("http://vocab.getty.edu/aat/300011914".into()),
|
||||||
@@ -82,7 +82,7 @@ async fn term_with_no_labels_round_trips_empty(pool: PgPool) {
|
|||||||
|
|
||||||
let mut tx = db.pool().begin().await.unwrap();
|
let mut tx = db.pool().begin().await.unwrap();
|
||||||
let term_id = vocab::add_term(
|
let term_id = vocab::add_term(
|
||||||
&mut *tx,
|
&mut tx,
|
||||||
&NewTerm {
|
&NewTerm {
|
||||||
vocabulary_id: v.id,
|
vocabulary_id: v.id,
|
||||||
external_uri: None,
|
external_uri: None,
|
||||||
@@ -127,7 +127,7 @@ async fn resolve_term_checks_vocabulary_membership(pool: PgPool) {
|
|||||||
|
|
||||||
let mut tx = db.pool().begin().await.unwrap();
|
let mut tx = db.pool().begin().await.unwrap();
|
||||||
let term_id = vocab::add_term(
|
let term_id = vocab::add_term(
|
||||||
&mut *tx,
|
&mut tx,
|
||||||
&NewTerm {
|
&NewTerm {
|
||||||
vocabulary_id: material.id,
|
vocabulary_id: material.id,
|
||||||
external_uri: None,
|
external_uri: None,
|
||||||
|
|||||||
Reference in New Issue
Block a user