refactor: test edit event
This commit is contained in:
parent
ee4481225e
commit
e540844dcd
@ -1,14 +1,6 @@
|
|||||||
use actix_web::{web, HttpResponse, Responder};
|
use actix_web::{web, HttpResponse, Responder};
|
||||||
use brass_macros::db_test;
|
|
||||||
use sqlx::PgPool;
|
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::{
|
use crate::{
|
||||||
endpoints::{events::NewOrEditEventTemplate, IdPath},
|
endpoints::{events::NewOrEditEventTemplate, IdPath},
|
||||||
utils::{ApplicationError, TemplateResponse},
|
utils::{ApplicationError, TemplateResponse},
|
||||||
@ -70,64 +62,44 @@ pub async fn get(
|
|||||||
Ok(template.to_response()?)
|
Ok(template.to_response()?)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[db_test]
|
#[cfg(test)]
|
||||||
async fn produces_template(context: &DbTestContext) {
|
mod tests {
|
||||||
//Location::create(&context.db_pool, &Industry().fake::<String>(), 1)
|
use brass_db::models::{Event, Location, Role};
|
||||||
// .await
|
use brass_macros::db_test;
|
||||||
// .unwrap();
|
use chrono::NaiveDateTime;
|
||||||
//
|
|
||||||
//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();
|
|
||||||
|
|
||||||
let date = NaiveDate::parse_from_str("2025-01-01", "%F").unwrap();
|
use crate::utils::test_helper::{
|
||||||
|
assert_snapshot, test_get, DbTestContext, NaiveDateTimeExt, RequestConfig,
|
||||||
let changeset = brass_db::models::EventChangeset {
|
ServiceResponseExt, StatusCode,
|
||||||
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,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
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 changeset = brass_db::models::EventChangeset {
|
||||||
let config = RequestConfig {
|
time: (
|
||||||
uri: "/events/1/edit".to_string(),
|
NaiveDateTime::from_ymd_and_hms(2025, 01, 01, 8, 0, 0).unwrap(),
|
||||||
role: Role::Admin,
|
NaiveDateTime::from_ymd_and_hms(2025, 01, 01, 10, 0, 0).unwrap(),
|
||||||
function: vec![brass_db::models::Function::Posten],
|
),
|
||||||
user_area: 1,
|
name: "Vorstellung".to_string(),
|
||||||
};
|
location_id: 1,
|
||||||
let response = test_get(&context.db_pool, app, &config).await;
|
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;
|
let config = RequestConfig::new("/events/1/edit").with_role(Role::Admin);
|
||||||
assert_snapshot!(body);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user