use backbone_accounting::domain::entity::PostingSourceType;
use sqlx::PgPool;
async fn pool() -> PgPool {
let url = std::env::var("DATABASE_URL").unwrap_or_else(|_| {
"postgresql://postgres:postgres@localhost:5433/backbone_accounting".to_string()
});
PgPool::connect(&url).await.unwrap()
}
#[tokio::test]
async fn every_posting_source_in_the_database_reads_back() {
let pool = pool().await;
let labels: Vec<String> = sqlx::query_scalar(
"SELECT e.enumlabel::text FROM pg_enum e JOIN pg_type t ON t.oid = e.enumtypid
WHERE t.typname = 'posting_source_type' ORDER BY e.enumsortorder",
)
.fetch_all(&pool)
.await
.unwrap();
assert!(labels.iter().any(|l| l == "final_settlement"), "the migrations add final_settlement");
for label in &labels {
let read: Result<PostingSourceType, _> =
sqlx::query_scalar("SELECT $1::text::posting_source_type")
.bind(label)
.fetch_one(&pool)
.await;
let value = read.unwrap_or_else(|e| panic!("posting source '{label}' cannot be read: {e}"));
assert_eq!(value.to_string(), *label, "'{label}' reads back as itself");
}
}