Lines
88.89 %
Functions
80 %
Branches
100 %
//! `submit-form` answers with a real value that a script reads directly (plan 0016 VF1).
use forms::escape_str;
use sqlx::PgPool;
use super::test_query_seed::{add_tx, fixture};
use crate::ctx::ScriptCtx;
use crate::session::Session;
async fn value_of(session: &mut Session, form: &str) -> String {
session.handle_form(&format!("(:id 1 :form {form})")).await
}
fn query(payload: &str) -> String {
format!(
"(submit-form \"transaction-query\" {})",
escape_str(payload)
)
#[sqlx::test(migrator = "server::db::MIGRATOR")]
async fn a_script_reads_the_page_plist_cells(pool: PgPool) -> anyhow::Result<()> {
let _guard = server::db::install_test_pool(pool.clone());
let f = fixture(&pool).await?;
add_tx(&f, "2024-03-01T10:00:00Z", "a").await?;
let newest = add_tx(&f, "2024-03-02T10:00:00Z", "b").await?;
let mut session = Session::new(ScriptCtx::new(f.user_id))?;
let one = query("(:limit \"1\")");
let all = query("(:limit \"5\")");
let cases = [
(format!("(car {one})"), ":ROWS".to_string()),
(format!("(car (cdr (cdr (cdr {one}))))"), "t".to_string()),
(format!("(car (cdr (cdr (cdr {all}))))"), "nil".to_string()),
(
format!("(car (cdr (cdr (cdr (cdr (cdr {all}))))))"),
"2".to_string(),
),
(format!("(car (car (car (cdr {one}))))"), ":ID".to_string()),
format!("(car (cdr (car (car (cdr {one})))))"),
format!("\"{newest}\""),
query("(:from \"2030-01-01\")"),
"(:ROWS nil :HAS-MORE nil :TOTAL 0)".to_string(),
];
for (form, expected) in cases {
assert_eq!(
value_of(&mut session, &form).await,
format!("(:id 1 :value {expected})"),
"{form}"
);
Ok(())
async fn a_mutation_still_answers_its_uuid_string(pool: PgPool) -> anyhow::Result<()> {
let form = "(submit-form \"account-create\" \"(:name \\\"Cafe\\\")\")";
let wire = value_of(&mut session, form).await;
let id = wire
.strip_prefix("(:id 1 :value \"")
.and_then(|rest| rest.strip_suffix("\")"))
.ok_or_else(|| anyhow::anyhow!("{wire}"))?;
uuid::Uuid::parse_str(id)?;
async fn a_script_still_matches_the_upper_case_keyword(pool: PgPool) -> anyhow::Result<()> {
let page = query("(:limit \"5\")");
(format!("(equal (car {page}) :rows)"), "t"),
(format!("(equal (car (cdr (cdr {page}))) :has-more)"), "t"),
(format!("(equal (car {page}) :ROWS)"), "t"),