Compare commits

..

No commits in common. "fac14ce9f1cb64175dfacd0528df2406b96860d6" and "66dd99dd7ce65f79068c23a70317c15d8b2e37fd" have entirely different histories.

28 changed files with 222 additions and 274 deletions

View File

@ -25,9 +25,7 @@ pub async fn delete(
#[cfg(test)]
mod tests {
use crate::utils::test_helper::{
create_test_login_user, test_delete, DbTestContext, RequestConfig, StatusCode,
};
use crate::utils::test_helper::{test_delete, DbTestContext, RequestConfig, StatusCode};
use brass_db::models::{Area, Function, Location, Role};
use brass_macros::db_test;
@ -48,8 +46,7 @@ mod tests {
function: vec![Function::Posten],
user_area: 1,
};
create_test_login_user(&context.db_pool, &config).await;
let response = test_delete(app, &config).await;
let response = test_delete(&context.db_pool, app, &config).await;
assert_eq!(StatusCode::OK, response.status());
assert!(Area::read_by_id(&context.db_pool, 2)
@ -61,9 +58,8 @@ mod tests {
#[db_test]
async fn returns_unauthorized_when_user_is_not_admin(context: &DbTestContext) {
let app = context.app().await;
let config = RequestConfig::new("/area/delete/1");
create_test_login_user(&context.db_pool, &config).await;
let response = test_delete(app, &config).await;
let response =
test_delete(&context.db_pool, app, &RequestConfig::new("/area/delete/1")).await;
assert_eq!(StatusCode::UNAUTHORIZED, response.status());
}
@ -77,8 +73,7 @@ mod tests {
function: vec![Function::Posten],
user_area: 1,
};
create_test_login_user(&context.db_pool, &config).await;
let response = test_delete(app, &config).await;
let response = test_delete(&context.db_pool, app, &config).await;
assert_eq!(StatusCode::NOT_FOUND, response.status());
}
@ -100,8 +95,7 @@ mod tests {
function: vec![Function::Posten],
user_area: 1,
};
create_test_login_user(&context.db_pool, &config).await;
let response = test_delete(app, &config).await;
let response = test_delete(&context.db_pool, app, &config).await;
assert_eq!(StatusCode::OK, response.status());
assert!(Area::read_by_id(&context.db_pool, 2)

View File

@ -36,7 +36,7 @@ mod tests {
use brass_macros::db_test;
use crate::utils::test_helper::{
assert_snapshot, create_test_login_user, read_body, test_get, DbTestContext, RequestConfig,
assert_snapshot, read_body, test_get, DbTestContext, RequestConfig,
};
#[db_test]
@ -44,8 +44,7 @@ mod tests {
let app = context.app().await;
let config = RequestConfig::new("/area/edit/1").with_role(Role::Admin);
create_test_login_user(&context.db_pool, &config).await;
let response = test_get(app, &config).await;
let response = test_get(&context.db_pool, app, &config).await;
assert_eq!(StatusCode::OK, response.status());
@ -58,8 +57,7 @@ mod tests {
let app = context.app().await;
let config = RequestConfig::new("/area/edit/1").with_role(Role::AreaManager);
create_test_login_user(&context.db_pool, &config).await;
let response = test_get(app, &config).await;
let response = test_get(&context.db_pool, app, &config).await;
assert_eq!(StatusCode::UNAUTHORIZED, response.status());
}
@ -69,8 +67,7 @@ mod tests {
let app = context.app().await;
let config = RequestConfig::new("/area/edit/2").with_role(Role::Admin);
create_test_login_user(&context.db_pool, &config).await;
let response = test_get(app, &config).await;
let response = test_get(&context.db_pool, app, &config).await;
assert_eq!(StatusCode::NOT_FOUND, response.status());
}

View File

@ -22,8 +22,7 @@ async fn get(user: web::ReqData<User>) -> Result<impl Responder, ApplicationErro
#[cfg(test)]
mod tests {
use crate::utils::test_helper::{
assert_snapshot, create_test_login_user, test_get, DbTestContext, RequestConfig,
ServiceResponseExt, StatusCode,
assert_snapshot, test_get, DbTestContext, RequestConfig, ServiceResponseExt, StatusCode,
};
use brass_db::models::Role;
use brass_macros::db_test;
@ -32,8 +31,7 @@ mod tests {
async fn produces_template_when_user_is_admin(context: &DbTestContext) {
let config = RequestConfig::new("/area/new").with_role(Role::Admin);
create_test_login_user(&context.db_pool, &config).await;
let response = test_get(context.app().await, &config).await;
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);
@ -43,8 +41,7 @@ mod tests {
#[db_test]
async fn returns_unauthorized_when_user_is_not_admin(context: &DbTestContext) {
let config = RequestConfig::new("/area/new").with_role(Role::AreaManager);
create_test_login_user(&context.db_pool, &config).await;
let response = test_get(context.app().await, &config).await;
let response = test_get(&context.db_pool, context.app().await, &config).await;
assert_eq!(StatusCode::UNAUTHORIZED, response.status());
}

View File

@ -37,7 +37,7 @@ mod tests {
use crate::{
endpoints::area::AreaForm,
utils::test_helper::{create_test_login_user, test_post, DbTestContext, RequestConfig},
utils::test_helper::{test_post, DbTestContext, RequestConfig},
};
#[db_test]
@ -50,13 +50,12 @@ mod tests {
function: vec![Function::Posten],
user_area: 1,
};
create_test_login_user(&context.db_pool, &config).await;
let request = AreaForm {
name: "Neuer Name".to_string(),
};
let response = test_post(app, &config, Some(request)).await;
let response = test_post(&context.db_pool, app, &config, Some(request)).await;
assert_eq!(StatusCode::FOUND, response.status());
@ -78,13 +77,12 @@ mod tests {
function: vec![Function::Posten],
user_area: 1,
};
create_test_login_user(&context.db_pool, &config).await;
let request = AreaForm {
name: "Neuer Name".to_string(),
};
let response = test_post(app, &config, Some(request)).await;
let response = test_post(&context.db_pool, app, &config, Some(request)).await;
assert_eq!(StatusCode::UNAUTHORIZED, response.status());
}
@ -99,13 +97,12 @@ mod tests {
function: vec![Function::Posten],
user_area: 1,
};
create_test_login_user(&context.db_pool, &config).await;
let request = AreaForm {
name: "Neuer Name".to_string(),
};
let response = test_post(app, &config, Some(request)).await;
let response = test_post(&context.db_pool, app, &config, Some(request)).await;
assert_eq!(StatusCode::NOT_FOUND, response.status());
}

View File

@ -30,7 +30,7 @@ mod tests {
use crate::{
endpoints::area::AreaForm,
utils::test_helper::{create_test_login_user, test_post, DbTestContext, RequestConfig},
utils::test_helper::{test_post, DbTestContext, RequestConfig},
};
#[db_test]
@ -43,13 +43,12 @@ mod tests {
function: vec![Function::Posten],
user_area: 1,
};
create_test_login_user(&context.db_pool, &config).await;
let request = AreaForm {
name: "Neuer Name".to_string(),
};
let response = test_post(app, &config, Some(request)).await;
let response = test_post(&context.db_pool, app, &config, Some(request)).await;
assert_eq!(StatusCode::FOUND, response.status());
@ -71,13 +70,12 @@ mod tests {
function: vec![Function::Posten],
user_area: 1,
};
create_test_login_user(&context.db_pool, &config).await;
let request = AreaForm {
name: "Neuer Name".to_string(),
};
let response = test_post(app, &config, Some(request)).await;
let response = test_post(&context.db_pool, app, &config, Some(request)).await;
assert_eq!(StatusCode::UNAUTHORIZED, response.status());
}

View File

@ -71,9 +71,7 @@ mod tests {
use fake::{faker::chrono::en::Date, Fake, Faker};
use sqlx::PgPool;
use crate::utils::test_helper::{
create_test_login_user, test_delete, DbTestContext, RequestConfig,
};
use crate::utils::test_helper::{test_delete, DbTestContext, RequestConfig};
use brass_db::models::{
Assignment, AssignmentChangeset, Availability, AvailabilityChangeset, Event,
EventChangeset, Function, Location, Role, User,
@ -120,9 +118,8 @@ mod tests {
function: vec![Function::Posten],
user_area: 1,
};
create_test_login_user(&context.db_pool, &config).await;
let response = test_delete(app, &config).await;
let response = test_delete(&context.db_pool, app, &config).await;
assert_eq!(StatusCode::OK, response.status());
assert_eq!(
@ -145,9 +142,8 @@ mod tests {
function: vec![Function::Posten],
user_area: 1,
};
create_test_login_user(&context.db_pool, &config).await;
let response = test_delete(app, &config).await;
let response = test_delete(&context.db_pool, app, &config).await;
assert_eq!(StatusCode::UNAUTHORIZED, response.status());
}
@ -161,9 +157,8 @@ mod tests {
function: vec![Function::Posten],
user_area: 1,
};
create_test_login_user(&context.db_pool, &config).await;
let response = test_delete(app, &config).await;
let response = test_delete(&context.db_pool, app, &config).await;
assert_eq!(StatusCode::NOT_FOUND, response.status());
}
@ -179,9 +174,8 @@ mod tests {
function: vec![Function::Posten],
user_area: 1,
};
create_test_login_user(&context.db_pool, &config).await;
let response = test_delete(app, &config).await;
let response = test_delete(&context.db_pool, app, &config).await;
assert_eq!(StatusCode::NOT_FOUND, response.status());
}

View File

@ -91,8 +91,8 @@ mod tests {
use sqlx::PgPool;
use crate::utils::test_helper::{
assert_snapshot, create_test_login_user, test_post, DbTestContext, NaiveDateTimeExt,
RequestConfig, ServiceResponseExt,
assert_snapshot, test_post, DbTestContext, NaiveDateTimeExt, RequestConfig,
ServiceResponseExt,
};
async fn arrange(pool: &PgPool) {
@ -139,9 +139,8 @@ mod tests {
let config = RequestConfig::new("/assignments/new?availability=1&function=1&event=1")
.with_role(Role::Admin);
create_test_login_user(&context.db_pool, &config).await;
let response = test_post::<_, _, String>(app, &config, None).await;
let response = test_post::<_, _, String>(&context.db_pool, app, &config, None).await;
let (status, body) = response.into_status_and_body().await;
assert_eq!(StatusCode::OK, status, "{body}");
@ -160,9 +159,8 @@ mod tests {
let config = RequestConfig::new("/assignments/new?availability=1&function=1&event=1")
.with_role(Role::Admin);
create_test_login_user(&context.db_pool, &config).await;
let response = test_post::<_, _, String>(app, &config, None).await;
let response = test_post::<_, _, String>(&context.db_pool, app, &config, None).await;
assert_eq!(StatusCode::UNPROCESSABLE_ENTITY, response.status());
}
@ -178,9 +176,8 @@ mod tests {
let config = RequestConfig::new("/assignments/new?availability=1&function=1&event=1")
.with_role(Role::Admin);
create_test_login_user(&context.db_pool, &config).await;
let response = test_post::<_, _, String>(app, &config, None).await;
let response = test_post::<_, _, String>(&context.db_pool, app, &config, None).await;
assert_eq!(StatusCode::NOT_FOUND, response.status());
}
@ -202,9 +199,8 @@ mod tests {
let config = RequestConfig::new("/assignments/new?availability=1&function=1&event=1")
.with_role(Role::AreaManager)
.with_user_area(2);
create_test_login_user(&context.db_pool, &config).await;
let response = test_post::<_, _, String>(app, &config, None).await;
let response = test_post::<_, _, String>(&context.db_pool, app, &config, None).await;
assert_eq!(StatusCode::UNPROCESSABLE_ENTITY, response.status());
}
@ -228,9 +224,8 @@ mod tests {
let config = RequestConfig::new("/assignments/new?availability=1&function=1&event=1")
.with_role(Role::Admin);
create_test_login_user(&context.db_pool, &config).await;
let response = test_post::<_, _, String>(app, &config, None).await;
let response = test_post::<_, _, String>(&context.db_pool, app, &config, None).await;
assert_eq!(StatusCode::UNPROCESSABLE_ENTITY, response.status());
}
@ -250,9 +245,8 @@ mod tests {
let config = RequestConfig::new("/assignments/new?availability=1&function=1&event=1")
.with_role(Role::Admin);
create_test_login_user(&context.db_pool, &config).await;
let response = test_post::<_, _, String>(app, &config, None).await;
let response = test_post::<_, _, String>(&context.db_pool, app, &config, None).await;
assert_eq!(StatusCode::UNPROCESSABLE_ENTITY, response.status());
}
@ -282,9 +276,8 @@ mod tests {
let config = RequestConfig::new("/assignments/new?availability=1&function=1&event=2")
.with_role(Role::Admin);
create_test_login_user(&context.db_pool, &config).await;
let response = test_post::<_, _, String>(app, &config, None).await;
let response = test_post::<_, _, String>(&context.db_pool, app, &config, None).await;
assert_eq!(StatusCode::UNPROCESSABLE_ENTITY, response.status());
}
@ -302,9 +295,8 @@ mod tests {
let config = RequestConfig::new("/assignments/new?availability=1&function=5&event=1")
.with_role(Role::Admin);
create_test_login_user(&context.db_pool, &config).await;
let response = test_post::<_, _, String>(app, &config, None).await;
let response = test_post::<_, _, String>(&context.db_pool, app, &config, None).await;
assert_eq!(StatusCode::UNPROCESSABLE_ENTITY, response.status());
}
@ -365,9 +357,8 @@ mod tests {
let config = RequestConfig::new("/assignments/new?availability=2&function=5&event=1")
.with_role(Role::Admin);
create_test_login_user(&context.db_pool, &config).await;
let response = test_post::<_, _, String>(app, &config, None).await;
let response = test_post::<_, _, String>(&context.db_pool, app, &config, None).await;
assert_eq!(StatusCode::UNPROCESSABLE_ENTITY, response.status());
}

View File

@ -23,44 +23,3 @@ pub async fn delete(
Ok(HttpResponse::Ok().finish())
}
#[cfg(test)]
mod tests {
use actix_http::StatusCode;
use brass_db::models::{Availability, AvailabilityChangeset};
use brass_macros::db_test;
use chrono::NaiveDateTime;
use crate::utils::test_helper::{
create_test_login_user, test_delete, DbTestContext, NaiveDateTimeExt, RequestConfig,
};
#[db_test]
async fn deletes_when_availability_is_from_user(context: &DbTestContext) {
let app = context.app().await;
let config = RequestConfig::new("/availability/delete/1");
create_test_login_user(&context.db_pool, &config).await;
Availability::create(
&context.db_pool,
1,
AvailabilityChangeset {
time: (
NaiveDateTime::from_ymd_and_hms(2025, 01, 01, 10, 0, 0).unwrap(),
NaiveDateTime::from_ymd_and_hms(2025, 02, 01, 10, 0, 0).unwrap(),
),
comment: None,
},
)
.await
.unwrap();
let response = test_delete(&app, &config).await;
assert_eq!(StatusCode::OK, response.status());
}
// test deletes availability_from_another_But_area_manager_in_area
// test doesnt_delete availability_from_another_But_area_manager_is_not_in_area
// test deletest_availability_from_another_user_when_user_admin
// test doesnt_delete availability_when_not_existing
}

View File

@ -75,8 +75,7 @@ mod tests {
use brass_macros::db_test;
use crate::utils::test_helper::{
assert_snapshot, create_test_login_user, test_get, DbTestContext, RequestConfig,
ServiceResponseExt,
assert_snapshot, test_get, DbTestContext, RequestConfig, ServiceResponseExt,
};
#[db_test]
@ -84,8 +83,7 @@ mod tests {
let app = context.app().await;
let config = RequestConfig::new("/");
create_test_login_user(&context.db_pool, &config).await;
let response = test_get(app, &config).await;
let response = test_get(&context.db_pool, app, &config).await;
let (status, body) = response.into_status_and_body().await;

View File

@ -25,9 +25,7 @@ pub async fn delete(
#[cfg(test)]
mod tests {
use crate::utils::test_helper::{
create_test_login_user, test_delete, DbTestContext, RequestConfig, StatusCode,
};
use crate::utils::test_helper::{test_delete, DbTestContext, RequestConfig, StatusCode};
use brass_db::models::{Clothing, Role};
use brass_macros::db_test;
@ -41,9 +39,8 @@ mod tests {
assert_eq!(2, Clothing::read_all(&context.db_pool).await.unwrap().len());
let config = RequestConfig::new("/clothing/1").with_role(Role::Admin);
create_test_login_user(&context.db_pool, &config).await;
let response = test_delete(app, &config).await;
let response = test_delete(&context.db_pool, app, &config).await;
assert_eq!(StatusCode::OK, response.status());
assert_eq!(1, Clothing::read_all(&context.db_pool).await.unwrap().len());
@ -53,9 +50,7 @@ mod tests {
#[db_test]
async fn returns_unauthorized_when_user_is_user(context: &DbTestContext) {
let app = context.app().await;
let config = RequestConfig::new("/clothing/1");
create_test_login_user(&context.db_pool, &config).await;
let response = test_delete(app, &config).await;
let response = test_delete(&context.db_pool, app, &RequestConfig::new("/clothing/1")).await;
assert_eq!(StatusCode::UNAUTHORIZED, response.status());
}
@ -63,9 +58,12 @@ mod tests {
#[db_test]
async fn returns_unauthorized_when_user_is_area_manager(context: &DbTestContext) {
let app = context.app().await;
let config = RequestConfig::new("/clothing/1").with_role(Role::AreaManager);
create_test_login_user(&context.db_pool, &config).await;
let response = test_delete(app, &config).await;
let response = test_delete(
&context.db_pool,
app,
&RequestConfig::new("/clothing/1").with_role(Role::AreaManager),
)
.await;
assert_eq!(StatusCode::UNAUTHORIZED, response.status());
}
@ -73,9 +71,12 @@ mod tests {
#[db_test]
async fn returns_not_found_when_clothing_does_not_exist(context: &DbTestContext) {
let app = context.app().await;
let config = RequestConfig::new("/clothing/100").with_role(Role::Admin);
create_test_login_user(&context.db_pool, &config).await;
let response = test_delete(app, &config).await;
let response = test_delete(
&context.db_pool,
app,
&RequestConfig::new("/clothing/100").with_role(Role::Admin),
)
.await;
assert_eq!(StatusCode::NOT_FOUND, response.status());
}

View File

@ -32,8 +32,7 @@ pub async fn get(
#[cfg(test)]
mod tests {
use crate::utils::test_helper::{
assert_snapshot, create_test_login_user, read_body, test_get, DbTestContext, RequestConfig,
StatusCode,
assert_snapshot, read_body, test_get, DbTestContext, RequestConfig, StatusCode,
};
use brass_db::models::{Clothing, Role};
use brass_macros::db_test;
@ -47,9 +46,8 @@ mod tests {
let app = context.app().await;
let config = RequestConfig::new("/clothing/edit/1");
create_test_login_user(&context.db_pool, &config).await;
let response = test_get(&app, &config).await;
let response = test_get(&context.db_pool, &app, &config).await;
assert_eq!(StatusCode::UNAUTHORIZED, response.status());
}
@ -62,9 +60,8 @@ mod tests {
let app = context.app().await;
let config = RequestConfig::new("/clothing/edit/1").with_role(Role::AreaManager);
create_test_login_user(&context.db_pool, &config).await;
let response = test_get(&app, &config).await;
let response = test_get(&context.db_pool, &app, &config).await;
assert_eq!(StatusCode::UNAUTHORIZED, response.status());
}
@ -76,9 +73,8 @@ mod tests {
.unwrap();
let config = RequestConfig::new("/clothing/edit/1").with_role(Role::Admin);
create_test_login_user(&context.db_pool, &config).await;
let response = test_get(&app, &config).await;
let response = test_get(&context.db_pool, &app, &config).await;
assert_eq!(StatusCode::OK, response.status());
let body = read_body(response).await;

View File

@ -39,7 +39,7 @@ pub async fn get(
#[cfg(test)]
mod tests {
use crate::utils::test_helper::{
assert_snapshot, create_test_login_user, read_body, test_get, DbTestContext, RequestConfig, StatusCode
assert_snapshot, read_body, test_get, DbTestContext, RequestConfig, StatusCode,
};
use brass_db::models::{Clothing, Role};
use brass_macros::db_test;
@ -49,9 +49,8 @@ mod tests {
let app = context.app().await;
let config = RequestConfig::new("/clothing");
create_test_login_user(&context.db_pool, &config).await;
let response = test_get(&app, &config).await;
let response = test_get(&context.db_pool, &app, &config).await;
assert_eq!(StatusCode::UNAUTHORIZED, response.status());
}
@ -60,9 +59,8 @@ mod tests {
let app = context.app().await;
let config = RequestConfig::new("/clothing").with_role(Role::AreaManager);
create_test_login_user(&context.db_pool, &config).await;
let response = test_get(&app, &config).await;
let response = test_get(&context.db_pool, &app, &config).await;
assert_eq!(StatusCode::UNAUTHORIZED, response.status());
}
@ -74,9 +72,8 @@ mod tests {
.unwrap();
let config = RequestConfig::new("/clothing").with_role(Role::Admin);
create_test_login_user(&context.db_pool, &config).await;
let response = test_get(&app, &config).await;
let response = test_get(&context.db_pool, &app, &config).await;
assert_eq!(StatusCode::OK, response.status());
let body = read_body(response).await;

View File

@ -29,8 +29,7 @@ pub async fn get(
#[cfg(test)]
mod tests {
use crate::utils::test_helper::{
assert_snapshot, create_test_login_user, test_get, DbTestContext, RequestConfig,
ServiceResponseExt, StatusCode,
assert_snapshot, read_body, test_get, DbTestContext, RequestConfig, StatusCode,
};
use brass_db::models::{Clothing, Role};
use brass_macros::db_test;
@ -44,9 +43,8 @@ mod tests {
let app = context.app().await;
let config = RequestConfig::new("/clothing/1");
create_test_login_user(&context.db_pool, &config).await;
let response = test_get(&app, &config).await;
let response = test_get(&context.db_pool, &app, &config).await;
assert_eq!(StatusCode::UNAUTHORIZED, response.status());
}
@ -59,9 +57,8 @@ mod tests {
let app = context.app().await;
let config = RequestConfig::new("/clothing/1").with_role(Role::AreaManager);
create_test_login_user(&context.db_pool, &config).await;
let response = test_get(&app, &config).await;
let response = test_get(&context.db_pool, &app, &config).await;
assert_eq!(StatusCode::UNAUTHORIZED, response.status());
}
@ -73,10 +70,11 @@ mod tests {
.unwrap();
let config = RequestConfig::new("/clothing/1").with_role(Role::Admin);
create_test_login_user(&context.db_pool, &config).await;
let (status, body) = test_get(&app, &config).await.into_status_and_body().await;
assert_eq!(StatusCode::OK, status);
let response = test_get(&context.db_pool, &app, &config).await;
assert_eq!(StatusCode::OK, response.status());
let body = read_body(response).await;
assert_snapshot!(body);
}
}

View File

@ -69,8 +69,8 @@ mod tests {
use chrono::NaiveDateTime;
use crate::utils::test_helper::{
assert_snapshot, create_test_login_user, test_get, DbTestContext, NaiveDateTimeExt,
RequestConfig, ServiceResponseExt, StatusCode,
assert_snapshot, test_get, DbTestContext, NaiveDateTimeExt, RequestConfig,
ServiceResponseExt, StatusCode,
};
#[db_test]
@ -96,8 +96,7 @@ mod tests {
Event::create(&context.db_pool, changeset).await.unwrap();
let config = RequestConfig::new("/events/1/edit").with_role(Role::Admin);
create_test_login_user(&context.db_pool, &config).await;
let response = test_get(context.app().await, &config).await;
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);

View File

@ -32,9 +32,7 @@ pub async fn post(
mod tests {
use crate::{
endpoints::location::LocationForm,
utils::test_helper::{
create_test_login_user, test_post, DbTestContext, RequestConfig, StatusCode,
},
utils::test_helper::{test_post, DbTestContext, RequestConfig, StatusCode},
};
use brass_db::models::{Function, Location, Role};
use brass_macros::db_test;
@ -48,14 +46,13 @@ mod tests {
function: vec![Function::Posten],
user_area: 1,
};
create_test_login_user(&context.db_pool, &config).await;
let form = LocationForm {
name: "Hauptbahnhof".to_string(),
area: Some(1),
};
let response = test_post(app, &config, Some(form)).await;
let response = test_post(&context.db_pool, app, &config, Some(form)).await;
assert_eq!(StatusCode::FOUND, response.status());
assert_eq!(
@ -77,14 +74,13 @@ mod tests {
function: vec![Function::Posten],
user_area: 1,
};
create_test_login_user(&context.db_pool, &config).await;
let form = LocationForm {
name: "Hauptbahnhof".to_string(),
area: None,
};
let response = test_post(app, &config, Some(form)).await;
let response = test_post(&context.db_pool, app, &config, Some(form)).await;
assert_eq!(StatusCode::FOUND, response.status());
assert_eq!(

View File

@ -22,16 +22,14 @@ mod tests {
use brass_macros::db_test;
use crate::utils::test_helper::{
assert_snapshot, create_test_login_user, test_get, DbTestContext, RequestConfig,
ServiceResponseExt,
assert_snapshot, test_get, DbTestContext, RequestConfig, ServiceResponseExt,
};
#[db_test]
async fn produces_template_fine(context: &DbTestContext) {
let config = RequestConfig::new("/users/changepassword");
create_test_login_user(&context.db_pool, &config).await;
let response = test_get(context.app().await, &config).await;
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);

View File

@ -103,7 +103,6 @@ mod tests {
function: vec![Function::Posten],
user_area: 1,
};
create_test_login_user(&context.db_pool, &config).await;
let new_name: String = Name().fake();
let new_mail: String = SafeEmail().fake();
@ -118,7 +117,7 @@ mod tests {
area: Some(2),
};
let response = test_post(app, &config, Some(form)).await;
let response = test_post(&context.db_pool, app, &config, Some(form)).await;
assert_eq!(StatusCode::FOUND, response.status());
let updated_user = User::read_by_id(&context.db_pool, 1)
@ -142,7 +141,6 @@ mod tests {
function: vec![Function::Posten],
user_area: 1,
};
create_test_login_user(&context.db_pool, &config).await;
let form = NewOrEditUserForm {
name: "".to_string(),
@ -154,7 +152,7 @@ mod tests {
area: Some(1),
};
let response = test_post(app, &config, Some(form)).await;
let response = test_post(&context.db_pool, app, &config, Some(form)).await;
assert_eq!(StatusCode::BAD_REQUEST, response.status());
}
@ -164,7 +162,6 @@ mod tests {
let app = context.app().await;
let config = RequestConfig::new("/users/edit/1").with_role(Role::Admin);
create_test_login_user(&context.db_pool, &config).await;
let new_name: String = Name().fake();
let new_mail: String = String::from("NONLowercaseEMAIL@example.com");
@ -179,7 +176,7 @@ mod tests {
area: Some(1),
};
let response = test_post(app, &config, Some(form)).await;
let response = test_post(&context.db_pool, app, &config, Some(form)).await;
let (status, body) = response.into_status_and_body().await;
debug!(body);
@ -201,7 +198,6 @@ mod tests {
let app = context.app().await;
let config = RequestConfig::new("/users/edit/1").with_role(Role::Admin);
create_test_login_user(&context.db_pool, &config).await;
let second_user = User::read_by_id(&context.db_pool, 2)
.await
@ -221,7 +217,7 @@ mod tests {
area: Some(2),
};
let response = test_post(app, &config, Some(form)).await;
let response = test_post(&context.db_pool, app, &config, Some(form)).await;
assert_eq!(StatusCode::UNPROCESSABLE_ENTITY, response.status());
}
}

View File

@ -83,8 +83,7 @@ async fn handle_lock_state_for_user(
#[cfg(test)]
mod tests {
use crate::utils::test_helper::{
assert_snapshot, create_test_login_user, read_body, test_put, DbTestContext, RequestConfig,
StatusCode,
assert_snapshot, read_body, test_put, DbTestContext, RequestConfig, StatusCode,
};
use brass_db::models::{Area, Function, Role, User};
use brass_macros::db_test;
@ -95,18 +94,28 @@ mod tests {
let app = context.app().await;
User::create(&context.db_pool, &Faker.fake()).await.unwrap();
let lock_config = RequestConfig::new("/users/1/lock").with_role(Role::Admin);
create_test_login_user(&context.db_pool, &lock_config).await;
let lock_response = test_put::<_, _, String>(&app, &lock_config, None).await;
let lock_config = RequestConfig {
uri: "/users/1/lock".to_string(),
role: Role::Admin,
function: vec![Function::Posten],
user_area: 1,
};
let lock_response =
test_put::<_, _, String>(&context.db_pool, &app, &lock_config, None).await;
assert_eq!(StatusCode::OK, lock_response.status());
let lock_body = read_body(lock_response).await;
assert_snapshot!(lock_body);
let unlock_config = RequestConfig::new("/users/1/unlock").with_role(Role::Admin);
let unlock_response = test_put::<_, _, String>(&app, &unlock_config, None).await;
let unlock_config = RequestConfig {
uri: "/users/1/unlock".to_string(),
role: Role::Admin,
function: vec![Function::Posten],
user_area: 1,
};
let unlock_response =
test_put::<_, _, String>(&context.db_pool, &app, &unlock_config, None).await;
assert_eq!(StatusCode::OK, unlock_response.status());
@ -126,9 +135,8 @@ mod tests {
function: vec![Function::Posten],
user_area: 2,
};
create_test_login_user(&context.db_pool, &config).await;
let response = test_put::<_, _, String>(&app, &config, None).await;
let response = test_put::<_, _, String>(&context.db_pool, &app, &config, None).await;
assert_eq!(StatusCode::UNAUTHORIZED, response.status())
}
@ -143,9 +151,8 @@ mod tests {
function: vec![Function::Posten],
user_area: 1,
};
create_test_login_user(&context.db_pool, &config).await;
let response = test_put::<_, _, String>(&app, &config, None).await;
let response = test_put::<_, _, String>(&context.db_pool, &app, &config, None).await;
assert_eq!(StatusCode::BAD_REQUEST, response.status())
}
@ -160,9 +167,8 @@ mod tests {
function: vec![Function::Posten],
user_area: 1,
};
create_test_login_user(&context.db_pool, &config).await;
let response = test_put::<_, _, String>(&app, &config, None).await;
let response = test_put::<_, _, String>(&context.db_pool, &app, &config, None).await;
assert_eq!(StatusCode::NOT_FOUND, response.status())
}

View File

@ -75,8 +75,7 @@ async fn handle_subscription_to_notifications(
#[cfg(test)]
mod tests {
use crate::utils::test_helper::{
assert_snapshot, create_test_login_user, read_body, test_put, DbTestContext, RequestConfig,
StatusCode,
assert_snapshot, read_body, test_put, DbTestContext, RequestConfig, StatusCode,
};
use brass_macros::db_test;
@ -85,8 +84,8 @@ mod tests {
let app = context.app().await;
let unsubscribe_config = RequestConfig::new("/users/1/unsubscribeNotifications");
create_test_login_user(&context.db_pool, &unsubscribe_config).await;
let unsubscribe_response = test_put::<_, _, String>(&app, &unsubscribe_config, None).await;
let unsubscribe_response =
test_put::<_, _, String>(&context.db_pool, &app, &unsubscribe_config, None).await;
assert_eq!(StatusCode::OK, unsubscribe_response.status());
@ -94,7 +93,8 @@ mod tests {
assert_snapshot!(unsubscribe_body);
let subscribe_config = RequestConfig::new("/users/1/subscribeNotifications");
let subscribe_response = test_put::<_, _, String>(&app, &subscribe_config, None).await;
let subscribe_response =
test_put::<_, _, String>(&context.db_pool, &app, &subscribe_config, None).await;
assert_eq!(StatusCode::OK, subscribe_response.status());
@ -107,8 +107,8 @@ mod tests {
let app = context.app().await;
let unsubscribe_config = RequestConfig::new("/users/3/unsubscribeNotifications");
create_test_login_user(&context.db_pool, &unsubscribe_config).await;
let unsubscribe_response = test_put::<_, _, String>(&app, &unsubscribe_config, None).await;
let unsubscribe_response =
test_put::<_, _, String>(&context.db_pool, &app, &unsubscribe_config, None).await;
assert_eq!(StatusCode::UNAUTHORIZED, unsubscribe_response.status());
}

View File

@ -25,10 +25,8 @@ pub async fn delete(
#[cfg(test)]
mod tests {
use crate::utils::test_helper::{
create_test_login_user, test_delete, DbTestContext, RequestConfig, StatusCode,
};
use brass_db::models::{Role, Vehicle};
use crate::utils::test_helper::{test_delete, DbTestContext, RequestConfig, StatusCode};
use brass_db::models::{Function, Role, Vehicle};
use brass_macros::db_test;
#[db_test]
@ -49,9 +47,13 @@ mod tests {
assert!(Vehicle::read(&context.db_pool, 1).await.unwrap().is_some());
let app = context.app().await;
let config = RequestConfig::new("/vehicles/1").with_role(role);
create_test_login_user(&context.db_pool, &config).await;
let response = test_delete(app, &config).await;
let config = RequestConfig {
uri: "/vehicles/1".to_string(),
role,
function: vec![Function::Posten],
user_area: 1,
};
let response = test_delete(&context.db_pool, app, &config).await;
assert_eq!(StatusCode::OK, response.status());
assert!(Vehicle::read(&context.db_pool, 1).await.unwrap().is_none());
@ -60,9 +62,7 @@ mod tests {
#[db_test]
async fn returns_unauthorized_when_user_is_staff(context: &DbTestContext) {
let app = context.app().await;
let config = RequestConfig::new("/vehicles/1");
create_test_login_user(&context.db_pool, &config).await;
let response = test_delete(app, &config).await;
let response = test_delete(&context.db_pool, app, &RequestConfig::new("/vehicles/1")).await;
assert_eq!(StatusCode::UNAUTHORIZED, response.status());
}
@ -70,9 +70,13 @@ mod tests {
#[db_test]
async fn returns_not_found_when_vehicle_does_not_exist(context: &DbTestContext) {
let app = context.app().await;
let config = RequestConfig::new("/vehicles/1").with_role(Role::Admin);
create_test_login_user(&context.db_pool, &config).await;
let response = test_delete(app, &config).await;
let config = RequestConfig {
uri: "/vehicles/1".to_string(),
role: Role::Admin,
function: vec![Function::Posten],
user_area: 1,
};
let response = test_delete(&context.db_pool, app, &config).await;
assert_eq!(StatusCode::NOT_FOUND, response.status());
}

View File

@ -32,10 +32,9 @@ pub async fn get(
#[cfg(test)]
mod tests {
use crate::utils::test_helper::{
assert_snapshot, create_test_login_user, test_get, DbTestContext, RequestConfig,
ServiceResponseExt, StatusCode,
assert_snapshot, read_body, test_get, DbTestContext, RequestConfig, StatusCode,
};
use brass_db::models::{Role, Vehicle};
use brass_db::models::{Role, Function, Vehicle};
use brass_macros::db_test;
#[db_test]
@ -47,9 +46,8 @@ mod tests {
let app = context.app().await;
let config = RequestConfig::new("/vehicles/1");
create_test_login_user(&context.db_pool, &config).await;
let response = test_get(&app, &config).await;
let response = test_get(&context.db_pool, &app, &config).await;
assert_eq!(StatusCode::UNAUTHORIZED, response.status());
}
@ -61,10 +59,14 @@ mod tests {
let app = context.app().await;
let config = RequestConfig::new("/vehicles/1").with_role(Role::AreaManager);
create_test_login_user(&context.db_pool, &config).await;
let config = RequestConfig {
uri: "/vehicles/1".to_string(),
role: Role::AreaManager,
function: vec![Function::Posten],
user_area: 1,
};
let response = test_get(&app, &config).await;
let response = test_get(&context.db_pool, &app, &config).await;
assert_eq!(StatusCode::OK, response.status());
}
@ -75,11 +77,17 @@ mod tests {
.await
.unwrap();
let config = RequestConfig::new("/vehicles/1").with_role(Role::Admin);
create_test_login_user(&context.db_pool, &config).await;
let config = RequestConfig {
uri: "/vehicles/1".to_string(),
role: Role::Admin,
function: vec![Function::Posten],
user_area: 1,
};
let (status, body) = test_get(&app, &config).await.into_status_and_body().await;
assert_eq!(StatusCode::OK, status);
let response = test_get(&context.db_pool, &app, &config).await;
assert_eq!(StatusCode::OK, response.status());
let body = read_body(response).await;
assert_snapshot!(body);
}
}

View File

@ -23,10 +23,9 @@ pub async fn get(user: web::ReqData<User>) -> Result<impl Responder, Application
#[cfg(test)]
mod tests {
use crate::utils::test_helper::{
assert_snapshot, create_test_login_user, test_get, DbTestContext, RequestConfig,
ServiceResponseExt, StatusCode,
assert_snapshot, read_body, test_get, DbTestContext, RequestConfig, StatusCode,
};
use brass_db::models::Role;
use brass_db::models::{Function, Role};
use brass_macros::db_test;
#[db_test]
@ -34,9 +33,8 @@ mod tests {
let app = context.app().await;
let config = RequestConfig::new("/vehicles/new");
create_test_login_user(&context.db_pool, &config).await;
let response = test_get(&app, &config).await;
let response = test_get(&context.db_pool, &app, &config).await;
assert_eq!(StatusCode::UNAUTHORIZED, response.status());
}
@ -44,10 +42,14 @@ mod tests {
async fn area_manager_can_edit(context: &DbTestContext) {
let app = context.app().await;
let config = RequestConfig::new("/vehicles/new").with_role(Role::AreaManager);
create_test_login_user(&context.db_pool, &config).await;
let config = RequestConfig {
uri: "/vehicles/new".to_string(),
role: Role::AreaManager,
function: vec![Function::Posten],
user_area: 1,
};
let response = test_get(&app, &config).await;
let response = test_get(&context.db_pool, &app, &config).await;
assert_eq!(StatusCode::OK, response.status());
}
@ -55,11 +57,17 @@ mod tests {
async fn produces_template_fine_when_user_is_admin(context: &DbTestContext) {
let app = context.app().await;
let config = RequestConfig::new("/vehicles/new").with_role(Role::Admin);
create_test_login_user(&context.db_pool, &config).await;
let config = RequestConfig {
uri: "/vehicles/new".to_string(),
role: Role::Admin,
function: vec![Function::Posten],
user_area: 1,
};
let (status, body) = test_get(&app, &config).await.into_status_and_body().await;
assert_eq!(StatusCode::OK, status);
let response = test_get(&context.db_pool, &app, &config).await;
assert_eq!(StatusCode::OK, response.status());
let body = read_body(response).await;
assert_snapshot!(body);
}
}

View File

@ -39,8 +39,7 @@ pub async fn get(
#[cfg(test)]
mod tests {
use crate::utils::test_helper::{
assert_snapshot, create_test_login_user, test_get, DbTestContext, RequestConfig,
ServiceResponseExt, StatusCode,
assert_snapshot, read_body, test_get, DbTestContext, RequestConfig, StatusCode,
};
use brass_db::models::{Role, Vehicle};
use brass_macros::db_test;
@ -50,9 +49,8 @@ mod tests {
let app = context.app().await;
let config = RequestConfig::new("/vehicles");
create_test_login_user(&context.db_pool, &config).await;
let response = test_get(&app, &config).await;
let response = test_get(&context.db_pool, &app, &config).await;
assert_eq!(StatusCode::UNAUTHORIZED, response.status());
}
@ -61,9 +59,8 @@ mod tests {
let app = context.app().await;
let config = RequestConfig::new("/vehicles").with_role(Role::AreaManager);
create_test_login_user(&context.db_pool, &config).await;
let response = test_get(&app, &config).await;
let response = test_get(&context.db_pool, &app, &config).await;
assert_eq!(StatusCode::OK, response.status());
}
@ -75,10 +72,11 @@ mod tests {
.unwrap();
let config = RequestConfig::new("/vehicles").with_role(Role::Admin);
create_test_login_user(&context.db_pool, &config).await;
let (status, body) = test_get(&app, &config).await.into_status_and_body().await;
assert_eq!(StatusCode::OK, status);
let response = test_get(&context.db_pool, &app, &config).await;
assert_eq!(StatusCode::OK, response.status());
let body = read_body(response).await;
assert_snapshot!(body);
}
}

View File

@ -46,7 +46,7 @@ mod tests {
use crate::{
endpoints::vehicle::VehicleForm,
utils::test_helper::{create_test_login_user, test_post, DbTestContext, RequestConfig},
utils::test_helper::{test_post, DbTestContext, RequestConfig},
};
#[db_test]
@ -67,14 +67,13 @@ mod tests {
let app = context.app().await;
let config = RequestConfig::new("/vehicles/1").with_role(role);
create_test_login_user(&context.db_pool, &config).await;
let request = VehicleForm {
station: "FF Leipzig Ost".to_string(),
radio_call_name: "11.49.2".to_string(),
};
let response = test_post(app, &config, Some(request)).await;
let response = test_post(&context.db_pool, app, &config, Some(request)).await;
assert_eq!(StatusCode::FOUND, response.status());
@ -88,14 +87,13 @@ mod tests {
let app = context.app().await;
let config = RequestConfig::new("/vehicles/1");
create_test_login_user(&context.db_pool, &config).await;
let request = VehicleForm {
station: "FF Leipzig Ost".to_string(),
radio_call_name: "11.49.2".to_string(),
};
let response = test_post(app, &config, Some(request)).await;
let response = test_post(&context.db_pool, app, &config, Some(request)).await;
assert_eq!(StatusCode::UNAUTHORIZED, response.status());
}
@ -105,14 +103,13 @@ mod tests {
let app = context.app().await;
let config = RequestConfig::new("/vehicles/1").with_role(Role::Admin);
create_test_login_user(&context.db_pool, &config).await;
let request = VehicleForm {
station: "FF Leipzig Ost".to_string(),
radio_call_name: "11.49.2".to_string(),
};
let response = test_post(app, &config, Some(request)).await;
let response = test_post(&context.db_pool, app, &config, Some(request)).await;
assert_eq!(StatusCode::NOT_FOUND, response.status());
}

View File

@ -30,7 +30,7 @@ mod tests {
use crate::{
endpoints::vehicle::VehicleForm,
utils::test_helper::{create_test_login_user, test_post, DbTestContext, RequestConfig},
utils::test_helper::{test_post, DbTestContext, RequestConfig},
};
#[db_test]
@ -47,14 +47,13 @@ mod tests {
let app = context.app().await;
let config = RequestConfig::new("/vehicles/new").with_role(role);
create_test_login_user(&context.db_pool, &config).await;
let request = VehicleForm {
station: "FF Leipzig Ost".to_string(),
radio_call_name: "11.49.1".to_string(),
};
let response = test_post(app, &config, Some(request)).await;
let response = test_post(&context.db_pool, app, &config, Some(request)).await;
assert_eq!(StatusCode::FOUND, response.status());
@ -68,14 +67,13 @@ mod tests {
let app = context.app().await;
let config = RequestConfig::new("/vehicles/new");
create_test_login_user(&context.db_pool, &config).await;
let request = VehicleForm {
station: "FF Leipzig Ost".to_string(),
radio_call_name: "11.49.2".to_string(),
};
let response = test_post(app, &config, Some(request)).await;
let response = test_post(&context.db_pool, app, &config, Some(request)).await;
assert_eq!(StatusCode::UNAUTHORIZED, response.status());
}

View File

@ -6,9 +6,7 @@ use actix_web::test;
use chrono::{NaiveDate, NaiveDateTime};
pub use test_context::{setup, teardown, DbTestContext};
pub use test_requests::RequestConfig;
pub use test_requests::{
create_test_login_user, read_body, test_delete, test_get, test_post, test_put,
};
pub use test_requests::{read_body, test_delete, test_get, test_post, test_put};
pub use actix_http::StatusCode;
@ -62,10 +60,7 @@ pub trait ServiceResponseExt {
async fn into_status_and_body(self) -> (StatusCode, String);
}
impl<B> ServiceResponseExt for ServiceResponse<B>
where
B: MessageBody,
{
impl<B> ServiceResponseExt for ServiceResponse<B> where B: MessageBody {
async fn into_status_and_body(self) -> (StatusCode, String) {
let status = self.status();
let response = String::from_utf8(test::read_body(self).await.to_vec()).unwrap();

View File

@ -9,7 +9,7 @@ use actix_web::{
};
use brass_db::models::{Function, Role, User};
use serde::Serialize;
use sqlx::PgPool;
use sqlx::{Pool, Postgres};
pub struct RequestConfig {
pub uri: String,
@ -48,7 +48,15 @@ impl RequestConfig {
}
}
pub async fn create_test_login_user(pool: &PgPool, config: &RequestConfig) {
async fn create_user_and_get_login_cookie<'a, T, R>(
pool: &Pool<Postgres>,
app: &T,
config: &RequestConfig,
) -> Cookie<'a>
where
T: Service<Request, Response = ServiceResponse<R>, Error = Error>,
R: MessageBody + 'a,
{
const HASH: &str = "$argon2id$v=19$m=19456,t=2,p=1$IPiLaPCFZOK69MA1a6GUzw$ZZinpbkP7pXhN7g7dGkh87kGTeuFd/2er1U+y+4IKWo";
const SALT: &str = "IPiLaPCFZOK69MA1a6GUzw";
@ -64,13 +72,7 @@ pub async fn create_test_login_user(pool: &PgPool, config: &RequestConfig) {
)
.await
.unwrap();
}
async fn perform_login_and_get_cookie<'a, T, R>(app: &T) -> Cookie<'a>
where
T: Service<Request, Response = ServiceResponse<R>, Error = Error>,
R: MessageBody + 'a,
{
let login_form = LoginForm {
email: "abc".to_string(),
password: "abc".to_string(),
@ -93,12 +95,16 @@ where
String::from_utf8(test::read_body(response).await.to_vec()).unwrap()
}
pub async fn test_get<T, R>(app: T, config: &RequestConfig) -> ServiceResponse<R>
pub async fn test_get<T, R>(
pool: &Pool<Postgres>,
app: T,
config: &RequestConfig,
) -> ServiceResponse<R>
where
T: Service<Request, Response = ServiceResponse<R>, Error = Error>,
R: MessageBody,
{
let cookie = perform_login_and_get_cookie(&app).await;
let cookie = create_user_and_get_login_cookie(pool, &app, &config).await;
let get_request = test::TestRequest::get()
.uri(&config.uri)
@ -109,6 +115,7 @@ where
}
pub async fn test_post<T, R, F>(
pool: &Pool<Postgres>,
app: T,
config: &RequestConfig,
form: Option<F>,
@ -118,7 +125,7 @@ where
R: MessageBody,
F: Serialize,
{
let cookie = perform_login_and_get_cookie(&app).await;
let cookie = create_user_and_get_login_cookie(pool, &app, config).await;
let post_request = test::TestRequest::post()
.uri(&config.uri)
@ -130,6 +137,7 @@ where
}
pub async fn test_put<T, R, F>(
pool: &Pool<Postgres>,
app: &T,
config: &RequestConfig,
form: Option<F>,
@ -139,7 +147,7 @@ where
R: MessageBody,
F: Serialize,
{
let cookie = perform_login_and_get_cookie(&app).await;
let cookie = create_user_and_get_login_cookie(pool, app, config).await;
let put_request = test::TestRequest::put()
.uri(&config.uri)
@ -150,12 +158,16 @@ where
test::call_service(app, put_request).await
}
pub async fn test_delete<T, R>(app: T, config: &RequestConfig) -> ServiceResponse<R>
pub async fn test_delete<T, R>(
pool: &Pool<Postgres>,
app: T,
config: &RequestConfig,
) -> ServiceResponse<R>
where
T: Service<Request, Response = ServiceResponse<R>, Error = Error>,
R: MessageBody,
{
let cookie = perform_login_and_get_cookie(&app).await;
let cookie = create_user_and_get_login_cookie(pool, &app, config).await;
let delete_request = test::TestRequest::delete()
.uri(&config.uri)

View File

@ -65,6 +65,22 @@ $crimson: #00d1b2; //#B80F0A;
vertical-align: middle;
}
// TODO: refactor into bulmas is-hidden?
.result {
visibility: hidden;
}
.fadeout {
visibility: visible;
opacity: 0;
transition: opacity 2s ease-in;
}
// TODO: refactor into bulmas is-hidden?
section.htmx-request {
visibility: hidden;
}
a.dropdown-item[disabled] {
color: hsl(221, 14%, 48%); // $grey;
cursor: default;