//! The deadlines of the demo people, on the Deadlines page, the people list //! and the person's pages. use axum::http::StatusCode; use sqlx::PgPool; use crate::common::local; async fn person(pool: &PgPool, surname: &str) -> i64 { sqlx::query_scalar("SELECT id FROM people WHERE surname = $1") .bind(surname) .fetch_one(pool) .await .unwrap() } #[sqlx::test(migrator = "visa::db::MIGRATOR")] async fn the_demo_people_show_every_kind_of_deadline(pool: PgPool) { visa::seed::demo(&pool, visa::dates::today()).await.unwrap(); let app = local(pool.clone()); let r = app.get("/desk").await; assert_eq!(r.status, StatusCode::OK); let page = r.text(); for expect in [ // Tomas: the report was due 11 days ago, a week of grace is over "Late", // Jane: 60 days of visa exemption, 20 left "Extension of stay", "Under 6 months", "TM.30 for the address", // Erika: back from a trip 79 days ago "Window open", "Work permit expiry", // Sofia: still abroad with her visa "Visa valid for entry", ] { assert!(page.contains(expect), "the dashboard lacks {expect:?}"); } assert!( !page.contains("SAMPLE"), "archived people have no deadlines" ); // the most urgent first: Tomas's late report let late = page.find("Late").unwrap(); let open = page.find("Window open").unwrap(); assert!(late < open); let tomas = person(&pool, "Novak").await; let p = app.get(&format!("/people/{tomas}")).await.text(); assert!( p.contains("Basis: extension of stay for marriage to a Thai national."), "{p}" ); assert!(p.contains("Report in person and pay the 2,000 THB fine")); let erika = person(&pool, "Mustermann").await; let s = app.get(&format!("/people/{erika}/stay")).await.text(); assert!( s.contains("Basis: extension of stay for work, kept by a re-entry permit."), "{s}" ); assert!(s.contains("Online until"), "Erika may still report online"); assert!( s.contains("Demo Engineering Co., Ltd."), "the work permit names the employer" ); // the people list shows each person's next deadline: the table in a // column, the record cards with the next dates and the stay let list = app.get("/people?view=table").await.text(); assert!(list.contains("90-day report,")); let cards = app.get("/people").await.text(); assert!(cards.contains("class=\"rcards\""), "{cards}"); assert!(cards.contains("