Read the one clock in the meal past-day tests
Browse files at this commitb1ef5941100b40cf2c43bb7aab08b2c426e35c9aParent: 4e4a808- fix
- read the one clock in the meal past-day tests
1 changed file +8 -5
src/domain/meal_booking.rsmodified+8 -5
| @@ -1344,11 +1344,12 @@ mod tests { | |||
| 1344 | assert!(check_cutoff(&past, &lunch(), &cutoff(Some(60), Some(720))).is_err()); | 1344 | assert!(check_cutoff(&past, &lunch(), &cutoff(Some(60), Some(720))).is_err()); |
| 1345 | } | 1345 | } |
| 1346 | 1346 | ||
| 1347 | + /// Through the crate's one clock ([`Timestamp::today_utc`]), never | ||
| 1348 | + /// `chrono::Utc::now` — the guard under test compares against that same | ||
| 1349 | + /// clock, and a test reading a second one is how a timezone mix gets back | ||
| 1350 | + /// in (`clippy.toml` denies it, tests included). | ||
| 1347 | fn today() -> String { | 1351 | fn today() -> String { |
| 1348 | - chrono::Utc::now() | 1352 | + Timestamp::today_utc().format("%Y-%m-%d").to_string() |
| 1349 | - .date_naive() | ||
| 1350 | - .format("%Y-%m-%d") | ||
| 1351 | - .to_string() | ||
| 1352 | } | 1353 | } |
| 1353 | 1354 | ||
| 1354 | /// The day being over is not the cutoff. It binds with no | 1355 | /// The day being over is not the cutoff. It binds with no |
| @@ -1357,7 +1358,9 @@ mod tests { | |||
| 1357 | /// — and it never binds today, at any hour. | 1358 | /// — and it never binds today, at any hour. |
| 1358 | #[test] | 1359 | #[test] |
| 1359 | fn the_past_day_guard_is_not_the_serving_hour_cutoff() { | 1360 | fn the_past_day_guard_is_not_the_serving_hour_cutoff() { |
| 1360 | - let yesterday = (chrono::Utc::now().date_naive() - chrono::Duration::days(1)) | 1361 | + let yesterday = Timestamp::today_utc() |
| 1362 | + .pred_opt() | ||
| 1363 | + .expect("there is a day before today") | ||
| 1361 | .format("%Y-%m-%d") | 1364 | .format("%Y-%m-%d") |
| 1362 | .to_string(); | 1365 | .to_string(); |
| 1363 | assert!(check_day_not_past(&MenuDate::try_new(&yesterday).unwrap()).is_err()); | 1366 | assert!(check_day_not_past(&MenuDate::try_new(&yesterday).unwrap()).is_err()); |