A company's office: its GPS position and a photo
The company form has a field for the office's GPS position (migration 0004, column companies.office_gps). It takes what people have at hand: the numbers Google Maps copies, a link to the place on Google Maps or OpenStreetMap, a geo: URI, or degrees, minutes and seconds. It keeps decimal degrees with six decimals and refuses a position outside Thailand, which catches a swapped pair; a short maps.app.goo.gl link is refused with a hint, as it holds no position (src/gps.rs, with unit tests). The company's page has an Office card: the position with links that open it on OpenStreetMap and Google Maps, the newest photo of the office, and a strip that uploads a photo (kind "Photo of the office") and returns to the card. The photos are documents like any other: encrypted on the server and audited. A refused photo shows its errors on the card only; office photos that are PDFs are counted under Company documents. The demo company has a position. Tests: the position read from a link, from degrees, minutes and seconds, the three refusals, the audit entry and its removal; a photo uploaded from the card, shown, and its errors placed.
This commit is contained in:
1 parent
e88bb74e1e
commit
2a6e972b68
14 files changed
+642
-8
No files matched your search
@@ -610,3 +610,76 @@ async fn the_demo_documents_open_as_what_they_are(pool: PgPool) {
|
||||
.is_empty()
|
||||
);
|
||||
}
|
||||
|
||||
/// A 1 x 1 PNG.
|
||||
const DOT_PNG: &[u8] = &[
|
||||
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52,
|
||||
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x08, 0x06, 0x00, 0x00, 0x00, 0x1f, 0x15, 0xc4,
|
||||
0x89, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x44, 0x41, 0x54, 0x78, 0x9c, 0x63, 0x00, 0x01, 0x00, 0x00,
|
||||
0x05, 0x00, 0x01, 0x0d, 0x0a, 0x2d, 0xb4, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae,
|
||||
0x42, 0x60, 0x82,
|
||||
];
|
||||
|
||||
#[sqlx::test(migrator = "visa::db::MIGRATOR")]
|
||||
async fn the_office_card_takes_a_photo_and_shows_it(pool: PgPool) {
|
||||
visa::seed::demo(&pool, visa::dates::today()).await.unwrap();
|
||||
let app = local(pool.clone());
|
||||
let company: i64 =
|
||||
sqlx::query_scalar("SELECT id FROM companies WHERE name = 'Demo Engineering Co., Ltd.'")
|
||||
.fetch_one(&pool)
|
||||
.await
|
||||
.unwrap();
|
||||
let base = format!("/companies/{company}/documents");
|
||||
let office = [("kind", "office-photo"), ("back", "office")];
|
||||
|
||||
// refused from the card: the card says so, the documents' strip does not
|
||||
let r = app.upload(&base, &office, &[("office.png", b"")]).await;
|
||||
assert_eq!(r.status, StatusCode::UNPROCESSABLE_ENTITY);
|
||||
let t = r.text();
|
||||
let (card, list) = (
|
||||
t.find("id=\"office\"").unwrap(),
|
||||
t.find("id=\"documents\"").unwrap(),
|
||||
);
|
||||
let notice = t
|
||||
.find("Nothing was uploaded")
|
||||
.expect("the card has the notice");
|
||||
assert!(
|
||||
card < notice && notice < list,
|
||||
"the notice is on the office card"
|
||||
);
|
||||
assert_eq!(t.matches("Nothing was uploaded").count(), 1, "{t}");
|
||||
|
||||
let r = app.upload(&base, &office, &[("office.png", DOT_PNG)]).await;
|
||||
assert_eq!(r.status, StatusCode::SEE_OTHER, "{}", r.body);
|
||||
assert_eq!(r.location(), format!("/companies/{company}#office"));
|
||||
let did: i64 = sqlx::query_scalar("SELECT id FROM documents WHERE company_id = $1")
|
||||
.bind(company)
|
||||
.fetch_one(&pool)
|
||||
.await
|
||||
.unwrap();
|
||||
let t = app.get(&format!("/companies/{company}")).await.text();
|
||||
assert!(
|
||||
t.contains(&format!("<img src=\"{base}/{did}/file\"")),
|
||||
"the card shows the photo: {t}"
|
||||
);
|
||||
assert!(t.contains("Add a newer photo"));
|
||||
assert!(
|
||||
t.contains("18.796500, 99.008200"),
|
||||
"the demo office's position"
|
||||
);
|
||||
let r = app.get(&format!("{base}/{did}/file")).await;
|
||||
assert_eq!(r.bytes, DOT_PNG);
|
||||
assert_eq!(r.header("content-type"), "image/png");
|
||||
|
||||
// a PDF of the office is listed, but the card shows only pictures
|
||||
let r = app
|
||||
.upload(&base, &office, &[("office.pdf", &pdf("office plan"))])
|
||||
.await;
|
||||
assert_eq!(r.status, StatusCode::SEE_OTHER, "{}", r.body);
|
||||
let t = app.get(&format!("/companies/{company}")).await.text();
|
||||
assert!(
|
||||
t.contains(&format!("<img src=\"{base}/{did}/file\"")),
|
||||
"{t}"
|
||||
);
|
||||
assert!(t.contains("1 more under"), "{t}");
|
||||
}
|
||||
Reference in new issue
Block a user