Files
zero2prod/tests/api/admin_dashboard.rs
Alphonse Paix 33281132c6
Some checks failed
Rust / Test (push) Has been cancelled
Rust / Rustfmt (push) Has been cancelled
Rust / Clippy (push) Has been cancelled
Rust / Code coverage (push) Has been cancelled
Update test suite to drop database automatically when test is successfull
2025-09-24 02:55:18 +02:00

34 lines
1.1 KiB
Rust

use crate::helpers::{TestApp, assert_is_redirect_to};
use sqlx::PgPool;
#[sqlx::test]
async fn you_must_be_logged_in_to_access_the_admin_dashboard(connection_pool: PgPool) {
let app = TestApp::spawn(connection_pool).await;
let response = app.get_admin_dashboard().await;
assert_is_redirect_to(&response, "/login");
}
#[sqlx::test]
async fn logout_clears_session_state(connection_pool: PgPool) {
let app = TestApp::spawn(connection_pool).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("Connected as"));
assert!(html_page.contains(&app.test_user.username));
let response = app.post_logout().await;
assert_is_redirect_to(&response, "/login");
let response = app.get_admin_dashboard().await;
assert_is_redirect_to(&response, "/login");
}