Refactor test suite to handle 303 See Other

This commit is contained in:
Alphonse Paix
2025-09-18 20:42:50 +02:00
parent c545fe0c01
commit 97e771b120
4 changed files with 11 additions and 9 deletions

View File

@@ -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<Response, AdminError> {
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())
}

View File

@@ -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};

View File

@@ -152,7 +152,7 @@
stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5.882V19.24a1.76 1.76 0 01-3.417.592l-2.147-6.15M18 13a3 3 0 100-6M5.436 13.683A4.001 4.001 0 017 6h1.832c4.1 0 7.625-1.234 9.168-3v14c-1.543-1.766-5.067-3-9.168-3H7a3.988 3.988 0 01-1.564-.317z" />
</svg>
Contact your subscribers
Send an email
</h2>
<p class="text-sm text-gray-600 mt-1">Contact your subscribers directly.</p>
</div>
@@ -215,7 +215,7 @@
stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z" />
</svg>
Password
Change your password
</h2>
<p class="text-sm text-gray-600 mt-1">Set a new password for your account.</p>
</div>

View File

@@ -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 {