Lines
85.71 %
Functions
60 %
Branches
100 %
//! Error codes and messages of `load-form` that the typed `load` must keep.
use sqlx::PgPool;
use uuid::Uuid;
use super::load_form;
use super::test_edit::{Fx, condition, fx};
use super::tests_edit_load::{leg, raw_transaction};
async fn rejected(fx: &Fx, name: &str, id: &str) -> anyhow::Result<(String, String)> {
let err = load_form(fx.user, name, id)
.await
.err()
.ok_or_else(|| anyhow::anyhow!("load was accepted"))?;
let condition = condition(&err);
Ok((condition.code, condition.message))
}
#[sqlx::test(migrator = "server::db::MIGRATOR")]
async fn malformed_id_is_an_args_error(pool: PgPool) -> anyhow::Result<()> {
let _guard = server::db::install_test_pool(pool.clone());
let fx = fx(&pool).await?;
let (code, message) = rejected(&fx, "transaction-edit", "nope").await?;
assert_eq!(code, "args");
assert_eq!(message, "invalid transaction id 'nope'");
Ok(())
async fn missing_transaction_is_a_not_found_error(pool: PgPool) -> anyhow::Result<()> {
let id = Uuid::new_v4().to_string();
let (code, message) = rejected(&fx, "transaction-edit", &id).await?;
assert_eq!(code, "not-found");
assert_eq!(message, "Transaction not found");
async fn unknown_form_is_an_args_error(pool: PgPool) -> anyhow::Result<()> {
let (code, message) = rejected(&fx, "nope", &Uuid::new_v4().to_string()).await?;
assert_eq!(message, "unknown form 'nope'");
async fn edit_refusal_is_an_args_error_with_its_reason(pool: PgPool) -> anyhow::Result<()> {
let tx = raw_transaction(&fx, |tx| {
vec![
leg(&fx, tx, fx.cash, -100),
leg(&fx, tx, fx.food, 60),
leg(&fx, tx, fx.food, 40),
]
})
.await?;
let (code, message) = rejected(&fx, "transaction-edit", &tx.to_string()).await?;
assert!(message.contains("paired"), "{message}");
async fn a_closed_pool_keeps_its_unavailable_condition(pool: PgPool) -> anyhow::Result<()> {
pool.close().await;
let err = load_form(fx.user, "transaction-edit", &Uuid::new_v4().to_string())
assert_eq!(
crate::host_failure::condition_code(&err),
Some(crate::envelope::ErrorCode::UNAVAILABLE),
"{err}"
);