Admin dashboard and sessions
This commit is contained in:
34
tests/api/admin_dashboard.rs
Normal file
34
tests/api/admin_dashboard.rs
Normal file
@@ -0,0 +1,34 @@
|
||||
use crate::helpers::{TestApp, assert_is_redirect_to};
|
||||
|
||||
#[tokio::test]
|
||||
async fn you_must_be_logged_in_to_access_the_admin_dashboard() {
|
||||
let app = TestApp::spawn().await;
|
||||
|
||||
let response = app.get_admin_dashboard().await;
|
||||
|
||||
assert_is_redirect_to(&response, "/login");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn logout_clears_session_state() {
|
||||
let app = TestApp::spawn().await;
|
||||
|
||||
let login_body = serde_json::json!({
|
||||
"username": &app.test_user.username,
|
||||
"password": &app.test_user.password,
|
||||
});
|
||||
let response = app.post_login(&login_body).await;
|
||||
assert_is_redirect_to(&response, "/admin/dashboard");
|
||||
|
||||
let html_page = app.get_admin_dashboard_html().await;
|
||||
assert!(html_page.contains(&format!("Welcome {}", app.test_user.username)));
|
||||
|
||||
let response = app.post_logout().await;
|
||||
assert_is_redirect_to(&response, "/login");
|
||||
|
||||
let html_page = app.get_login_html().await;
|
||||
assert!(html_page.contains("You have successfully logged out"));
|
||||
|
||||
let response = app.get_admin_dashboard().await;
|
||||
assert_is_redirect_to(&response, "/login");
|
||||
}
|
||||
Reference in New Issue
Block a user