Phase 6: the Non-B extension pack, checked and printed as one PDF
The pack for an extension of stay based on work, item by item in the
officer's order, each with its state at the date of the application:
generated, has blanks, uploaded, missing, out of date, no date, or not
needed for this person.
- src/pack/mod.rs: the rules as a pure function of the records and the
documents, a unit test per rule. Copies belong to their record (the
current passport, the last arrival and its TDAC, the re-entry permit it
came back on, every extension since the passport was issued, the last
90-day report, the current address, the work permit); the company
certificate and BOJ.5 count six months from their certification, the
balance sheet 17 months from its year's end, PND.1, SPS 1-10 and PP.30
the last three months, PND.91 the latest year; two photos of the office.
Sources in docs/PLAN.md (thailand.go.th 006_008, Immigration Division 1).
- A Pack tab: the six parts, each item's files and form, and what fixes it
(the upload with the kind and record chosen, through the new ?kind= on
the Documents tab and on a company's page; a document's date; a record).
The application's fields are the Forms tab's, and both tabs carry them.
- /people/{id}/pack.pdf (src/pack/pdf.rs): a cover sheet with the contents
page by page and what to sign and bring, the five forms, then every copy:
uploaded PDFs as they are (a PDF 2.0 upload makes the pack 2.0), images
fitted on A4 and turned as their EXIF orientation says, a page in place of
a file that cannot be read; bookmarks per item. krilla gains its
raster-images feature. The audit logs the forms' codes and a view or
download of each document that went in.
- A company's page shows its part of every employee's pack.
- The extension deadline links to the pack; at 390 px the six tabs fit, as
"Visa and stay" reads "Stay" on phones.
- Demo data shows every state.
- The Forms tab showed "Back about" and "Purpose" empty: the template read
app.back and app.purpose, which serialize as "return" and "for".
docs/PLAN.md: phase 6 done, open question 2 settled (the office is the
application's), phase 7 planned from Alex's answers: the client link, the
MRZ from a phone photo, later the signed agreement; reminders move to 8.
Checks: cargo fmt, clippy -D warnings, 97 unit and 47 integration tests;
layout_check 0 problems (pack, company, forms, dashboard, person; light,
dark, desk, phone); the tabs measured at 390 and 360 px; the pack PDF
rendered and looked at, an EXIF-turned JPEG upright.
This commit is contained in:
1 parent
990d5c88a4
commit
fc8c1b6a44
26 files changed
+3367
-59
No files matched your search
@@ -9,6 +9,7 @@ mod companies;
|
||||
mod deadlines;
|
||||
mod documents;
|
||||
mod garage;
|
||||
mod pack;
|
||||
mod pages;
|
||||
mod papers;
|
||||
mod people;
|
||||
|
||||
+183
@@ -0,0 +1,183 @@
|
||||
//! 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("<li class=\"ci\"")
|
||||
.map_or(rest.len(), |e| e + 1);
|
||||
&rest[..end]
|
||||
}
|
||||
|
||||
fn pages(pdf: &[u8]) -> 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</a>"), "{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("<option value=\"pnd91\" selected>"));
|
||||
let r = app.get(&format!("/companies/{company}?kind=pp30")).await;
|
||||
let t = r.text();
|
||||
assert!(t.contains("<option value=\"pp30\" selected>"), "{t}");
|
||||
// the company's page shows its part of every pack
|
||||
assert!(t.contains("For the extension packs"));
|
||||
assert!(item(&t, "shareholders").contains("Out of date"));
|
||||
// the deadline of the extension leads to the pack
|
||||
let t = app.get(&format!("/people/{id}")).await.text();
|
||||
assert!(
|
||||
t.contains(&format!("href=\"/people/{id}/pack\">Prepare the pack")),
|
||||
"{t}"
|
||||
);
|
||||
}
|
||||
|
||||
#[sqlx::test(migrator = "visa::db::MIGRATOR")]
|
||||
async fn the_pdf_is_the_cover_the_forms_and_the_copies_and_it_is_audited(pool: PgPool) {
|
||||
let (app, id, company) = seeded(&pool).await;
|
||||
let r = app.get(&format!("/people/{id}/pack.pdf")).await;
|
||||
assert_eq!(r.status, StatusCode::OK, "{}", r.body);
|
||||
assert_eq!(r.header("content-type"), "application/pdf");
|
||||
assert_eq!(r.header("cache-control"), "private, no-store");
|
||||
assert!(
|
||||
r.header("content-disposition")
|
||||
.contains("MUSTERMANN Erika - Extension pack - "),
|
||||
"{}",
|
||||
r.header("content-disposition")
|
||||
);
|
||||
let sizes = pages(&r.bytes);
|
||||
// the cover, six pages of forms, nine copies of Erika's and eight of the
|
||||
// employer's (the old BOJ.5 stays out)
|
||||
assert_eq!(sizes.len(), 1 + 6 + 9 + 8, "{sizes:?}");
|
||||
// the passport's photo page, a picture wider than high, lies on its side
|
||||
assert!(
|
||||
sizes
|
||||
.iter()
|
||||
.any(|(w, h)| (w - 842.0).abs() < 1.0 && (h - 595.0).abs() < 1.0)
|
||||
);
|
||||
|
||||
let rows: Vec<(String, String, Option<i64>, Option<i64>)> = sqlx::query_as(
|
||||
"SELECT action, entity, person_id, company_id FROM audit_log \
|
||||
WHERE entity IN ('form', 'document') AND actor <> 'seed' ORDER BY id",
|
||||
)
|
||||
.fetch_all(&pool)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(rows.len(), 1 + 17, "{rows:?}");
|
||||
assert!(rows.iter().all(|r| r.0 == "view" && r.2 == Some(id)));
|
||||
let of_company = rows.iter().filter(|r| r.3 == Some(company)).count();
|
||||
assert_eq!(of_company, 8);
|
||||
let codes: Vec<String> =
|
||||
sqlx::query_scalar("SELECT unnest(fields) FROM audit_log WHERE entity = 'form'")
|
||||
.fetch_all(&pool)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(codes, ["TM.7", "STM.2", "STM.9", "STM.11", "STM.1"]);
|
||||
|
||||
// a file that cannot be read gets a page of its own, and no audit row
|
||||
let tdac: i64 =
|
||||
sqlx::query_scalar("SELECT id FROM documents WHERE person_id = $1 AND kind = 'tdac'")
|
||||
.bind(id)
|
||||
.fetch_one(&pool)
|
||||
.await
|
||||
.unwrap();
|
||||
app.st.files.as_ref().unwrap().remove(tdac).await.unwrap();
|
||||
let r = app.get(&format!("/people/{id}/pack.pdf?download=1")).await;
|
||||
assert_eq!(r.status, StatusCode::OK, "{}", r.body);
|
||||
assert!(r.header("content-disposition").starts_with("attachment;"));
|
||||
assert_eq!(pages(&r.bytes).len(), 24);
|
||||
let downloads: i64 = sqlx::query_scalar(
|
||||
"SELECT count(*) FROM audit_log WHERE action = 'download' AND entity = 'document'",
|
||||
)
|
||||
.fetch_one(&pool)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(downloads, 16);
|
||||
}
|
||||
@@ -139,6 +139,10 @@ async fn every_page_renders_with_demo_data(pool: PgPool) {
|
||||
format!("/people/{erika}/forms"),
|
||||
"This application".to_string(),
|
||||
),
|
||||
(
|
||||
format!("/people/{erika}/pack"),
|
||||
"Extension pack, work (Non-B)".to_string(),
|
||||
),
|
||||
];
|
||||
for kind in visa::records::STAY {
|
||||
pages.push((
|
||||
|
||||
@@ -137,6 +137,11 @@ async fn the_forms_tab_lists_the_forms_and_what_they_lack(pool: PgPool) {
|
||||
.await;
|
||||
assert_eq!(r.status, StatusCode::OK);
|
||||
let t = r.text();
|
||||
// the fields keep what was entered (they serialize as "return" and "for")
|
||||
assert!(
|
||||
t.contains("name=\"return\" type=\"date\" value=\"2027-01-20\""),
|
||||
"{t}"
|
||||
);
|
||||
let tm8 = &t[t.find("id=\"form-tm8\"").unwrap()..];
|
||||
assert!(tm8.contains("Complete"), "{tm8}");
|
||||
assert!(tm8.contains("to=Germany"), "{tm8}");
|
||||
|
||||
Reference in new issue
Block a user