From 94143f54d7f0bc5f90bd9de2a60e7a89c270acc1 Mon Sep 17 00:00:00 2001 From: Max Hohlfeld Date: Sat, 2 Aug 2025 13:19:34 +0200 Subject: [PATCH] test: get new availability --- ..._produces_template_when_user_is_admin.snap | 133 ++++++++++++++++++ web/src/endpoints/availability/get_new.rs | 30 ++++ web/src/endpoints/availability/mod.rs | 7 +- 3 files changed, 169 insertions(+), 1 deletion(-) create mode 100644 web/snapshots/brass_web__endpoints__availability__get_new__tests__inner_produces_template_when_user_is_admin.snap diff --git a/web/snapshots/brass_web__endpoints__availability__get_new__tests__inner_produces_template_when_user_is_admin.snap b/web/snapshots/brass_web__endpoints__availability__get_new__tests__inner_produces_template_when_user_is_admin.snap new file mode 100644 index 00000000..1d02c00a --- /dev/null +++ b/web/snapshots/brass_web__endpoints__availability__get_new__tests__inner_produces_template_when_user_is_admin.snap @@ -0,0 +1,133 @@ +--- +source: web/src/endpoints/availability/get_new.rs +expression: body +snapshot_kind: text +--- +
+
+ +
+

Neue Vefügbarkeit für Mittwoch, 01.01.2025

+ + + + + + +
+
+ +
+
+
+ + +

noch mögliche Zeiträume:

+
+ + + 01.01. 00:00 Uhr - 01.01. 10:00 Uhr + + + + 01.01. 20:00 Uhr - 02.01. 23:59 Uhr + + +
+ +
+
+ +
+
+
+ +
+
+ +
+
+
+ +
+ + +
+
+
+
+ +
+
+ +
+
+
+
+ +
+

+ + + + + + verfügbar von Mittwoch, 01.01. + 10:00 + Uhr bis + Mittwoch, 01.01. + 20:00 + Uhr +

+

+
+
+
+ +
+
+
+
+
+ +
+ +
+
+
+ +
+
+
diff --git a/web/src/endpoints/availability/get_new.rs b/web/src/endpoints/availability/get_new.rs index 6f137332..44357bd6 100644 --- a/web/src/endpoints/availability/get_new.rs +++ b/web/src/endpoints/availability/get_new.rs @@ -41,3 +41,33 @@ pub async fn get( Ok(template.to_response()?) } + +#[cfg(test)] +mod tests { + use crate::utils::test_helper::{ + assert_snapshot, create_test_login_user, test_get, DbTestContext, RequestConfig, + ServiceResponseExt, StatusCode, + }; + use brass_db::models::{Availability, AvailabilityChangeset}; + use brass_macros::db_test; + use chrono::NaiveDate; + + #[db_test] + async fn produces_template_when_user_is_admin(context: &DbTestContext) { + let config = RequestConfig::new("/availability/new?date=2025-01-01"); + + create_test_login_user(&context.db_pool, &config).await; + + let date = NaiveDate::from_ymd_opt(2025, 01, 01).unwrap(); + let changeset = AvailabilityChangeset::create_for_test(&date, 10, 20); + Availability::create(&context.db_pool, 1, &changeset) + .await + .unwrap(); + + let response = test_get(context.app().await, &config).await; + let (status, body) = response.into_status_and_body().await; + + assert_eq!(StatusCode::OK, status); + assert_snapshot!(body); + } +} diff --git a/web/src/endpoints/availability/mod.rs b/web/src/endpoints/availability/mod.rs index b75ea133..19650c56 100644 --- a/web/src/endpoints/availability/mod.rs +++ b/web/src/endpoints/availability/mod.rs @@ -19,7 +19,12 @@ pub mod post_update; pub mod put_cross_areal; #[derive(Template)] -#[template(path = "availability/new_or_edit.html")] +#[cfg_attr(not(test), template(path = "availability/new_or_edit.html"))] +#[cfg_attr( + test, + template(path = "availability/new_or_edit.html", block = "content"), + allow(dead_code) +)] struct NewOrEditAvailabilityTemplate<'a> { user: User, date: NaiveDate,