refactor: test edit event

This commit is contained in:
Max Hohlfeld 2025-07-13 12:09:40 +02:00
parent ee4481225e
commit e540844dcd
2 changed files with 34 additions and 62 deletions

View File

@ -1,14 +1,6 @@
use actix_web::{web, HttpResponse, Responder};
use brass_macros::db_test;
use sqlx::PgPool;
#[cfg(test)]
use crate::utils::test_helper::{
assert_snapshot, read_body, test_get, DbTestContext, RequestConfig, StatusCode,
};
#[cfg(test)]
use chrono::{NaiveDate, NaiveTime};
use crate::{
endpoints::{events::NewOrEditEventTemplate, IdPath},
utils::{ApplicationError, TemplateResponse},
@ -70,64 +62,44 @@ pub async fn get(
Ok(template.to_response()?)
}
#[db_test]
async fn produces_template(context: &DbTestContext) {
//Location::create(&context.db_pool, &Industry().fake::<String>(), 1)
// .await
// .unwrap();
//
//let date: NaiveDate = Date().fake();
//let time: NaiveTime = Time().fake();
//let words: Vec<String> = Words(3..5).fake();
//Event::create(
// &context.db_pool,
// &date,
// &time,
// &time,
// &words.join(" "),
// 1,
// false,
// false,
// 2,
// &Word().fake(),
// None,
//)
//.await
//.unwrap();
//// TODO: refactor
Location::create(&context.db_pool, "Hauptbahnhof", 1)
.await
.unwrap();
#[cfg(test)]
mod tests {
use brass_db::models::{Event, Location, Role};
use brass_macros::db_test;
use chrono::NaiveDateTime;
let date = NaiveDate::parse_from_str("2025-01-01", "%F").unwrap();
let changeset = brass_db::models::EventChangeset {
time: (
date.and_time(NaiveTime::parse_from_str("08:00", "%R").unwrap()),
date.and_time(NaiveTime::parse_from_str("10:00", "%R").unwrap()),
),
name: "Vorstellung".to_string(),
location_id: 1,
voluntary_fuehrungsassistent: false,
voluntary_wachhabender: false,
amount_of_posten: 2,
clothing: 1,
note: None,
use crate::utils::test_helper::{
assert_snapshot, test_get, DbTestContext, NaiveDateTimeExt, RequestConfig,
ServiceResponseExt, StatusCode,
};
Event::create(&context.db_pool, changeset).await.unwrap();
#[db_test]
async fn produces_template(context: &DbTestContext) {
Location::create(&context.db_pool, "Hauptbahnhof", 1)
.await
.unwrap();
let app = context.app().await;
let config = RequestConfig {
uri: "/events/1/edit".to_string(),
role: Role::Admin,
function: vec![brass_db::models::Function::Posten],
user_area: 1,
};
let response = test_get(&context.db_pool, app, &config).await;
let changeset = brass_db::models::EventChangeset {
time: (
NaiveDateTime::from_ymd_and_hms(2025, 01, 01, 8, 0, 0).unwrap(),
NaiveDateTime::from_ymd_and_hms(2025, 01, 01, 10, 0, 0).unwrap(),
),
name: "Vorstellung".to_string(),
location_id: 1,
voluntary_fuehrungsassistent: false,
voluntary_wachhabender: false,
amount_of_posten: 2,
clothing: 1,
note: None,
};
assert_eq!(StatusCode::OK, response.status());
Event::create(&context.db_pool, changeset).await.unwrap();
let body = read_body(response).await;
assert_snapshot!(body);
let config = RequestConfig::new("/events/1/edit").with_role(Role::Admin);
let response = test_get(&context.db_pool, context.app().await, &config).await;
let (status, body) = response.into_status_and_body().await;
assert_eq!(StatusCode::OK, status);
assert_snapshot!(body);
}
}