Pack print: A4 upright pages, small pictures at their size, card sides on one sheet
Every page of the pack is now A4 upright, so it prints as one stack. A
PDF page or a whole-page picture that lies wider than tall is turned
onto the page (a small one that fits as it is stays as it is), and a
PDF page is only made smaller, never larger.
A picture never prints larger than its resolution allows (the JFIF or
PNG dpi, else 150 dpi), nor larger than its kind's box: passport pages,
visas and stamps 180 x 128 mm, cards 130 x 90 mm, and a phone's
screenshot (the TDAC, or any picture about twice as tall as wide)
150 x 75 mm. These print at the top of the page.
Cards: a new kind "ID card", and the work permit, take two pictures in
one upload as front and back (migration 0008 documents.back_of). The
Documents tab marks them front/back, lists them together and offers
"Print both sides" (.../documents/{id}/sides.pdf); the pack prints both
on one sheet. The client link takes ID cards too. The demo seeds a TDAC
screenshot and an ID card's two sides.
Checks: fmt, clippy, 108 unit and 57 integration tests (print sizes,
dpi reading, the back following its front, the paired upload, its
audit and the sides PDF); the demo pack's pages checked as images.
The Documents tab's actions stack on a phone, so none is cut off.
This commit is contained in:
1 parent
506221ecd0
commit
1f526f17f9
16 files changed
+724
-73
No files matched your search
@@ -687,3 +687,74 @@ async fn the_office_card_takes_a_photo_and_shows_it(pool: PgPool) {
|
||||
);
|
||||
assert!(t.contains("1 more under"), "{t}");
|
||||
}
|
||||
|
||||
#[sqlx::test(migrator = "visa::db::MIGRATOR")]
|
||||
async fn a_cards_two_sides_print_on_one_page(pool: PgPool) {
|
||||
let app = local(pool.clone());
|
||||
let id = person(&app, "Card").await;
|
||||
let front = visa::seed::plain_png(428, 270);
|
||||
let mut back = visa::seed::plain_png(428, 270);
|
||||
// another picture: the same bytes would be one file twice
|
||||
back.extend_from_slice(b"\0");
|
||||
let r = app
|
||||
.upload(
|
||||
&format!("/people/{id}/documents"),
|
||||
&[("kind", "id-card")],
|
||||
&[("front.png", &front), ("back.png", &back)],
|
||||
)
|
||||
.await;
|
||||
assert_eq!(r.status, StatusCode::SEE_OTHER, "{}", r.body);
|
||||
let docs = documents::list(&pool, Owner::Person(id)).await.unwrap();
|
||||
assert_eq!(docs.len(), 2);
|
||||
// listed front first, the back pointing at it
|
||||
assert_eq!(
|
||||
(docs[0].file_name.as_str(), docs[0].back_of),
|
||||
("front.png", None)
|
||||
);
|
||||
assert_eq!(docs[1].back_of, Some(docs[0].id));
|
||||
let fields: Vec<String> = sqlx::query_scalar(
|
||||
"SELECT fields FROM audit_log WHERE entity = 'document' AND entity_id = $1",
|
||||
)
|
||||
.bind(docs[1].id)
|
||||
.fetch_one(&pool)
|
||||
.await
|
||||
.map(|f: Vec<String>| f)
|
||||
.unwrap();
|
||||
assert!(fields.contains(&"back_of".to_string()), "{fields:?}");
|
||||
|
||||
let tab = app.get(&format!("/people/{id}/documents")).await.text();
|
||||
assert!(
|
||||
tab.contains(">front</span>") && tab.contains(">back</span>"),
|
||||
"{tab}"
|
||||
);
|
||||
let sides = format!("/people/{id}/documents/{}/sides.pdf", docs[0].id);
|
||||
assert!(tab.contains(&sides), "{tab}");
|
||||
let r = app.get(&sides).await;
|
||||
assert_eq!(r.status, StatusCode::OK, "{}", r.body);
|
||||
assert!(r.bytes.starts_with(b"%PDF-"));
|
||||
assert_eq!(r.header("content-type"), "application/pdf");
|
||||
// a document without a back has no such page
|
||||
let r = app
|
||||
.get(&format!("/people/{id}/documents/{}/sides.pdf", docs[1].id))
|
||||
.await;
|
||||
assert_eq!(r.status, StatusCode::NOT_FOUND);
|
||||
|
||||
// two pictures of another kind are two documents of their own
|
||||
let r = app
|
||||
.upload(
|
||||
&format!("/people/{id}/documents"),
|
||||
&[("kind", "other")],
|
||||
&[
|
||||
("a.png", &visa::seed::plain_png(20, 20)),
|
||||
("b.png", &visa::seed::plain_png(21, 20)),
|
||||
],
|
||||
)
|
||||
.await;
|
||||
assert_eq!(r.status, StatusCode::SEE_OTHER);
|
||||
let paired: i64 =
|
||||
sqlx::query_scalar("SELECT count(*) FROM documents WHERE back_of IS NOT NULL")
|
||||
.fetch_one(&pool)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(paired, 1);
|
||||
}
|
||||
Reference in new issue
Block a user