test: get changepassword for profile
This commit is contained in:
parent
649d1a6ecf
commit
678690855a
@ -0,0 +1,43 @@
|
||||
---
|
||||
source: web/src/endpoints/user/get_changepassword.rs
|
||||
expression: body
|
||||
snapshot_kind: text
|
||||
---
|
||||
<div class="field">
|
||||
<div class="control">
|
||||
<a href="/profile" hx-boost="true" class="button is-link is-light">Schließen</a>
|
||||
</div>
|
||||
</div>
|
||||
<form class="box" hx-post="/users/changepassword" hx-target-422="#error-message"
|
||||
_="on change put '' into #error-message">
|
||||
|
||||
<div class="field">
|
||||
<label class="label" for="currentpassword">aktuelles Passwort:</label>
|
||||
<div class="control">
|
||||
<input class="input" placeholder="**********" name="currentpassword" type="password" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label class="label" for="password">neues Passwort:</label>
|
||||
<div class="control">
|
||||
<input class="input" hx-trigger="keyup changed delay:500ms" hx-target="#password-strength"
|
||||
hx-post="/users/changepassword" hx-target-422="#password-strength" placeholder="**********" name="password"
|
||||
type="password" required hx-swap="outerHTML" maxlength=256 _="on input put '' into #password-strength">
|
||||
</div>
|
||||
<div id="password-strength" class=" mb-3 help content"></div>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label class="label" for="passwordretyped">neues Passwort wiederholen:</label>
|
||||
<div class="control">
|
||||
<input class="input" placeholder="**********" name="passwordretyped" type="password" maxlength=256 required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="error-message" class="mb-3 help is-danger"></div>
|
||||
|
||||
<div class="level">
|
||||
<input class="button is-primary level-left" type="submit" value="Passwort ändern" />
|
||||
</div>
|
||||
</form>
|
@ -21,42 +21,27 @@ async fn get(user: web::ReqData<User>) -> Result<impl Responder, ApplicationErro
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::{
|
||||
utils::test_helper::{
|
||||
assert_snapshot, read_body, test_get, DbTestContext, RequestConfig, StatusCode,
|
||||
},
|
||||
use crate::utils::test_helper::{
|
||||
assert_snapshot, test_get, DbTestContext, RequestConfig, ServiceResponseExt, StatusCode,
|
||||
};
|
||||
use brass_db::models::{Function, Role};
|
||||
use brass_db::models::Role;
|
||||
use brass_macros::db_test;
|
||||
|
||||
#[db_test]
|
||||
async fn produces_template_when_user_is_admin(context: &DbTestContext) {
|
||||
let app = context.app().await;
|
||||
let config = RequestConfig {
|
||||
uri: "/area/new".to_string(),
|
||||
role: Role::Admin,
|
||||
function: vec![Function::Posten],
|
||||
user_area: 1,
|
||||
};
|
||||
let response = test_get(&context.db_pool, app, &config).await;
|
||||
let config = RequestConfig::new("/area/new").with_role(Role::Admin);
|
||||
|
||||
assert_eq!(StatusCode::OK, response.status());
|
||||
let response = test_get(&context.db_pool, context.app().await, &config).await;
|
||||
let (status, body) = response.into_status_and_body().await;
|
||||
|
||||
let body = read_body(response).await;
|
||||
assert_eq!(StatusCode::OK, status);
|
||||
assert_snapshot!(body);
|
||||
}
|
||||
|
||||
#[db_test]
|
||||
async fn returns_unauthorized_when_user_is_not_admin(context: &DbTestContext) {
|
||||
let app = context.app().await;
|
||||
|
||||
let config = RequestConfig {
|
||||
uri: "/area/new".to_string(),
|
||||
role: Role::AreaManager,
|
||||
function: vec![Function::Posten],
|
||||
user_area: 1,
|
||||
};
|
||||
let response = test_get(&context.db_pool, app, &config).await;
|
||||
let config = RequestConfig::new("/area/new").with_role(Role::AreaManager);
|
||||
let response = test_get(&context.db_pool, context.app().await, &config).await;
|
||||
|
||||
assert_eq!(StatusCode::UNAUTHORIZED, response.status());
|
||||
}
|
||||
|
@ -15,3 +15,24 @@ pub async fn get(_user: web::ReqData<User>) -> Result<impl Responder, Applicatio
|
||||
|
||||
Ok(template.to_response()?)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use actix_http::StatusCode;
|
||||
use brass_macros::db_test;
|
||||
|
||||
use crate::utils::test_helper::{
|
||||
assert_snapshot, test_get, DbTestContext, RequestConfig, ServiceResponseExt,
|
||||
};
|
||||
|
||||
#[db_test]
|
||||
async fn produces_template_fine(context: &DbTestContext) {
|
||||
let config = RequestConfig::new("/users/changepassword");
|
||||
|
||||
let response = test_get(&context.db_pool, context.app().await, &config).await;
|
||||
let (status, body) = response.into_status_and_body().await;
|
||||
|
||||
assert_eq!(StatusCode::OK, status);
|
||||
assert_snapshot!(body);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user