//! The Pack tab: the extension pack's checklist with each item's state, the //! employer's part on the company's page, and the whole pack as one PDF with //! its audit entries. use axum::http::StatusCode; use sqlx::PgPool; use crate::common::{App, local}; async fn seeded(pool: &PgPool) -> (App, i64, i64) { let today = visa::dates::today(); visa::seed::demo(pool, today).await.unwrap(); let app = local(pool.clone()); let store = app.st.files.as_ref().unwrap(); visa::seed::demo_documents(pool, store, today) .await .unwrap(); let erika: i64 = sqlx::query_scalar("SELECT id FROM people WHERE surname = 'Mustermann'") .fetch_one(pool) .await .unwrap(); let company: i64 = sqlx::query_scalar("SELECT id FROM companies WHERE name = 'Demo Engineering Co., Ltd.'") .fetch_one(pool) .await .unwrap(); (app, erika, company) } /// The item `key` of the tab, up to the next one. fn item<'a>(page: &'a str, key: &str) -> &'a str { let at = page .find(&format!("id=\"item-{key}\"")) .unwrap_or_else(|| panic!("no item {key}")); let rest = &page[at..]; let end = rest[1..] .find("
  • Vec<(f32, f32)> { krilla::pdf::Pdf::new(pdf.to_vec()) .unwrap() .pages() .iter() .map(|p| p.render_dimensions()) .collect() } #[sqlx::test(migrator = "visa::db::MIGRATOR")] async fn the_tab_shows_each_item_with_its_state(pool: PgPool) { let (app, id, company) = seeded(&pool).await; let r = app.get(&format!("/people/{id}/pack")).await; assert_eq!(r.status, StatusCode::OK, "{}", r.body); let t = r.text(); assert!(t.contains("Extension pack, work (Non-B)"), "{t}"); assert!(t.contains("aria-current=\"page\">Pack"), "{t}"); // the forms come from the records; the copies from the documents assert!(item(&t, "tm7").contains("Generated")); assert!(item(&t, "tm7").contains(&format!("/people/{id}/forms/tm7.pdf?date="))); for key in [ "passport", "visa", "arrival", "reentry", "extensions", "tdac", "work-permit", ] { assert!( item(&t, key).contains("Uploaded"), "{key}: {}", item(&t, key) ); } // the employer's documents, each judged by its date assert!(item(&t, "company-certificate").contains("counts until")); assert!(item(&t, "shareholders").contains("Out of date")); assert!(item(&t, "pnd1").contains("3 files")); assert!(item(&t, "sps1-10").contains("No date")); assert!(item(&t, "office-photo").contains("1 of 2")); let pp30 = item(&t, "pp30"); assert!(pp30.contains("Missing"), "{pp30}"); assert!( pp30.contains(&format!("/companies/{company}?kind=pp30#upload")), "{pp30}" ); assert!(t.contains(&format!("/people/{id}/pack.pdf?date="))); // the Forms tab and the Pack tab carry the application to each other let r = app.get(&format!("/people/{id}/pack?days=180")).await; assert!(r.text().contains(&format!("/people/{id}/forms?date="))); assert!(r.text().contains("days=180")); // a wrong value is marked, and its PDF goes back to the tab let r = app.get(&format!("/people/{id}/pack?date=202611-20")).await; assert_eq!(r.status, StatusCode::UNPROCESSABLE_ENTITY); let r = app.get(&format!("/people/{id}/pack.pdf?days=many")).await; assert_eq!(r.status, StatusCode::SEE_OTHER); assert!(r.location().starts_with(&format!("/people/{id}/pack?"))); assert_eq!( app.get("/people/999999/pack").await.status, StatusCode::NOT_FOUND ); // the fixes open the upload with the kind chosen let r = app.get(&format!("/people/{id}/documents?kind=pnd91")).await; assert!(r.text().contains("