Compare commits
No commits in common. "fac14ce9f1cb64175dfacd0528df2406b96860d6" and "66dd99dd7ce65f79068c23a70317c15d8b2e37fd" have entirely different histories.
fac14ce9f1
...
66dd99dd7c
@ -25,9 +25,7 @@ pub async fn delete(
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::utils::test_helper::{
|
use crate::utils::test_helper::{test_delete, DbTestContext, RequestConfig, StatusCode};
|
||||||
create_test_login_user, test_delete, DbTestContext, RequestConfig, StatusCode,
|
|
||||||
};
|
|
||||||
use brass_db::models::{Area, Function, Location, Role};
|
use brass_db::models::{Area, Function, Location, Role};
|
||||||
use brass_macros::db_test;
|
use brass_macros::db_test;
|
||||||
|
|
||||||
@ -48,8 +46,7 @@ mod tests {
|
|||||||
function: vec![Function::Posten],
|
function: vec![Function::Posten],
|
||||||
user_area: 1,
|
user_area: 1,
|
||||||
};
|
};
|
||||||
create_test_login_user(&context.db_pool, &config).await;
|
let response = test_delete(&context.db_pool, app, &config).await;
|
||||||
let response = test_delete(app, &config).await;
|
|
||||||
|
|
||||||
assert_eq!(StatusCode::OK, response.status());
|
assert_eq!(StatusCode::OK, response.status());
|
||||||
assert!(Area::read_by_id(&context.db_pool, 2)
|
assert!(Area::read_by_id(&context.db_pool, 2)
|
||||||
@ -61,9 +58,8 @@ mod tests {
|
|||||||
#[db_test]
|
#[db_test]
|
||||||
async fn returns_unauthorized_when_user_is_not_admin(context: &DbTestContext) {
|
async fn returns_unauthorized_when_user_is_not_admin(context: &DbTestContext) {
|
||||||
let app = context.app().await;
|
let app = context.app().await;
|
||||||
let config = RequestConfig::new("/area/delete/1");
|
let response =
|
||||||
create_test_login_user(&context.db_pool, &config).await;
|
test_delete(&context.db_pool, app, &RequestConfig::new("/area/delete/1")).await;
|
||||||
let response = test_delete(app, &config).await;
|
|
||||||
|
|
||||||
assert_eq!(StatusCode::UNAUTHORIZED, response.status());
|
assert_eq!(StatusCode::UNAUTHORIZED, response.status());
|
||||||
}
|
}
|
||||||
@ -77,8 +73,7 @@ mod tests {
|
|||||||
function: vec![Function::Posten],
|
function: vec![Function::Posten],
|
||||||
user_area: 1,
|
user_area: 1,
|
||||||
};
|
};
|
||||||
create_test_login_user(&context.db_pool, &config).await;
|
let response = test_delete(&context.db_pool, app, &config).await;
|
||||||
let response = test_delete(app, &config).await;
|
|
||||||
|
|
||||||
assert_eq!(StatusCode::NOT_FOUND, response.status());
|
assert_eq!(StatusCode::NOT_FOUND, response.status());
|
||||||
}
|
}
|
||||||
@ -100,8 +95,7 @@ mod tests {
|
|||||||
function: vec![Function::Posten],
|
function: vec![Function::Posten],
|
||||||
user_area: 1,
|
user_area: 1,
|
||||||
};
|
};
|
||||||
create_test_login_user(&context.db_pool, &config).await;
|
let response = test_delete(&context.db_pool, app, &config).await;
|
||||||
let response = test_delete(app, &config).await;
|
|
||||||
|
|
||||||
assert_eq!(StatusCode::OK, response.status());
|
assert_eq!(StatusCode::OK, response.status());
|
||||||
assert!(Area::read_by_id(&context.db_pool, 2)
|
assert!(Area::read_by_id(&context.db_pool, 2)
|
||||||
|
@ -36,7 +36,7 @@ mod tests {
|
|||||||
use brass_macros::db_test;
|
use brass_macros::db_test;
|
||||||
|
|
||||||
use crate::utils::test_helper::{
|
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]
|
#[db_test]
|
||||||
@ -44,8 +44,7 @@ mod tests {
|
|||||||
let app = context.app().await;
|
let app = context.app().await;
|
||||||
|
|
||||||
let config = RequestConfig::new("/area/edit/1").with_role(Role::Admin);
|
let config = RequestConfig::new("/area/edit/1").with_role(Role::Admin);
|
||||||
create_test_login_user(&context.db_pool, &config).await;
|
let response = test_get(&context.db_pool, app, &config).await;
|
||||||
let response = test_get(app, &config).await;
|
|
||||||
|
|
||||||
assert_eq!(StatusCode::OK, response.status());
|
assert_eq!(StatusCode::OK, response.status());
|
||||||
|
|
||||||
@ -58,8 +57,7 @@ mod tests {
|
|||||||
let app = context.app().await;
|
let app = context.app().await;
|
||||||
|
|
||||||
let config = RequestConfig::new("/area/edit/1").with_role(Role::AreaManager);
|
let config = RequestConfig::new("/area/edit/1").with_role(Role::AreaManager);
|
||||||
create_test_login_user(&context.db_pool, &config).await;
|
let response = test_get(&context.db_pool, app, &config).await;
|
||||||
let response = test_get(app, &config).await;
|
|
||||||
|
|
||||||
assert_eq!(StatusCode::UNAUTHORIZED, response.status());
|
assert_eq!(StatusCode::UNAUTHORIZED, response.status());
|
||||||
}
|
}
|
||||||
@ -69,8 +67,7 @@ mod tests {
|
|||||||
let app = context.app().await;
|
let app = context.app().await;
|
||||||
|
|
||||||
let config = RequestConfig::new("/area/edit/2").with_role(Role::Admin);
|
let config = RequestConfig::new("/area/edit/2").with_role(Role::Admin);
|
||||||
create_test_login_user(&context.db_pool, &config).await;
|
let response = test_get(&context.db_pool, app, &config).await;
|
||||||
let response = test_get(app, &config).await;
|
|
||||||
|
|
||||||
assert_eq!(StatusCode::NOT_FOUND, response.status());
|
assert_eq!(StatusCode::NOT_FOUND, response.status());
|
||||||
}
|
}
|
||||||
|
@ -22,8 +22,7 @@ async fn get(user: web::ReqData<User>) -> Result<impl Responder, ApplicationErro
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::utils::test_helper::{
|
use crate::utils::test_helper::{
|
||||||
assert_snapshot, create_test_login_user, test_get, DbTestContext, RequestConfig,
|
assert_snapshot, test_get, DbTestContext, RequestConfig, ServiceResponseExt, StatusCode,
|
||||||
ServiceResponseExt, StatusCode,
|
|
||||||
};
|
};
|
||||||
use brass_db::models::Role;
|
use brass_db::models::Role;
|
||||||
use brass_macros::db_test;
|
use brass_macros::db_test;
|
||||||
@ -32,8 +31,7 @@ mod tests {
|
|||||||
async fn produces_template_when_user_is_admin(context: &DbTestContext) {
|
async fn produces_template_when_user_is_admin(context: &DbTestContext) {
|
||||||
let config = RequestConfig::new("/area/new").with_role(Role::Admin);
|
let config = RequestConfig::new("/area/new").with_role(Role::Admin);
|
||||||
|
|
||||||
create_test_login_user(&context.db_pool, &config).await;
|
let response = test_get(&context.db_pool, context.app().await, &config).await;
|
||||||
let response = test_get(context.app().await, &config).await;
|
|
||||||
let (status, body) = response.into_status_and_body().await;
|
let (status, body) = response.into_status_and_body().await;
|
||||||
|
|
||||||
assert_eq!(StatusCode::OK, status);
|
assert_eq!(StatusCode::OK, status);
|
||||||
@ -43,8 +41,7 @@ mod tests {
|
|||||||
#[db_test]
|
#[db_test]
|
||||||
async fn returns_unauthorized_when_user_is_not_admin(context: &DbTestContext) {
|
async fn returns_unauthorized_when_user_is_not_admin(context: &DbTestContext) {
|
||||||
let config = RequestConfig::new("/area/new").with_role(Role::AreaManager);
|
let config = RequestConfig::new("/area/new").with_role(Role::AreaManager);
|
||||||
create_test_login_user(&context.db_pool, &config).await;
|
let response = test_get(&context.db_pool, context.app().await, &config).await;
|
||||||
let response = test_get(context.app().await, &config).await;
|
|
||||||
|
|
||||||
assert_eq!(StatusCode::UNAUTHORIZED, response.status());
|
assert_eq!(StatusCode::UNAUTHORIZED, response.status());
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ mod tests {
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
endpoints::area::AreaForm,
|
endpoints::area::AreaForm,
|
||||||
utils::test_helper::{create_test_login_user, test_post, DbTestContext, RequestConfig},
|
utils::test_helper::{test_post, DbTestContext, RequestConfig},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[db_test]
|
#[db_test]
|
||||||
@ -50,13 +50,12 @@ mod tests {
|
|||||||
function: vec![Function::Posten],
|
function: vec![Function::Posten],
|
||||||
user_area: 1,
|
user_area: 1,
|
||||||
};
|
};
|
||||||
create_test_login_user(&context.db_pool, &config).await;
|
|
||||||
|
|
||||||
let request = AreaForm {
|
let request = AreaForm {
|
||||||
name: "Neuer Name".to_string(),
|
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());
|
assert_eq!(StatusCode::FOUND, response.status());
|
||||||
|
|
||||||
@ -78,13 +77,12 @@ mod tests {
|
|||||||
function: vec![Function::Posten],
|
function: vec![Function::Posten],
|
||||||
user_area: 1,
|
user_area: 1,
|
||||||
};
|
};
|
||||||
create_test_login_user(&context.db_pool, &config).await;
|
|
||||||
|
|
||||||
let request = AreaForm {
|
let request = AreaForm {
|
||||||
name: "Neuer Name".to_string(),
|
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());
|
assert_eq!(StatusCode::UNAUTHORIZED, response.status());
|
||||||
}
|
}
|
||||||
@ -99,13 +97,12 @@ mod tests {
|
|||||||
function: vec![Function::Posten],
|
function: vec![Function::Posten],
|
||||||
user_area: 1,
|
user_area: 1,
|
||||||
};
|
};
|
||||||
create_test_login_user(&context.db_pool, &config).await;
|
|
||||||
|
|
||||||
let request = AreaForm {
|
let request = AreaForm {
|
||||||
name: "Neuer Name".to_string(),
|
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());
|
assert_eq!(StatusCode::NOT_FOUND, response.status());
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ mod tests {
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
endpoints::area::AreaForm,
|
endpoints::area::AreaForm,
|
||||||
utils::test_helper::{create_test_login_user, test_post, DbTestContext, RequestConfig},
|
utils::test_helper::{test_post, DbTestContext, RequestConfig},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[db_test]
|
#[db_test]
|
||||||
@ -43,13 +43,12 @@ mod tests {
|
|||||||
function: vec![Function::Posten],
|
function: vec![Function::Posten],
|
||||||
user_area: 1,
|
user_area: 1,
|
||||||
};
|
};
|
||||||
create_test_login_user(&context.db_pool, &config).await;
|
|
||||||
|
|
||||||
let request = AreaForm {
|
let request = AreaForm {
|
||||||
name: "Neuer Name".to_string(),
|
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());
|
assert_eq!(StatusCode::FOUND, response.status());
|
||||||
|
|
||||||
@ -71,13 +70,12 @@ mod tests {
|
|||||||
function: vec![Function::Posten],
|
function: vec![Function::Posten],
|
||||||
user_area: 1,
|
user_area: 1,
|
||||||
};
|
};
|
||||||
create_test_login_user(&context.db_pool, &config).await;
|
|
||||||
|
|
||||||
let request = AreaForm {
|
let request = AreaForm {
|
||||||
name: "Neuer Name".to_string(),
|
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());
|
assert_eq!(StatusCode::UNAUTHORIZED, response.status());
|
||||||
}
|
}
|
||||||
|
@ -71,9 +71,7 @@ mod tests {
|
|||||||
use fake::{faker::chrono::en::Date, Fake, Faker};
|
use fake::{faker::chrono::en::Date, Fake, Faker};
|
||||||
use sqlx::PgPool;
|
use sqlx::PgPool;
|
||||||
|
|
||||||
use crate::utils::test_helper::{
|
use crate::utils::test_helper::{test_delete, DbTestContext, RequestConfig};
|
||||||
create_test_login_user, test_delete, DbTestContext, RequestConfig,
|
|
||||||
};
|
|
||||||
use brass_db::models::{
|
use brass_db::models::{
|
||||||
Assignment, AssignmentChangeset, Availability, AvailabilityChangeset, Event,
|
Assignment, AssignmentChangeset, Availability, AvailabilityChangeset, Event,
|
||||||
EventChangeset, Function, Location, Role, User,
|
EventChangeset, Function, Location, Role, User,
|
||||||
@ -120,9 +118,8 @@ mod tests {
|
|||||||
function: vec![Function::Posten],
|
function: vec![Function::Posten],
|
||||||
user_area: 1,
|
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!(StatusCode::OK, response.status());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
@ -145,9 +142,8 @@ mod tests {
|
|||||||
function: vec![Function::Posten],
|
function: vec![Function::Posten],
|
||||||
user_area: 1,
|
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());
|
assert_eq!(StatusCode::UNAUTHORIZED, response.status());
|
||||||
}
|
}
|
||||||
@ -161,9 +157,8 @@ mod tests {
|
|||||||
function: vec![Function::Posten],
|
function: vec![Function::Posten],
|
||||||
user_area: 1,
|
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());
|
assert_eq!(StatusCode::NOT_FOUND, response.status());
|
||||||
}
|
}
|
||||||
@ -179,9 +174,8 @@ mod tests {
|
|||||||
function: vec![Function::Posten],
|
function: vec![Function::Posten],
|
||||||
user_area: 1,
|
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());
|
assert_eq!(StatusCode::NOT_FOUND, response.status());
|
||||||
}
|
}
|
||||||
|
@ -91,8 +91,8 @@ mod tests {
|
|||||||
use sqlx::PgPool;
|
use sqlx::PgPool;
|
||||||
|
|
||||||
use crate::utils::test_helper::{
|
use crate::utils::test_helper::{
|
||||||
assert_snapshot, create_test_login_user, test_post, DbTestContext, NaiveDateTimeExt,
|
assert_snapshot, test_post, DbTestContext, NaiveDateTimeExt, RequestConfig,
|
||||||
RequestConfig, ServiceResponseExt,
|
ServiceResponseExt,
|
||||||
};
|
};
|
||||||
|
|
||||||
async fn arrange(pool: &PgPool) {
|
async fn arrange(pool: &PgPool) {
|
||||||
@ -139,9 +139,8 @@ mod tests {
|
|||||||
|
|
||||||
let config = RequestConfig::new("/assignments/new?availability=1&function=1&event=1")
|
let config = RequestConfig::new("/assignments/new?availability=1&function=1&event=1")
|
||||||
.with_role(Role::Admin);
|
.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;
|
let (status, body) = response.into_status_and_body().await;
|
||||||
|
|
||||||
assert_eq!(StatusCode::OK, status, "{body}");
|
assert_eq!(StatusCode::OK, status, "{body}");
|
||||||
@ -160,9 +159,8 @@ mod tests {
|
|||||||
|
|
||||||
let config = RequestConfig::new("/assignments/new?availability=1&function=1&event=1")
|
let config = RequestConfig::new("/assignments/new?availability=1&function=1&event=1")
|
||||||
.with_role(Role::Admin);
|
.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());
|
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")
|
let config = RequestConfig::new("/assignments/new?availability=1&function=1&event=1")
|
||||||
.with_role(Role::Admin);
|
.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());
|
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")
|
let config = RequestConfig::new("/assignments/new?availability=1&function=1&event=1")
|
||||||
.with_role(Role::AreaManager)
|
.with_role(Role::AreaManager)
|
||||||
.with_user_area(2);
|
.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());
|
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")
|
let config = RequestConfig::new("/assignments/new?availability=1&function=1&event=1")
|
||||||
.with_role(Role::Admin);
|
.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());
|
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")
|
let config = RequestConfig::new("/assignments/new?availability=1&function=1&event=1")
|
||||||
.with_role(Role::Admin);
|
.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());
|
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")
|
let config = RequestConfig::new("/assignments/new?availability=1&function=1&event=2")
|
||||||
.with_role(Role::Admin);
|
.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());
|
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")
|
let config = RequestConfig::new("/assignments/new?availability=1&function=5&event=1")
|
||||||
.with_role(Role::Admin);
|
.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());
|
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")
|
let config = RequestConfig::new("/assignments/new?availability=2&function=5&event=1")
|
||||||
.with_role(Role::Admin);
|
.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());
|
assert_eq!(StatusCode::UNPROCESSABLE_ENTITY, response.status());
|
||||||
}
|
}
|
||||||
|
@ -23,44 +23,3 @@ pub async fn delete(
|
|||||||
|
|
||||||
Ok(HttpResponse::Ok().finish())
|
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
|
|
||||||
}
|
|
||||||
|
@ -75,8 +75,7 @@ mod tests {
|
|||||||
use brass_macros::db_test;
|
use brass_macros::db_test;
|
||||||
|
|
||||||
use crate::utils::test_helper::{
|
use crate::utils::test_helper::{
|
||||||
assert_snapshot, create_test_login_user, test_get, DbTestContext, RequestConfig,
|
assert_snapshot, test_get, DbTestContext, RequestConfig, ServiceResponseExt,
|
||||||
ServiceResponseExt,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[db_test]
|
#[db_test]
|
||||||
@ -84,8 +83,7 @@ mod tests {
|
|||||||
let app = context.app().await;
|
let app = context.app().await;
|
||||||
|
|
||||||
let config = RequestConfig::new("/");
|
let config = RequestConfig::new("/");
|
||||||
create_test_login_user(&context.db_pool, &config).await;
|
let response = test_get(&context.db_pool, app, &config).await;
|
||||||
let response = test_get(app, &config).await;
|
|
||||||
|
|
||||||
let (status, body) = response.into_status_and_body().await;
|
let (status, body) = response.into_status_and_body().await;
|
||||||
|
|
||||||
|
@ -25,9 +25,7 @@ pub async fn delete(
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::utils::test_helper::{
|
use crate::utils::test_helper::{test_delete, DbTestContext, RequestConfig, StatusCode};
|
||||||
create_test_login_user, test_delete, DbTestContext, RequestConfig, StatusCode,
|
|
||||||
};
|
|
||||||
use brass_db::models::{Clothing, Role};
|
use brass_db::models::{Clothing, Role};
|
||||||
use brass_macros::db_test;
|
use brass_macros::db_test;
|
||||||
|
|
||||||
@ -41,9 +39,8 @@ mod tests {
|
|||||||
assert_eq!(2, Clothing::read_all(&context.db_pool).await.unwrap().len());
|
assert_eq!(2, Clothing::read_all(&context.db_pool).await.unwrap().len());
|
||||||
|
|
||||||
let config = RequestConfig::new("/clothing/1").with_role(Role::Admin);
|
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!(StatusCode::OK, response.status());
|
||||||
|
|
||||||
assert_eq!(1, Clothing::read_all(&context.db_pool).await.unwrap().len());
|
assert_eq!(1, Clothing::read_all(&context.db_pool).await.unwrap().len());
|
||||||
@ -53,9 +50,7 @@ mod tests {
|
|||||||
#[db_test]
|
#[db_test]
|
||||||
async fn returns_unauthorized_when_user_is_user(context: &DbTestContext) {
|
async fn returns_unauthorized_when_user_is_user(context: &DbTestContext) {
|
||||||
let app = context.app().await;
|
let app = context.app().await;
|
||||||
let config = RequestConfig::new("/clothing/1");
|
let response = test_delete(&context.db_pool, app, &RequestConfig::new("/clothing/1")).await;
|
||||||
create_test_login_user(&context.db_pool, &config).await;
|
|
||||||
let response = test_delete(app, &config).await;
|
|
||||||
|
|
||||||
assert_eq!(StatusCode::UNAUTHORIZED, response.status());
|
assert_eq!(StatusCode::UNAUTHORIZED, response.status());
|
||||||
}
|
}
|
||||||
@ -63,9 +58,12 @@ mod tests {
|
|||||||
#[db_test]
|
#[db_test]
|
||||||
async fn returns_unauthorized_when_user_is_area_manager(context: &DbTestContext) {
|
async fn returns_unauthorized_when_user_is_area_manager(context: &DbTestContext) {
|
||||||
let app = context.app().await;
|
let app = context.app().await;
|
||||||
let config = RequestConfig::new("/clothing/1").with_role(Role::AreaManager);
|
let response = test_delete(
|
||||||
create_test_login_user(&context.db_pool, &config).await;
|
&context.db_pool,
|
||||||
let response = test_delete(app, &config).await;
|
app,
|
||||||
|
&RequestConfig::new("/clothing/1").with_role(Role::AreaManager),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
|
||||||
assert_eq!(StatusCode::UNAUTHORIZED, response.status());
|
assert_eq!(StatusCode::UNAUTHORIZED, response.status());
|
||||||
}
|
}
|
||||||
@ -73,9 +71,12 @@ mod tests {
|
|||||||
#[db_test]
|
#[db_test]
|
||||||
async fn returns_not_found_when_clothing_does_not_exist(context: &DbTestContext) {
|
async fn returns_not_found_when_clothing_does_not_exist(context: &DbTestContext) {
|
||||||
let app = context.app().await;
|
let app = context.app().await;
|
||||||
let config = RequestConfig::new("/clothing/100").with_role(Role::Admin);
|
let response = test_delete(
|
||||||
create_test_login_user(&context.db_pool, &config).await;
|
&context.db_pool,
|
||||||
let response = test_delete(app, &config).await;
|
app,
|
||||||
|
&RequestConfig::new("/clothing/100").with_role(Role::Admin),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
|
||||||
assert_eq!(StatusCode::NOT_FOUND, response.status());
|
assert_eq!(StatusCode::NOT_FOUND, response.status());
|
||||||
}
|
}
|
||||||
|
@ -32,8 +32,7 @@ pub async fn get(
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::utils::test_helper::{
|
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, StatusCode,
|
||||||
StatusCode,
|
|
||||||
};
|
};
|
||||||
use brass_db::models::{Clothing, Role};
|
use brass_db::models::{Clothing, Role};
|
||||||
use brass_macros::db_test;
|
use brass_macros::db_test;
|
||||||
@ -47,9 +46,8 @@ mod tests {
|
|||||||
let app = context.app().await;
|
let app = context.app().await;
|
||||||
|
|
||||||
let config = RequestConfig::new("/clothing/edit/1");
|
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());
|
assert_eq!(StatusCode::UNAUTHORIZED, response.status());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,9 +60,8 @@ mod tests {
|
|||||||
let app = context.app().await;
|
let app = context.app().await;
|
||||||
|
|
||||||
let config = RequestConfig::new("/clothing/edit/1").with_role(Role::AreaManager);
|
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());
|
assert_eq!(StatusCode::UNAUTHORIZED, response.status());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,9 +73,8 @@ mod tests {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let config = RequestConfig::new("/clothing/edit/1").with_role(Role::Admin);
|
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());
|
assert_eq!(StatusCode::OK, response.status());
|
||||||
|
|
||||||
let body = read_body(response).await;
|
let body = read_body(response).await;
|
||||||
|
@ -39,7 +39,7 @@ pub async fn get(
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::utils::test_helper::{
|
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_db::models::{Clothing, Role};
|
||||||
use brass_macros::db_test;
|
use brass_macros::db_test;
|
||||||
@ -49,9 +49,8 @@ mod tests {
|
|||||||
let app = context.app().await;
|
let app = context.app().await;
|
||||||
|
|
||||||
let config = RequestConfig::new("/clothing");
|
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());
|
assert_eq!(StatusCode::UNAUTHORIZED, response.status());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,9 +59,8 @@ mod tests {
|
|||||||
let app = context.app().await;
|
let app = context.app().await;
|
||||||
|
|
||||||
let config = RequestConfig::new("/clothing").with_role(Role::AreaManager);
|
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());
|
assert_eq!(StatusCode::UNAUTHORIZED, response.status());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,9 +72,8 @@ mod tests {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let config = RequestConfig::new("/clothing").with_role(Role::Admin);
|
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());
|
assert_eq!(StatusCode::OK, response.status());
|
||||||
|
|
||||||
let body = read_body(response).await;
|
let body = read_body(response).await;
|
||||||
|
@ -29,8 +29,7 @@ pub async fn get(
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::utils::test_helper::{
|
use crate::utils::test_helper::{
|
||||||
assert_snapshot, create_test_login_user, test_get, DbTestContext, RequestConfig,
|
assert_snapshot, read_body, test_get, DbTestContext, RequestConfig, StatusCode,
|
||||||
ServiceResponseExt, StatusCode,
|
|
||||||
};
|
};
|
||||||
use brass_db::models::{Clothing, Role};
|
use brass_db::models::{Clothing, Role};
|
||||||
use brass_macros::db_test;
|
use brass_macros::db_test;
|
||||||
@ -44,9 +43,8 @@ mod tests {
|
|||||||
let app = context.app().await;
|
let app = context.app().await;
|
||||||
|
|
||||||
let config = RequestConfig::new("/clothing/1");
|
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());
|
assert_eq!(StatusCode::UNAUTHORIZED, response.status());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,9 +57,8 @@ mod tests {
|
|||||||
let app = context.app().await;
|
let app = context.app().await;
|
||||||
|
|
||||||
let config = RequestConfig::new("/clothing/1").with_role(Role::AreaManager);
|
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());
|
assert_eq!(StatusCode::UNAUTHORIZED, response.status());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,10 +70,11 @@ mod tests {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let config = RequestConfig::new("/clothing/1").with_role(Role::Admin);
|
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;
|
let response = test_get(&context.db_pool, &app, &config).await;
|
||||||
assert_eq!(StatusCode::OK, status);
|
assert_eq!(StatusCode::OK, response.status());
|
||||||
|
|
||||||
|
let body = read_body(response).await;
|
||||||
assert_snapshot!(body);
|
assert_snapshot!(body);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,8 +69,8 @@ mod tests {
|
|||||||
use chrono::NaiveDateTime;
|
use chrono::NaiveDateTime;
|
||||||
|
|
||||||
use crate::utils::test_helper::{
|
use crate::utils::test_helper::{
|
||||||
assert_snapshot, create_test_login_user, test_get, DbTestContext, NaiveDateTimeExt,
|
assert_snapshot, test_get, DbTestContext, NaiveDateTimeExt, RequestConfig,
|
||||||
RequestConfig, ServiceResponseExt, StatusCode,
|
ServiceResponseExt, StatusCode,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[db_test]
|
#[db_test]
|
||||||
@ -96,8 +96,7 @@ mod tests {
|
|||||||
Event::create(&context.db_pool, changeset).await.unwrap();
|
Event::create(&context.db_pool, changeset).await.unwrap();
|
||||||
|
|
||||||
let config = RequestConfig::new("/events/1/edit").with_role(Role::Admin);
|
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.db_pool, context.app().await, &config).await;
|
||||||
let response = test_get(context.app().await, &config).await;
|
|
||||||
let (status, body) = response.into_status_and_body().await;
|
let (status, body) = response.into_status_and_body().await;
|
||||||
|
|
||||||
assert_eq!(StatusCode::OK, status);
|
assert_eq!(StatusCode::OK, status);
|
||||||
|
@ -32,9 +32,7 @@ pub async fn post(
|
|||||||
mod tests {
|
mod tests {
|
||||||
use crate::{
|
use crate::{
|
||||||
endpoints::location::LocationForm,
|
endpoints::location::LocationForm,
|
||||||
utils::test_helper::{
|
utils::test_helper::{test_post, DbTestContext, RequestConfig, StatusCode},
|
||||||
create_test_login_user, test_post, DbTestContext, RequestConfig, StatusCode,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
use brass_db::models::{Function, Location, Role};
|
use brass_db::models::{Function, Location, Role};
|
||||||
use brass_macros::db_test;
|
use brass_macros::db_test;
|
||||||
@ -48,14 +46,13 @@ mod tests {
|
|||||||
function: vec![Function::Posten],
|
function: vec![Function::Posten],
|
||||||
user_area: 1,
|
user_area: 1,
|
||||||
};
|
};
|
||||||
create_test_login_user(&context.db_pool, &config).await;
|
|
||||||
|
|
||||||
let form = LocationForm {
|
let form = LocationForm {
|
||||||
name: "Hauptbahnhof".to_string(),
|
name: "Hauptbahnhof".to_string(),
|
||||||
area: Some(1),
|
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!(StatusCode::FOUND, response.status());
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
@ -77,14 +74,13 @@ mod tests {
|
|||||||
function: vec![Function::Posten],
|
function: vec![Function::Posten],
|
||||||
user_area: 1,
|
user_area: 1,
|
||||||
};
|
};
|
||||||
create_test_login_user(&context.db_pool, &config).await;
|
|
||||||
|
|
||||||
let form = LocationForm {
|
let form = LocationForm {
|
||||||
name: "Hauptbahnhof".to_string(),
|
name: "Hauptbahnhof".to_string(),
|
||||||
area: None,
|
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!(StatusCode::FOUND, response.status());
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -22,16 +22,14 @@ mod tests {
|
|||||||
use brass_macros::db_test;
|
use brass_macros::db_test;
|
||||||
|
|
||||||
use crate::utils::test_helper::{
|
use crate::utils::test_helper::{
|
||||||
assert_snapshot, create_test_login_user, test_get, DbTestContext, RequestConfig,
|
assert_snapshot, test_get, DbTestContext, RequestConfig, ServiceResponseExt,
|
||||||
ServiceResponseExt,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[db_test]
|
#[db_test]
|
||||||
async fn produces_template_fine(context: &DbTestContext) {
|
async fn produces_template_fine(context: &DbTestContext) {
|
||||||
let config = RequestConfig::new("/users/changepassword");
|
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;
|
let (status, body) = response.into_status_and_body().await;
|
||||||
|
|
||||||
assert_eq!(StatusCode::OK, status);
|
assert_eq!(StatusCode::OK, status);
|
||||||
|
@ -103,7 +103,6 @@ mod tests {
|
|||||||
function: vec![Function::Posten],
|
function: vec![Function::Posten],
|
||||||
user_area: 1,
|
user_area: 1,
|
||||||
};
|
};
|
||||||
create_test_login_user(&context.db_pool, &config).await;
|
|
||||||
|
|
||||||
let new_name: String = Name().fake();
|
let new_name: String = Name().fake();
|
||||||
let new_mail: String = SafeEmail().fake();
|
let new_mail: String = SafeEmail().fake();
|
||||||
@ -118,7 +117,7 @@ mod tests {
|
|||||||
area: Some(2),
|
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());
|
assert_eq!(StatusCode::FOUND, response.status());
|
||||||
|
|
||||||
let updated_user = User::read_by_id(&context.db_pool, 1)
|
let updated_user = User::read_by_id(&context.db_pool, 1)
|
||||||
@ -142,7 +141,6 @@ mod tests {
|
|||||||
function: vec![Function::Posten],
|
function: vec![Function::Posten],
|
||||||
user_area: 1,
|
user_area: 1,
|
||||||
};
|
};
|
||||||
create_test_login_user(&context.db_pool, &config).await;
|
|
||||||
|
|
||||||
let form = NewOrEditUserForm {
|
let form = NewOrEditUserForm {
|
||||||
name: "".to_string(),
|
name: "".to_string(),
|
||||||
@ -154,7 +152,7 @@ mod tests {
|
|||||||
area: Some(1),
|
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());
|
assert_eq!(StatusCode::BAD_REQUEST, response.status());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,7 +162,6 @@ mod tests {
|
|||||||
|
|
||||||
let app = context.app().await;
|
let app = context.app().await;
|
||||||
let config = RequestConfig::new("/users/edit/1").with_role(Role::Admin);
|
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_name: String = Name().fake();
|
||||||
let new_mail: String = String::from("NONLowercaseEMAIL@example.com");
|
let new_mail: String = String::from("NONLowercaseEMAIL@example.com");
|
||||||
@ -179,7 +176,7 @@ mod tests {
|
|||||||
area: Some(1),
|
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;
|
let (status, body) = response.into_status_and_body().await;
|
||||||
debug!(body);
|
debug!(body);
|
||||||
|
|
||||||
@ -201,7 +198,6 @@ mod tests {
|
|||||||
|
|
||||||
let app = context.app().await;
|
let app = context.app().await;
|
||||||
let config = RequestConfig::new("/users/edit/1").with_role(Role::Admin);
|
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)
|
let second_user = User::read_by_id(&context.db_pool, 2)
|
||||||
.await
|
.await
|
||||||
@ -221,7 +217,7 @@ mod tests {
|
|||||||
area: Some(2),
|
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());
|
assert_eq!(StatusCode::UNPROCESSABLE_ENTITY, response.status());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,8 +83,7 @@ async fn handle_lock_state_for_user(
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::utils::test_helper::{
|
use crate::utils::test_helper::{
|
||||||
assert_snapshot, create_test_login_user, read_body, test_put, DbTestContext, RequestConfig,
|
assert_snapshot, read_body, test_put, DbTestContext, RequestConfig, StatusCode,
|
||||||
StatusCode,
|
|
||||||
};
|
};
|
||||||
use brass_db::models::{Area, Function, Role, User};
|
use brass_db::models::{Area, Function, Role, User};
|
||||||
use brass_macros::db_test;
|
use brass_macros::db_test;
|
||||||
@ -95,18 +94,28 @@ mod tests {
|
|||||||
let app = context.app().await;
|
let app = context.app().await;
|
||||||
User::create(&context.db_pool, &Faker.fake()).await.unwrap();
|
User::create(&context.db_pool, &Faker.fake()).await.unwrap();
|
||||||
|
|
||||||
let lock_config = RequestConfig::new("/users/1/lock").with_role(Role::Admin);
|
let lock_config = RequestConfig {
|
||||||
create_test_login_user(&context.db_pool, &lock_config).await;
|
uri: "/users/1/lock".to_string(),
|
||||||
|
role: Role::Admin,
|
||||||
let lock_response = test_put::<_, _, String>(&app, &lock_config, None).await;
|
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());
|
assert_eq!(StatusCode::OK, lock_response.status());
|
||||||
|
|
||||||
let lock_body = read_body(lock_response).await;
|
let lock_body = read_body(lock_response).await;
|
||||||
assert_snapshot!(lock_body);
|
assert_snapshot!(lock_body);
|
||||||
|
|
||||||
let unlock_config = RequestConfig::new("/users/1/unlock").with_role(Role::Admin);
|
let unlock_config = RequestConfig {
|
||||||
let unlock_response = test_put::<_, _, String>(&app, &unlock_config, None).await;
|
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());
|
assert_eq!(StatusCode::OK, unlock_response.status());
|
||||||
|
|
||||||
@ -126,9 +135,8 @@ mod tests {
|
|||||||
function: vec![Function::Posten],
|
function: vec![Function::Posten],
|
||||||
user_area: 2,
|
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())
|
assert_eq!(StatusCode::UNAUTHORIZED, response.status())
|
||||||
}
|
}
|
||||||
@ -143,9 +151,8 @@ mod tests {
|
|||||||
function: vec![Function::Posten],
|
function: vec![Function::Posten],
|
||||||
user_area: 1,
|
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())
|
assert_eq!(StatusCode::BAD_REQUEST, response.status())
|
||||||
}
|
}
|
||||||
@ -160,9 +167,8 @@ mod tests {
|
|||||||
function: vec![Function::Posten],
|
function: vec![Function::Posten],
|
||||||
user_area: 1,
|
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())
|
assert_eq!(StatusCode::NOT_FOUND, response.status())
|
||||||
}
|
}
|
||||||
|
@ -75,8 +75,7 @@ async fn handle_subscription_to_notifications(
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::utils::test_helper::{
|
use crate::utils::test_helper::{
|
||||||
assert_snapshot, create_test_login_user, read_body, test_put, DbTestContext, RequestConfig,
|
assert_snapshot, read_body, test_put, DbTestContext, RequestConfig, StatusCode,
|
||||||
StatusCode,
|
|
||||||
};
|
};
|
||||||
use brass_macros::db_test;
|
use brass_macros::db_test;
|
||||||
|
|
||||||
@ -85,8 +84,8 @@ mod tests {
|
|||||||
let app = context.app().await;
|
let app = context.app().await;
|
||||||
|
|
||||||
let unsubscribe_config = RequestConfig::new("/users/1/unsubscribeNotifications");
|
let unsubscribe_config = RequestConfig::new("/users/1/unsubscribeNotifications");
|
||||||
create_test_login_user(&context.db_pool, &unsubscribe_config).await;
|
let unsubscribe_response =
|
||||||
let unsubscribe_response = test_put::<_, _, String>(&app, &unsubscribe_config, None).await;
|
test_put::<_, _, String>(&context.db_pool, &app, &unsubscribe_config, None).await;
|
||||||
|
|
||||||
assert_eq!(StatusCode::OK, unsubscribe_response.status());
|
assert_eq!(StatusCode::OK, unsubscribe_response.status());
|
||||||
|
|
||||||
@ -94,7 +93,8 @@ mod tests {
|
|||||||
assert_snapshot!(unsubscribe_body);
|
assert_snapshot!(unsubscribe_body);
|
||||||
|
|
||||||
let subscribe_config = RequestConfig::new("/users/1/subscribeNotifications");
|
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());
|
assert_eq!(StatusCode::OK, subscribe_response.status());
|
||||||
|
|
||||||
@ -107,8 +107,8 @@ mod tests {
|
|||||||
let app = context.app().await;
|
let app = context.app().await;
|
||||||
|
|
||||||
let unsubscribe_config = RequestConfig::new("/users/3/unsubscribeNotifications");
|
let unsubscribe_config = RequestConfig::new("/users/3/unsubscribeNotifications");
|
||||||
create_test_login_user(&context.db_pool, &unsubscribe_config).await;
|
let unsubscribe_response =
|
||||||
let unsubscribe_response = test_put::<_, _, String>(&app, &unsubscribe_config, None).await;
|
test_put::<_, _, String>(&context.db_pool, &app, &unsubscribe_config, None).await;
|
||||||
|
|
||||||
assert_eq!(StatusCode::UNAUTHORIZED, unsubscribe_response.status());
|
assert_eq!(StatusCode::UNAUTHORIZED, unsubscribe_response.status());
|
||||||
}
|
}
|
||||||
|
@ -25,10 +25,8 @@ pub async fn delete(
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::utils::test_helper::{
|
use crate::utils::test_helper::{test_delete, DbTestContext, RequestConfig, StatusCode};
|
||||||
create_test_login_user, test_delete, DbTestContext, RequestConfig, StatusCode,
|
use brass_db::models::{Function, Role, Vehicle};
|
||||||
};
|
|
||||||
use brass_db::models::{Role, Vehicle};
|
|
||||||
use brass_macros::db_test;
|
use brass_macros::db_test;
|
||||||
|
|
||||||
#[db_test]
|
#[db_test]
|
||||||
@ -49,9 +47,13 @@ mod tests {
|
|||||||
assert!(Vehicle::read(&context.db_pool, 1).await.unwrap().is_some());
|
assert!(Vehicle::read(&context.db_pool, 1).await.unwrap().is_some());
|
||||||
|
|
||||||
let app = context.app().await;
|
let app = context.app().await;
|
||||||
let config = RequestConfig::new("/vehicles/1").with_role(role);
|
let config = RequestConfig {
|
||||||
create_test_login_user(&context.db_pool, &config).await;
|
uri: "/vehicles/1".to_string(),
|
||||||
let response = test_delete(app, &config).await;
|
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_eq!(StatusCode::OK, response.status());
|
||||||
assert!(Vehicle::read(&context.db_pool, 1).await.unwrap().is_none());
|
assert!(Vehicle::read(&context.db_pool, 1).await.unwrap().is_none());
|
||||||
@ -60,9 +62,7 @@ mod tests {
|
|||||||
#[db_test]
|
#[db_test]
|
||||||
async fn returns_unauthorized_when_user_is_staff(context: &DbTestContext) {
|
async fn returns_unauthorized_when_user_is_staff(context: &DbTestContext) {
|
||||||
let app = context.app().await;
|
let app = context.app().await;
|
||||||
let config = RequestConfig::new("/vehicles/1");
|
let response = test_delete(&context.db_pool, app, &RequestConfig::new("/vehicles/1")).await;
|
||||||
create_test_login_user(&context.db_pool, &config).await;
|
|
||||||
let response = test_delete(app, &config).await;
|
|
||||||
|
|
||||||
assert_eq!(StatusCode::UNAUTHORIZED, response.status());
|
assert_eq!(StatusCode::UNAUTHORIZED, response.status());
|
||||||
}
|
}
|
||||||
@ -70,9 +70,13 @@ mod tests {
|
|||||||
#[db_test]
|
#[db_test]
|
||||||
async fn returns_not_found_when_vehicle_does_not_exist(context: &DbTestContext) {
|
async fn returns_not_found_when_vehicle_does_not_exist(context: &DbTestContext) {
|
||||||
let app = context.app().await;
|
let app = context.app().await;
|
||||||
let config = RequestConfig::new("/vehicles/1").with_role(Role::Admin);
|
let config = RequestConfig {
|
||||||
create_test_login_user(&context.db_pool, &config).await;
|
uri: "/vehicles/1".to_string(),
|
||||||
let response = test_delete(app, &config).await;
|
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());
|
assert_eq!(StatusCode::NOT_FOUND, response.status());
|
||||||
}
|
}
|
||||||
|
@ -32,10 +32,9 @@ pub async fn get(
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::utils::test_helper::{
|
use crate::utils::test_helper::{
|
||||||
assert_snapshot, create_test_login_user, test_get, DbTestContext, RequestConfig,
|
assert_snapshot, read_body, test_get, DbTestContext, RequestConfig, StatusCode,
|
||||||
ServiceResponseExt, StatusCode,
|
|
||||||
};
|
};
|
||||||
use brass_db::models::{Role, Vehicle};
|
use brass_db::models::{Role, Function, Vehicle};
|
||||||
use brass_macros::db_test;
|
use brass_macros::db_test;
|
||||||
|
|
||||||
#[db_test]
|
#[db_test]
|
||||||
@ -47,9 +46,8 @@ mod tests {
|
|||||||
let app = context.app().await;
|
let app = context.app().await;
|
||||||
|
|
||||||
let config = RequestConfig::new("/vehicles/1");
|
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());
|
assert_eq!(StatusCode::UNAUTHORIZED, response.status());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,10 +59,14 @@ mod tests {
|
|||||||
|
|
||||||
let app = context.app().await;
|
let app = context.app().await;
|
||||||
|
|
||||||
let config = RequestConfig::new("/vehicles/1").with_role(Role::AreaManager);
|
let config = RequestConfig {
|
||||||
create_test_login_user(&context.db_pool, &config).await;
|
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());
|
assert_eq!(StatusCode::OK, response.status());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,11 +77,17 @@ mod tests {
|
|||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let config = RequestConfig::new("/vehicles/1").with_role(Role::Admin);
|
let config = RequestConfig {
|
||||||
create_test_login_user(&context.db_pool, &config).await;
|
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;
|
let response = test_get(&context.db_pool, &app, &config).await;
|
||||||
assert_eq!(StatusCode::OK, status);
|
assert_eq!(StatusCode::OK, response.status());
|
||||||
|
|
||||||
|
let body = read_body(response).await;
|
||||||
assert_snapshot!(body);
|
assert_snapshot!(body);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,10 +23,9 @@ pub async fn get(user: web::ReqData<User>) -> Result<impl Responder, Application
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::utils::test_helper::{
|
use crate::utils::test_helper::{
|
||||||
assert_snapshot, create_test_login_user, test_get, DbTestContext, RequestConfig,
|
assert_snapshot, read_body, test_get, DbTestContext, RequestConfig, StatusCode,
|
||||||
ServiceResponseExt, StatusCode,
|
|
||||||
};
|
};
|
||||||
use brass_db::models::Role;
|
use brass_db::models::{Function, Role};
|
||||||
use brass_macros::db_test;
|
use brass_macros::db_test;
|
||||||
|
|
||||||
#[db_test]
|
#[db_test]
|
||||||
@ -34,9 +33,8 @@ mod tests {
|
|||||||
let app = context.app().await;
|
let app = context.app().await;
|
||||||
|
|
||||||
let config = RequestConfig::new("/vehicles/new");
|
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());
|
assert_eq!(StatusCode::UNAUTHORIZED, response.status());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,10 +42,14 @@ mod tests {
|
|||||||
async fn area_manager_can_edit(context: &DbTestContext) {
|
async fn area_manager_can_edit(context: &DbTestContext) {
|
||||||
let app = context.app().await;
|
let app = context.app().await;
|
||||||
|
|
||||||
let config = RequestConfig::new("/vehicles/new").with_role(Role::AreaManager);
|
let config = RequestConfig {
|
||||||
create_test_login_user(&context.db_pool, &config).await;
|
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());
|
assert_eq!(StatusCode::OK, response.status());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,11 +57,17 @@ mod tests {
|
|||||||
async fn produces_template_fine_when_user_is_admin(context: &DbTestContext) {
|
async fn produces_template_fine_when_user_is_admin(context: &DbTestContext) {
|
||||||
let app = context.app().await;
|
let app = context.app().await;
|
||||||
|
|
||||||
let config = RequestConfig::new("/vehicles/new").with_role(Role::Admin);
|
let config = RequestConfig {
|
||||||
create_test_login_user(&context.db_pool, &config).await;
|
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;
|
let response = test_get(&context.db_pool, &app, &config).await;
|
||||||
assert_eq!(StatusCode::OK, status);
|
assert_eq!(StatusCode::OK, response.status());
|
||||||
|
|
||||||
|
let body = read_body(response).await;
|
||||||
assert_snapshot!(body);
|
assert_snapshot!(body);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,8 +39,7 @@ pub async fn get(
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::utils::test_helper::{
|
use crate::utils::test_helper::{
|
||||||
assert_snapshot, create_test_login_user, test_get, DbTestContext, RequestConfig,
|
assert_snapshot, read_body, test_get, DbTestContext, RequestConfig, StatusCode,
|
||||||
ServiceResponseExt, StatusCode,
|
|
||||||
};
|
};
|
||||||
use brass_db::models::{Role, Vehicle};
|
use brass_db::models::{Role, Vehicle};
|
||||||
use brass_macros::db_test;
|
use brass_macros::db_test;
|
||||||
@ -50,9 +49,8 @@ mod tests {
|
|||||||
let app = context.app().await;
|
let app = context.app().await;
|
||||||
|
|
||||||
let config = RequestConfig::new("/vehicles");
|
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());
|
assert_eq!(StatusCode::UNAUTHORIZED, response.status());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,9 +59,8 @@ mod tests {
|
|||||||
let app = context.app().await;
|
let app = context.app().await;
|
||||||
|
|
||||||
let config = RequestConfig::new("/vehicles").with_role(Role::AreaManager);
|
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());
|
assert_eq!(StatusCode::OK, response.status());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,10 +72,11 @@ mod tests {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let config = RequestConfig::new("/vehicles").with_role(Role::Admin);
|
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;
|
let response = test_get(&context.db_pool, &app, &config).await;
|
||||||
assert_eq!(StatusCode::OK, status);
|
assert_eq!(StatusCode::OK, response.status());
|
||||||
|
|
||||||
|
let body = read_body(response).await;
|
||||||
assert_snapshot!(body);
|
assert_snapshot!(body);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ mod tests {
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
endpoints::vehicle::VehicleForm,
|
endpoints::vehicle::VehicleForm,
|
||||||
utils::test_helper::{create_test_login_user, test_post, DbTestContext, RequestConfig},
|
utils::test_helper::{test_post, DbTestContext, RequestConfig},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[db_test]
|
#[db_test]
|
||||||
@ -67,14 +67,13 @@ mod tests {
|
|||||||
let app = context.app().await;
|
let app = context.app().await;
|
||||||
|
|
||||||
let config = RequestConfig::new("/vehicles/1").with_role(role);
|
let config = RequestConfig::new("/vehicles/1").with_role(role);
|
||||||
create_test_login_user(&context.db_pool, &config).await;
|
|
||||||
|
|
||||||
let request = VehicleForm {
|
let request = VehicleForm {
|
||||||
station: "FF Leipzig Ost".to_string(),
|
station: "FF Leipzig Ost".to_string(),
|
||||||
radio_call_name: "11.49.2".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());
|
assert_eq!(StatusCode::FOUND, response.status());
|
||||||
|
|
||||||
@ -88,14 +87,13 @@ mod tests {
|
|||||||
let app = context.app().await;
|
let app = context.app().await;
|
||||||
|
|
||||||
let config = RequestConfig::new("/vehicles/1");
|
let config = RequestConfig::new("/vehicles/1");
|
||||||
create_test_login_user(&context.db_pool, &config).await;
|
|
||||||
|
|
||||||
let request = VehicleForm {
|
let request = VehicleForm {
|
||||||
station: "FF Leipzig Ost".to_string(),
|
station: "FF Leipzig Ost".to_string(),
|
||||||
radio_call_name: "11.49.2".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());
|
assert_eq!(StatusCode::UNAUTHORIZED, response.status());
|
||||||
}
|
}
|
||||||
@ -105,14 +103,13 @@ mod tests {
|
|||||||
let app = context.app().await;
|
let app = context.app().await;
|
||||||
|
|
||||||
let config = RequestConfig::new("/vehicles/1").with_role(Role::Admin);
|
let config = RequestConfig::new("/vehicles/1").with_role(Role::Admin);
|
||||||
create_test_login_user(&context.db_pool, &config).await;
|
|
||||||
|
|
||||||
let request = VehicleForm {
|
let request = VehicleForm {
|
||||||
station: "FF Leipzig Ost".to_string(),
|
station: "FF Leipzig Ost".to_string(),
|
||||||
radio_call_name: "11.49.2".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());
|
assert_eq!(StatusCode::NOT_FOUND, response.status());
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ mod tests {
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
endpoints::vehicle::VehicleForm,
|
endpoints::vehicle::VehicleForm,
|
||||||
utils::test_helper::{create_test_login_user, test_post, DbTestContext, RequestConfig},
|
utils::test_helper::{test_post, DbTestContext, RequestConfig},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[db_test]
|
#[db_test]
|
||||||
@ -47,14 +47,13 @@ mod tests {
|
|||||||
let app = context.app().await;
|
let app = context.app().await;
|
||||||
|
|
||||||
let config = RequestConfig::new("/vehicles/new").with_role(role);
|
let config = RequestConfig::new("/vehicles/new").with_role(role);
|
||||||
create_test_login_user(&context.db_pool, &config).await;
|
|
||||||
|
|
||||||
let request = VehicleForm {
|
let request = VehicleForm {
|
||||||
station: "FF Leipzig Ost".to_string(),
|
station: "FF Leipzig Ost".to_string(),
|
||||||
radio_call_name: "11.49.1".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());
|
assert_eq!(StatusCode::FOUND, response.status());
|
||||||
|
|
||||||
@ -68,14 +67,13 @@ mod tests {
|
|||||||
let app = context.app().await;
|
let app = context.app().await;
|
||||||
|
|
||||||
let config = RequestConfig::new("/vehicles/new");
|
let config = RequestConfig::new("/vehicles/new");
|
||||||
create_test_login_user(&context.db_pool, &config).await;
|
|
||||||
|
|
||||||
let request = VehicleForm {
|
let request = VehicleForm {
|
||||||
station: "FF Leipzig Ost".to_string(),
|
station: "FF Leipzig Ost".to_string(),
|
||||||
radio_call_name: "11.49.2".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());
|
assert_eq!(StatusCode::UNAUTHORIZED, response.status());
|
||||||
}
|
}
|
||||||
|
@ -6,9 +6,7 @@ use actix_web::test;
|
|||||||
use chrono::{NaiveDate, NaiveDateTime};
|
use chrono::{NaiveDate, NaiveDateTime};
|
||||||
pub use test_context::{setup, teardown, DbTestContext};
|
pub use test_context::{setup, teardown, DbTestContext};
|
||||||
pub use test_requests::RequestConfig;
|
pub use test_requests::RequestConfig;
|
||||||
pub use test_requests::{
|
pub use test_requests::{read_body, test_delete, test_get, test_post, test_put};
|
||||||
create_test_login_user, read_body, test_delete, test_get, test_post, test_put,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub use actix_http::StatusCode;
|
pub use actix_http::StatusCode;
|
||||||
|
|
||||||
@ -62,10 +60,7 @@ pub trait ServiceResponseExt {
|
|||||||
async fn into_status_and_body(self) -> (StatusCode, String);
|
async fn into_status_and_body(self) -> (StatusCode, String);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<B> ServiceResponseExt for ServiceResponse<B>
|
impl<B> ServiceResponseExt for ServiceResponse<B> where B: MessageBody {
|
||||||
where
|
|
||||||
B: MessageBody,
|
|
||||||
{
|
|
||||||
async fn into_status_and_body(self) -> (StatusCode, String) {
|
async fn into_status_and_body(self) -> (StatusCode, String) {
|
||||||
let status = self.status();
|
let status = self.status();
|
||||||
let response = String::from_utf8(test::read_body(self).await.to_vec()).unwrap();
|
let response = String::from_utf8(test::read_body(self).await.to_vec()).unwrap();
|
||||||
|
@ -9,7 +9,7 @@ use actix_web::{
|
|||||||
};
|
};
|
||||||
use brass_db::models::{Function, Role, User};
|
use brass_db::models::{Function, Role, User};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use sqlx::PgPool;
|
use sqlx::{Pool, Postgres};
|
||||||
|
|
||||||
pub struct RequestConfig {
|
pub struct RequestConfig {
|
||||||
pub uri: String,
|
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 HASH: &str = "$argon2id$v=19$m=19456,t=2,p=1$IPiLaPCFZOK69MA1a6GUzw$ZZinpbkP7pXhN7g7dGkh87kGTeuFd/2er1U+y+4IKWo";
|
||||||
const SALT: &str = "IPiLaPCFZOK69MA1a6GUzw";
|
const SALT: &str = "IPiLaPCFZOK69MA1a6GUzw";
|
||||||
|
|
||||||
@ -64,13 +72,7 @@ pub async fn create_test_login_user(pool: &PgPool, config: &RequestConfig) {
|
|||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.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 {
|
let login_form = LoginForm {
|
||||||
email: "abc".to_string(),
|
email: "abc".to_string(),
|
||||||
password: "abc".to_string(),
|
password: "abc".to_string(),
|
||||||
@ -93,12 +95,16 @@ where
|
|||||||
String::from_utf8(test::read_body(response).await.to_vec()).unwrap()
|
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
|
where
|
||||||
T: Service<Request, Response = ServiceResponse<R>, Error = Error>,
|
T: Service<Request, Response = ServiceResponse<R>, Error = Error>,
|
||||||
R: MessageBody,
|
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()
|
let get_request = test::TestRequest::get()
|
||||||
.uri(&config.uri)
|
.uri(&config.uri)
|
||||||
@ -109,6 +115,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn test_post<T, R, F>(
|
pub async fn test_post<T, R, F>(
|
||||||
|
pool: &Pool<Postgres>,
|
||||||
app: T,
|
app: T,
|
||||||
config: &RequestConfig,
|
config: &RequestConfig,
|
||||||
form: Option<F>,
|
form: Option<F>,
|
||||||
@ -118,7 +125,7 @@ where
|
|||||||
R: MessageBody,
|
R: MessageBody,
|
||||||
F: Serialize,
|
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()
|
let post_request = test::TestRequest::post()
|
||||||
.uri(&config.uri)
|
.uri(&config.uri)
|
||||||
@ -130,6 +137,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn test_put<T, R, F>(
|
pub async fn test_put<T, R, F>(
|
||||||
|
pool: &Pool<Postgres>,
|
||||||
app: &T,
|
app: &T,
|
||||||
config: &RequestConfig,
|
config: &RequestConfig,
|
||||||
form: Option<F>,
|
form: Option<F>,
|
||||||
@ -139,7 +147,7 @@ where
|
|||||||
R: MessageBody,
|
R: MessageBody,
|
||||||
F: Serialize,
|
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()
|
let put_request = test::TestRequest::put()
|
||||||
.uri(&config.uri)
|
.uri(&config.uri)
|
||||||
@ -150,12 +158,16 @@ where
|
|||||||
test::call_service(app, put_request).await
|
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
|
where
|
||||||
T: Service<Request, Response = ServiceResponse<R>, Error = Error>,
|
T: Service<Request, Response = ServiceResponse<R>, Error = Error>,
|
||||||
R: MessageBody,
|
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()
|
let delete_request = test::TestRequest::delete()
|
||||||
.uri(&config.uri)
|
.uri(&config.uri)
|
||||||
|
@ -65,6 +65,22 @@ $crimson: #00d1b2; //#B80F0A;
|
|||||||
vertical-align: middle;
|
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] {
|
a.dropdown-item[disabled] {
|
||||||
color: hsl(221, 14%, 48%); // $grey;
|
color: hsl(221, 14%, 48%); // $grey;
|
||||||
cursor: default;
|
cursor: default;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user