From 97e771b120114ae83d62e805af0da092dc0629e2 Mon Sep 17 00:00:00 2001 From: Alphonse Paix Date: Thu, 18 Sep 2025 20:42:50 +0200 Subject: [PATCH] Refactor test suite to handle 303 See Other --- src/routes/admin/logout.rs | 8 +++----- src/routes/login.rs | 1 + templates/dashboard.html | 4 ++-- tests/api/helpers.rs | 7 +++++-- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/routes/admin/logout.rs b/src/routes/admin/logout.rs index cd605d7..2f02292 100644 --- a/src/routes/admin/logout.rs +++ b/src/routes/admin/logout.rs @@ -1,15 +1,13 @@ use crate::{routes::AdminError, session_state::TypedSession}; use axum::{ - http::HeaderMap, + http::{HeaderMap, StatusCode}, response::{IntoResponse, Response}, }; -use reqwest::StatusCode; #[tracing::instrument(name = "Logging out", skip(session))] pub async fn logout(session: TypedSession) -> Result { session.clear().await; let mut headers = HeaderMap::new(); headers.insert("HX-Redirect", "/login".parse().unwrap()); - headers.insert("Location", "/login".parse().unwrap()); - Ok((StatusCode::SEE_OTHER, headers).into_response()) -} + Ok((StatusCode::OK, headers).into_response()) +} \ No newline at end of file diff --git a/src/routes/login.rs b/src/routes/login.rs index ad6a75f..7e7434e 100644 --- a/src/routes/login.rs +++ b/src/routes/login.rs @@ -9,6 +9,7 @@ use askama::Template; use axum::{ Form, Json, extract::State, + http::HeaderMap, response::{Html, IntoResponse, Response}, }; use axum::{http::StatusCode, response::Redirect}; diff --git a/templates/dashboard.html b/templates/dashboard.html index 793fada..75424f2 100644 --- a/templates/dashboard.html +++ b/templates/dashboard.html @@ -152,7 +152,7 @@ stroke="currentColor"> - Contact your subscribers + Send an email

Contact your subscribers directly.

@@ -215,7 +215,7 @@ stroke="currentColor"> - Password + Change your password

Set a new password for your account.

diff --git a/tests/api/helpers.rs b/tests/api/helpers.rs index e43a62d..c087b6f 100644 --- a/tests/api/helpers.rs +++ b/tests/api/helpers.rs @@ -297,8 +297,11 @@ async fn configure_database(config: &DatabaseSettings) -> PgPool { } pub fn assert_is_redirect_to(response: &reqwest::Response, location: &str) { - assert_eq!(response.status().as_u16(), 303); - assert_eq!(response.headers().get("location").unwrap(), location); + assert!( + response.status().as_u16() == 303 + || response.status().as_u16() == 200 + && response.headers().get("hx-redirect").unwrap() == location + ); } pub fn when_sending_an_email() -> MockBuilder {