From 87c2f20c0a9eb9fbf31013ad11b20e3fa5970d50 Mon Sep 17 00:00:00 2001 From: Rien Maertens Date: Sat, 19 Feb 2022 14:56:31 +0100 Subject: [PATCH] Add test for change_state --- tests/users.rs | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/tests/users.rs b/tests/users.rs index 4db9e49e..6b25e951 100644 --- a/tests/users.rs +++ b/tests/users.rs @@ -879,3 +879,52 @@ async fn validate_on_admin_create() { }) .await; } + +#[rocket::async_test] +async fn disable_user() { + common::as_admin(async move |http_client, db, _admin| { + let user = User::create( + NewUser { + username: String::from("somebody"), + password: String::from("once told me"), + full_name: String::from("zeus"), + email: String::from("would@be.forever"), + ssh_key: Some(String::from("ssh-rsa nananananananaaa")), + not_a_robot: true, + }, + common::BCRYPT_COST, + &db, + ) + .await + .unwrap(); + + assert_eq!( + user.state, + UserState::Active, + "user should be active before state change" + ); + + let response = http_client + .post(format!("/users/{}/change_state", user.username)) + .header(ContentType::Form) + .header(Accept::JSON) + .body("state=Disabled") + .dispatch() + .await; + + assert_eq!( + response.status(), + Status::NoContent, + "admin should be able to disable user" + ); + + let user = user.reload(&db).await.expect("reload user"); + + assert_eq!( + user.state, + UserState::Disabled, + "user should be disabled after state change" + ); + }) + .await; +}