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.
226 lines
8.4 KiB
Rust
226 lines
8.4 KiB
Rust
//! The Forms tab: the Immigration Bureau's forms filled in from the records,
|
|
//! what each still lacks, the PDFs and their audit entries.
|
|
|
|
use axum::http::StatusCode;
|
|
use sqlx::PgPool;
|
|
use visa::papers::values::{self, Application};
|
|
|
|
use crate::common::local;
|
|
|
|
async fn erika(pool: &PgPool) -> i64 {
|
|
sqlx::query_scalar("SELECT id FROM people WHERE surname = 'Mustermann'")
|
|
.fetch_one(pool)
|
|
.await
|
|
.unwrap()
|
|
}
|
|
|
|
fn pages(pdf: &[u8]) -> usize {
|
|
krilla::pdf::Pdf::new(pdf.to_vec()).unwrap().pages().len()
|
|
}
|
|
|
|
#[sqlx::test(migrator = "visa::db::MIGRATOR")]
|
|
async fn the_values_come_from_the_records(pool: PgPool) {
|
|
let today = visa::dates::today();
|
|
visa::seed::demo(&pool, today).await.unwrap();
|
|
let id = erika(&pool).await;
|
|
let facts = values::load(&pool, id).await.unwrap().unwrap();
|
|
let app = Application::default().with_defaults(&facts, today);
|
|
assert_eq!(
|
|
app.reason,
|
|
"To continue working for Demo Engineering Co., Ltd. as Electrical engineer"
|
|
);
|
|
assert_eq!((app.days.as_str(), app.entries.as_str()), ("365", "single"));
|
|
let v = values::values(&facts, &app, today);
|
|
let plus = |days: i64| today + chrono::TimeDelta::days(days);
|
|
let expect = [
|
|
("family_name", "MUSTERMANN".to_string()),
|
|
("first_name", "ERIKA".to_string()),
|
|
("full_name", "ERIKA MUSTERMANN".to_string()),
|
|
("title", "Ms".to_string()),
|
|
("nationality", "GERMANY".to_string()),
|
|
("birth_place", "BERLIN".to_string()),
|
|
("birth_month", "AUGUST".to_string()),
|
|
("passport_no", "C01X00T47".to_string()),
|
|
("passport_issued_at", "STADT KOELN".to_string()),
|
|
("passport_expiry_year", "2031".to_string()),
|
|
("visa_type", "NON-IMMIGRANT B".to_string()),
|
|
("visa_kind", "non-immigrant".to_string()),
|
|
("visa_issued_at", "ROYAL THAI EMBASSY, BERLIN".to_string()),
|
|
// the last arrival: back from a trip on the re-entry permit
|
|
("arrived_by", "TG111".to_string()),
|
|
("arrived_from", "SINGAPORE".to_string()),
|
|
(
|
|
"arrival_port",
|
|
"CHIANG MAI INTERNATIONAL AIRPORT".to_string(),
|
|
),
|
|
(
|
|
"permitted_day",
|
|
chrono::Datelike::day(&plus(60)).to_string(),
|
|
),
|
|
("position", "ELECTRICAL ENGINEER".to_string()),
|
|
("salary", "95,000".to_string()),
|
|
("company_name", "DEMO ENGINEERING CO., LTD.".to_string()),
|
|
("company_capital", "5,000,000".to_string()),
|
|
("revenue", "48,500,000".to_string()),
|
|
("figures_year", "2025".to_string()),
|
|
("thai_staff", "24".to_string()),
|
|
("coordinator", "WANIDA MEECHAI".to_string()),
|
|
("days", "365".to_string()),
|
|
(
|
|
"reason_short",
|
|
"WORKING AT DEMO ENGINEERING CO., LTD.".to_string(),
|
|
),
|
|
(
|
|
"company_written_at",
|
|
"DEMO ENGINEERING CO., LTD.".to_string(),
|
|
),
|
|
("road", "SOI 7, HUAY KAEW ROAD".to_string()),
|
|
("extension_nth", "2".to_string()),
|
|
];
|
|
for (key, want) in expect {
|
|
assert_eq!(v.get(key), Some(&want), "{key}");
|
|
}
|
|
// nothing is missing for an extension but the employer's certificate
|
|
// date, which only the company's documents give
|
|
for paper in visa::papers::EXTENSION {
|
|
let lacks: Vec<&str> = values::missing(paper, &v, &facts)
|
|
.iter()
|
|
.map(|m| m.what)
|
|
.collect();
|
|
if paper == visa::papers::Paper::Stm1 {
|
|
assert_eq!(
|
|
lacks,
|
|
["The employer's company certificate, uploaded with its date"],
|
|
"{}",
|
|
paper.code()
|
|
);
|
|
} else {
|
|
assert!(lacks.is_empty(), "{}: {lacks:?}", paper.code());
|
|
}
|
|
}
|
|
}
|
|
|
|
#[sqlx::test(migrator = "visa::db::MIGRATOR")]
|
|
async fn the_forms_tab_lists_the_forms_and_what_they_lack(pool: PgPool) {
|
|
let today = visa::dates::today();
|
|
visa::seed::demo(&pool, today).await.unwrap();
|
|
let app = local(pool.clone());
|
|
let id = erika(&pool).await;
|
|
let r = app.get(&format!("/people/{id}/forms")).await;
|
|
assert_eq!(r.status, StatusCode::OK, "{}", r.body);
|
|
let t = r.text();
|
|
for code in ["TM.7", "STM.2", "STM.9", "STM.11", "STM.1", "TM.47", "TM.8"] {
|
|
assert!(t.contains(code), "{code}");
|
|
}
|
|
assert!(t.contains(
|
|
"value=\"To continue working for Demo Engineering Co., Ltd. as Electrical engineer\""
|
|
));
|
|
assert!(
|
|
t.contains(&format!("/people/{id}/forms/tm7.pdf?date={today}")),
|
|
"{t}"
|
|
);
|
|
// the trip is still blank on TM.8, and the certificate's date on STM.1
|
|
let tm8 = &t[t.find("id=\"form-tm8\"").unwrap()..];
|
|
assert!(tm8.contains("The trip"), "{tm8}");
|
|
let stm1 = &t[t.find("id=\"form-stm1\"").unwrap()..t.find("id=\"form-tm47\"").unwrap()];
|
|
assert!(stm1.contains("company certificate"), "{stm1}");
|
|
assert!(
|
|
stm1.contains("#documents"),
|
|
"the link goes to the company's documents"
|
|
);
|
|
|
|
// with the trip, TM.8 is complete and its link carries the trip
|
|
let r = app
|
|
.get(&format!(
|
|
"/people/{id}/forms?to=Germany&leave=2027-01-05&return=2027-01-20&entries=multiple"
|
|
))
|
|
.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}");
|
|
|
|
// wrong values are marked on the tab; a PDF with them goes back there
|
|
let r = app
|
|
.get(&format!("/people/{id}/forms?date=202611-18&days=many"))
|
|
.await;
|
|
assert_eq!(r.status, StatusCode::UNPROCESSABLE_ENTITY);
|
|
assert!(
|
|
r.text().contains("Enter the number of days"),
|
|
"{}",
|
|
r.text()
|
|
);
|
|
let r = app
|
|
.get(&format!("/people/{id}/forms/tm7.pdf?days=many"))
|
|
.await;
|
|
assert_eq!(r.status, StatusCode::SEE_OTHER);
|
|
assert!(r.location().starts_with(&format!("/people/{id}/forms?")));
|
|
}
|
|
|
|
#[sqlx::test(migrator = "visa::db::MIGRATOR")]
|
|
async fn a_form_is_the_official_pages_filled_in_and_audited(pool: PgPool) {
|
|
let today = visa::dates::today();
|
|
visa::seed::demo(&pool, today).await.unwrap();
|
|
let app = local(pool.clone());
|
|
let id = erika(&pool).await;
|
|
|
|
let r = app.get(&format!("/people/{id}/forms/tm7.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").starts_with("inline;"));
|
|
assert!(
|
|
r.header("content-disposition")
|
|
.contains(&format!("MUSTERMANN Erika - TM.7 - {today}.pdf")),
|
|
"{}",
|
|
r.header("content-disposition")
|
|
);
|
|
assert_eq!(pages(&r.bytes), 2, "TM.7 has two pages");
|
|
|
|
let r = app
|
|
.get(&format!("/people/{id}/forms/extension.pdf?download=1"))
|
|
.await;
|
|
assert_eq!(r.status, StatusCode::OK);
|
|
assert!(r.header("content-disposition").starts_with("attachment;"));
|
|
assert_eq!(pages(&r.bytes), 6, "TM.7, STM.2, STM.9, STM.11 and STM.1");
|
|
let r = app.get(&format!("/people/{id}/forms/tm8.pdf")).await;
|
|
assert_eq!(pages(&r.bytes), 2);
|
|
|
|
// what was opened and saved, by whom; the form's values are not logged
|
|
let rows: Vec<(String, Vec<String>)> = sqlx::query_as(
|
|
"SELECT action, fields FROM audit_log WHERE entity = 'form' AND person_id = $1 ORDER BY id",
|
|
)
|
|
.bind(id)
|
|
.fetch_all(&pool)
|
|
.await
|
|
.unwrap();
|
|
assert_eq!(
|
|
rows,
|
|
[
|
|
("view".to_string(), vec!["TM.7".to_string()]),
|
|
(
|
|
"download".to_string(),
|
|
["TM.7", "STM.2", "STM.9", "STM.11", "STM.1"]
|
|
.map(String::from)
|
|
.to_vec()
|
|
),
|
|
("view".to_string(), vec!["TM.8".to_string()]),
|
|
]
|
|
);
|
|
let t = app.get(&format!("/activity?person={id}")).await.text();
|
|
assert!(t.contains("TM.7, STM.2, STM.9, STM.11, STM.1"), "{t}");
|
|
|
|
for bad in ["tm99.pdf", "tm7", "extension.txt"] {
|
|
let r = app.get(&format!("/people/{id}/forms/{bad}")).await;
|
|
assert_eq!(r.status, StatusCode::NOT_FOUND, "{bad}");
|
|
}
|
|
let r = app.get("/people/999999/forms/tm7.pdf").await;
|
|
assert_eq!(r.status, StatusCode::NOT_FOUND);
|
|
}
|