Lines
100 %
Functions
Branches
use server::command::config::SetConfig;
use sqlx::PgPool;
use uuid::Uuid;
use super::test_seed::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)
}
fn text(value: &str) -> ResponsePayload {
ResponsePayload::Value(nomiscript::Value::String(value.to_string()))
#[sqlx::test(migrator = "server::db::MIGRATOR")]
async fn a_valid_instant_prints_in_utc_when_no_zone_is_set(pool: PgPool) -> anyhow::Result<()> {
let _guard = server::db::install_test_pool(pool.clone());
let user = seed_user(&pool).await?;
let printed = call(user, r#"(format-date "2026-11-21T08:41:07.004152Z")"#).await?;
assert_eq!(printed, text("2026-11-21 08:41"));
Ok(())
async fn the_user_zone_is_applied(pool: PgPool) -> anyhow::Result<()> {
SetConfig::new()
.user_id(user)
.name("timezone".to_string())
.value("Asia/Tokyo".to_string())
.run()
.await?;
let printed = call(user, r#"(format-date "2026-11-30T17:00:00Z")"#).await?;
assert_eq!(printed, text("2026-12-01 02:00"));
async fn a_bad_instant_is_a_catchable_args_error(pool: PgPool) -> anyhow::Result<()> {
let bad = r#"(format-date "yesterday")"#;
let caught = call(user, &format!("(handler-case {bad} (args (e) \"caught\"))")).await?;
let uncaught = call(user, bad).await?;
assert_eq!(caught, text("caught"));
assert!(
matches!(&uncaught, ResponsePayload::Error { code, message, .. }
if code.as_symbol() == "args" && message.contains("yesterday")),
"{uncaught:?}"
);