Compare commits

..

4 Commits

Author SHA1 Message Date
b55f122f1d Merge pull request 'sanity-check-timing; fixes #488' (#535) from sanity-check-timing into staging
Some checks failed
CI/CD Pipeline / deploy-staging (push) Blocked by required conditions
CI/CD Pipeline / deploy-main (push) Blocked by required conditions
CI/CD Pipeline / test (push) Has been cancelled
Reviewed-on: #535
2024-05-22 22:41:31 +02:00
446e48020e test fails due to new sanity check (25km in 1 min :-)); started trip 2 hours ago now in tests
All checks were successful
CI/CD Pipeline / test (push) Successful in 9m25s
CI/CD Pipeline / deploy-staging (push) Has been skipped
CI/CD Pipeline / deploy-main (push) Has been skipped
2024-05-22 22:28:33 +02:00
93e3e0ef5c only allow realistic values for logbook entries
Some checks failed
CI/CD Pipeline / test (push) Failing after 14m37s
CI/CD Pipeline / deploy-staging (push) Has been skipped
CI/CD Pipeline / deploy-main (push) Has been skipped
2024-05-22 22:05:03 +02:00
8f5cc70981 Merge pull request 'automate schnupper mails' (#534) from automate-schnupper-mails into main
All checks were successful
CI/CD Pipeline / test (push) Successful in 9m19s
CI/CD Pipeline / deploy-staging (push) Has been skipped
CI/CD Pipeline / deploy-main (push) Successful in 5m8s
Reviewed-on: #534
2024-05-22 08:51:41 +02:00
3 changed files with 36 additions and 19 deletions

View File

@ -67,6 +67,16 @@ test("Cox can start and finish trip", async ({ page }, testInfo) => {
await expect(page.getByRole("listbox")).toContainText( await expect(page.getByRole("listbox")).toContainText(
"Nur 2 Ruderer können hinzugefügt werden", "Nur 2 Ruderer können hinzugefügt werden",
); );
// Trip starts 2 hours ago
const datetimeSelector = '#departure';
const currentValue = await page.$eval(datetimeSelector, el => el.value);
const currentDate = new Date(currentValue);
currentDate.setMinutes(currentDate.getMinutes());
currentDate.setHours(currentDate.getHours() - new Date().getTimezoneOffset()/60 - 2);
const newDatetime = currentDate.toISOString().slice(0, 16);
await page.$eval(datetimeSelector, (el, value) => el.value = value, newDatetime);
await expect(page.locator("#shipmaster-newrowerjs")).toContainText("cox"); await expect(page.locator("#shipmaster-newrowerjs")).toContainText("cox");
await expect(page.locator("#steering_person-newrowerjs")).toContainText( await expect(page.locator("#steering_person-newrowerjs")).toContainText(
"rower2 cox", "rower2 cox",
@ -80,15 +90,6 @@ test("Cox can start and finish trip", async ({ page }, testInfo) => {
await page.goto("/log"); await page.goto("/log");
await page.locator("div:nth-child(2) > .border-0").click(); await page.locator("div:nth-child(2) > .border-0").click();
// Add a minute
const datetimeSelector = '#arrivaljs';
const currentValue = await page.$eval(datetimeSelector, el => el.value);
const currentDate = new Date(currentValue);
currentDate.setMinutes(currentDate.getMinutes() + 1);
currentDate.setHours(currentDate.getHours() - new Date().getTimezoneOffset()/60);
const newDatetime = currentDate.toISOString().slice(0, 16);
await page.$eval(datetimeSelector, (el, value) => el.value = value, newDatetime);
await page.getByRole("combobox", { name: "Destination" }).click(); await page.getByRole("combobox", { name: "Destination" }).click();
await page.getByRole("combobox", { name: "Destination" }).fill("Ottensheim"); await page.getByRole("combobox", { name: "Destination" }).fill("Ottensheim");
await page.getByRole("button", { name: "Ausfahrt beenden" }).click(); await page.getByRole("button", { name: "Ausfahrt beenden" }).click();
@ -153,6 +154,16 @@ test("Kiosk can start and finish trip", async ({ page }, testInfo) => {
await expect(page.getByRole("listbox")).toContainText( await expect(page.getByRole("listbox")).toContainText(
"Nur 2 Ruderer können hinzugefügt werden", "Nur 2 Ruderer können hinzugefügt werden",
); );
// Trip starts 2 hours ago
const datetimeSelector = '#departure';
const currentValue = await page.$eval(datetimeSelector, el => el.value);
const currentDate = new Date(currentValue);
currentDate.setMinutes(currentDate.getMinutes());
currentDate.setHours(currentDate.getHours() - new Date().getTimezoneOffset()/60 - 2);
const newDatetime = currentDate.toISOString().slice(0, 16);
await page.$eval(datetimeSelector, (el, value) => el.value = value, newDatetime);
await expect(page.locator("#shipmaster-newrowerjs")).toContainText("cox"); await expect(page.locator("#shipmaster-newrowerjs")).toContainText("cox");
await expect(page.locator("#steering_person-newrowerjs")).toContainText( await expect(page.locator("#steering_person-newrowerjs")).toContainText(
"rower2 cox", "rower2 cox",
@ -166,15 +177,6 @@ test("Kiosk can start and finish trip", async ({ page }, testInfo) => {
await page.goto("/log"); await page.goto("/log");
await page.locator('div:nth-child(2) > .pt-2 > div > div > div:nth-child(2) > .border-0').click(); // 2 trips currently running, try to close second one await page.locator('div:nth-child(2) > .pt-2 > div > div > div:nth-child(2) > .border-0').click(); // 2 trips currently running, try to close second one
// Add a minute
const datetimeSelector = '#arrivaljs';
const currentValue = await page.$eval(datetimeSelector, el => el.value);
const currentDate = new Date(currentValue);
currentDate.setMinutes(currentDate.getMinutes() + 1);
currentDate.setHours(currentDate.getHours() - new Date().getTimezoneOffset()/60);
const newDatetime = currentDate.toISOString().slice(0, 16);
await page.$eval(datetimeSelector, (el, value) => el.value = value, newDatetime);
await page.getByRole("combobox", { name: "Destination" }).click(); await page.getByRole("combobox", { name: "Destination" }).click();
await page.getByRole("combobox", { name: "Destination" }).fill("Ottensheim"); await page.getByRole("combobox", { name: "Destination" }).fill("Ottensheim");
await page.getByRole("button", { name: "Ausfahrt beenden" }).click(); await page.getByRole("button", { name: "Ausfahrt beenden" }).click();

View File

@ -104,6 +104,7 @@ pub enum LogbookUpdateError {
SteeringPersonNotInRowers, SteeringPersonNotInRowers,
UserNotAllowedToUseBoat, UserNotAllowedToUseBoat,
OnlyAllowedToEndTripsEndingToday, OnlyAllowedToEndTripsEndingToday,
TooFast(i64, i64),
} }
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
@ -127,6 +128,7 @@ pub enum LogbookCreateError {
ArrivalSetButNotRemainingTwo, ArrivalSetButNotRemainingTwo,
OnlyAllowedToEndTripsEndingToday, OnlyAllowedToEndTripsEndingToday,
CantChangeHandoperatableStatusForThisBoat, CantChangeHandoperatableStatusForThisBoat,
TooFast(i64, i64),
} }
impl From<LogbookUpdateError> for LogbookCreateError { impl From<LogbookUpdateError> for LogbookCreateError {
@ -150,6 +152,7 @@ impl From<LogbookUpdateError> for LogbookCreateError {
LogbookUpdateError::OnlyAllowedToEndTripsEndingToday => { LogbookUpdateError::OnlyAllowedToEndTripsEndingToday => {
LogbookCreateError::OnlyAllowedToEndTripsEndingToday LogbookCreateError::OnlyAllowedToEndTripsEndingToday
} }
LogbookUpdateError::TooFast(km, min) => LogbookCreateError::TooFast(km, min),
} }
} }
} }
@ -517,6 +520,17 @@ ORDER BY departure DESC
if arr.and_utc().timestamp() < dep.and_utc().timestamp() { if arr.and_utc().timestamp() < dep.and_utc().timestamp() {
return Err(LogbookUpdateError::ArrivalNotAfterDeparture); return Err(LogbookUpdateError::ArrivalNotAfterDeparture);
} }
let duration_in_mins = (arr.and_utc().timestamp() - dep.and_utc().timestamp()) / 60;
// Not possible to row < 1 min / 500 m = < 2 min / km
let possible_distance_km = duration_in_mins / 2;
if log.distance_in_km > possible_distance_km {
return Err(LogbookUpdateError::TooFast(
log.distance_in_km,
duration_in_mins,
));
}
let today = Local::now().date_naive(); let today = Local::now().date_naive();
let day_diff = today - arr.date(); let day_diff = today - arr.date();
let day_diff = day_diff.num_days(); let day_diff = day_diff.num_days();

View File

@ -227,7 +227,7 @@ async fn create_logbook(
Err(LogbookCreateError::ArrivalSetButNotRemainingTwo) => Flash::error(Redirect::to("/log"), "Ankunftszeit gesetzt aber nicht Distanz + Strecke"), Err(LogbookCreateError::ArrivalSetButNotRemainingTwo) => Flash::error(Redirect::to("/log"), "Ankunftszeit gesetzt aber nicht Distanz + Strecke"),
Err(LogbookCreateError::OnlyAllowedToEndTripsEndingToday) => Flash::error(Redirect::to("/log"), "Nur Ausfahrten, die in der letzten Woche enden dürfen eingetragen werden. Für einen Nachtrag schreibe alle Daten Philipp (Tel. nr. siehe Signal oder it@rudernlinz.at)."), Err(LogbookCreateError::OnlyAllowedToEndTripsEndingToday) => Flash::error(Redirect::to("/log"), "Nur Ausfahrten, die in der letzten Woche enden dürfen eingetragen werden. Für einen Nachtrag schreibe alle Daten Philipp (Tel. nr. siehe Signal oder it@rudernlinz.at)."),
Err(LogbookCreateError::CantChangeHandoperatableStatusForThisBoat) => Flash::error(Redirect::to("/log"), "Handsteuer-Status dieses Boots kann nicht verändert werden."), Err(LogbookCreateError::CantChangeHandoperatableStatusForThisBoat) => Flash::error(Redirect::to("/log"), "Handsteuer-Status dieses Boots kann nicht verändert werden."),
Err(LogbookCreateError::TooFast(km, min)) => Flash::error(Redirect::to("/log"), format!("KM zu groß für die eingegebene Dauer ({km} km in {min} Minuten). Bitte überprüfe deine Start- und Endzeit und versuche es erneut.")),
} }
} }
@ -300,6 +300,7 @@ async fn home_logbook(
Ok(_) => Flash::success(Redirect::to("/log"), "Ausfahrt korrekt eingetragen"), Ok(_) => Flash::success(Redirect::to("/log"), "Ausfahrt korrekt eingetragen"),
Err(LogbookUpdateError::TooManyRowers(expected, actual)) => Flash::error(Redirect::to("/log"), format!("Zu viele Ruderer (Boot fasst maximal {expected}, es wurden jedoch {actual} Ruderer ausgewählt)")), Err(LogbookUpdateError::TooManyRowers(expected, actual)) => Flash::error(Redirect::to("/log"), format!("Zu viele Ruderer (Boot fasst maximal {expected}, es wurden jedoch {actual} Ruderer ausgewählt)")),
Err(LogbookUpdateError::OnlyAllowedToEndTripsEndingToday) => Flash::error(Redirect::to("/log"), "Nur Ausfahrten, die heute enden dürfen eingetragen werden. Für einen Nachtrag schreibe alle Daten Philipp (Tel. nr. siehe Signal oder it@rudernlinz.at)."), Err(LogbookUpdateError::OnlyAllowedToEndTripsEndingToday) => Flash::error(Redirect::to("/log"), "Nur Ausfahrten, die heute enden dürfen eingetragen werden. Für einen Nachtrag schreibe alle Daten Philipp (Tel. nr. siehe Signal oder it@rudernlinz.at)."),
Err(LogbookUpdateError::TooFast(km, min)) => Flash::error(Redirect::to("/log"), format!("KM zu groß für die eingegebene Dauer ({km} km in {min} Minuten). Bitte überprüfe deine Start- und Endzeit und versuche es erneut.")),
Err(e) => Flash::error( Err(e) => Flash::error(
Redirect::to("/log"), Redirect::to("/log"),
format!("Eintrag {logbook_id} konnte nicht abgesendet werden (Fehler: {e:?})!"), format!("Eintrag {logbook_id} konnte nicht abgesendet werden (Fehler: {e:?})!"),