Add an integration test for sign in

This commit is contained in:
Greg Burri 2025-05-02 16:55:40 +02:00
parent 8c70f90234
commit 6b043620b8

View file

@ -137,3 +137,39 @@ async fn sign_up() -> Result<(), Box<dyn Error>> {
Ok(())
}
#[derive(Serialize, Debug)]
pub struct SignInFormData {
email: String,
password: String,
}
#[tokio::test]
async fn sign_in() -> Result<(), Box<dyn Error>> {
// 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(())
}