From 6b043620b89c07023b6098649bf351c508675a73 Mon Sep 17 00:00:00 2001 From: Greg Burri Date: Fri, 2 May 2025 16:55:40 +0200 Subject: [PATCH] Add an integration test for sign in --- backend/tests/http.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/backend/tests/http.rs b/backend/tests/http.rs index 2b3e56a..43087b3 100644 --- a/backend/tests/http.rs +++ b/backend/tests/http.rs @@ -137,3 +137,39 @@ async fn sign_up() -> Result<(), Box> { Ok(()) } + +#[derive(Serialize, Debug)] +pub struct SignInFormData { + email: String, + password: String, +} + +#[tokio::test] +async fn sign_in() -> Result<(), Box> { + // Arrange. + let state = utils::common_state().await?; + let _user_id = utils::create_user( + &state.db_connection, + "president@spaceball.planet", + "12345678", + ) + .await?; + let server = TestServer::new(app::make_service(state))?; + + // Act. + let response = server + .post("/signin") + .form(&SignInFormData { + email: "president@spaceball.planet".into(), + password: "12345678".into(), + }) + .await; + + // Assert. + response.assert_status_see_other(); // Redirection after successful sign in. + response.assert_text(""); + response.assert_header("location", "/en/"); // English is the default language. + dbg!(&response); + + Ok(()) +}