Lines
100 %
Functions
Branches
use sqlx::PgPool;
use uuid::Uuid;
use super::test_seed::{seed_account, seed_user};
use crate::ctx::ScriptCtx;
use crate::envelope::ResponsePayload;
use crate::response::parse_response;
use crate::session::Session;
async fn call(user_id: Uuid, form: &str) -> anyhow::Result<ResponsePayload> {
let mut session = Session::new(ScriptCtx::new(user_id))?;
let wire = session.handle_form(&format!("(:id 1 :form {form})")).await;
Ok(parse_response(&wire)?.payload)
}
#[sqlx::test(migrator = "server::db::MIGRATOR")]
async fn handler_case_args_catches_a_blank_tag_name(pool: PgPool) -> anyhow::Result<()> {
let _guard = server::db::install_test_pool(pool.clone());
let user = seed_user(&pool).await?;
let account = seed_account(user, "Cafe").await?;
let blank = format!(r#"(set-account-tag "{account}" "" "x")"#);
let caught = call(
user,
&format!("(handler-case {blank} (args (e) \"caught\"))"),
)
.await?;
let uncaught = call(user, &blank).await?;
assert_eq!(
caught,
ResponsePayload::Value(nomiscript::Value::String("caught".to_string()))
);
assert!(
matches!(&uncaught, ResponsePayload::Error { code, .. } if code.as_symbol() == "args"),
"{uncaught:?}"
Ok(())
async fn handler_case_args_catches_a_bad_id_in_a_plain_native(pool: PgPool) -> anyhow::Result<()> {
r#"(handler-case (get-balance "x") (args (e) "caught"))"#,
let uncaught = call(user, r#"(get-balance "x")"#).await?;