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
@@ -263,3 +263,76 @@ async fn an_archived_company_is_no_longer_offered(pool: PgPool) {
|
||||
.unwrap();
|
||||
assert_eq!(actions, vec!["create", "archive", "restore"]);
|
||||
}
|
||||
|
||||
#[sqlx::test(migrator = "visa::db::MIGRATOR")]
|
||||
async fn the_office_position_is_read_from_what_people_paste(pool: PgPool) {
|
||||
let app = local(pool.clone());
|
||||
let name = ("name", "Test Works Co., Ltd.");
|
||||
for (pasted, message) in [
|
||||
("99.0082, 18.7965", "outside Thailand"),
|
||||
(
|
||||
"https://maps.app.goo.gl/AbCdEf123",
|
||||
"A short link holds no position",
|
||||
),
|
||||
("next to the market", "Enter the latitude and longitude"),
|
||||
] {
|
||||
let r = app
|
||||
.post("/companies", &[name, ("office_gps", pasted)])
|
||||
.await;
|
||||
assert_eq!(r.status, StatusCode::UNPROCESSABLE_ENTITY, "{pasted}");
|
||||
assert!(r.text().contains(message), "{pasted}: {}", r.text());
|
||||
}
|
||||
|
||||
// a link to the place on Google Maps
|
||||
let r = app
|
||||
.post(
|
||||
"/companies",
|
||||
&[
|
||||
name,
|
||||
(
|
||||
"office_gps",
|
||||
"https://www.google.com/maps/place/Demo+Tower/@18.7965,99.0082,17z/data=!3m1",
|
||||
),
|
||||
],
|
||||
)
|
||||
.await;
|
||||
assert_eq!(r.status, StatusCode::SEE_OTHER, "{}", r.body);
|
||||
let id = company_from(r.location());
|
||||
let stored = || async {
|
||||
sqlx::query_scalar::<_, String>("SELECT office_gps FROM companies WHERE id = $1")
|
||||
.bind(id)
|
||||
.fetch_one(&pool)
|
||||
.await
|
||||
.unwrap()
|
||||
};
|
||||
assert_eq!(stored().await, "18.796500, 99.008200");
|
||||
let page = app.get(&format!("/companies/{id}")).await.text();
|
||||
assert!(page.contains("18.796500, 99.008200"), "{page}");
|
||||
assert!(
|
||||
page.contains("https://www.openstreetmap.org/?mlat=18.796500&mlon=99.008200"),
|
||||
"{page}"
|
||||
);
|
||||
assert!(page.contains("https://www.google.com/maps/search/?api=1&query=18.796500,99.008200"));
|
||||
assert!(page.contains("No photo of the office yet"));
|
||||
|
||||
// degrees, minutes and seconds; the audit log names the field
|
||||
let r = app
|
||||
.post(
|
||||
&format!("/companies/{id}"),
|
||||
&[name, ("office_gps", "18°47'47.4\"N 99°00'29.5\"E")],
|
||||
)
|
||||
.await;
|
||||
assert_eq!(r.status, StatusCode::SEE_OTHER, "{}", r.body);
|
||||
assert_eq!(stored().await, "18.796500, 99.008194");
|
||||
assert_eq!(
|
||||
audit_fields(&pool, "company", id, "update").await,
|
||||
vec![vec!["office_gps".to_string()]]
|
||||
);
|
||||
|
||||
// and it can be taken out again
|
||||
let r = app.post(&format!("/companies/{id}"), &[name]).await;
|
||||
assert_eq!(r.status, StatusCode::SEE_OTHER, "{}", r.body);
|
||||
assert_eq!(stored().await, "");
|
||||
let page = app.get(&format!("/companies/{id}")).await.text();
|
||||
assert!(page.contains("Add the GPS position"), "{page}");
|
||||
}
|
||||
Reference in new issue
Block a user