Skip to content

Commit

Permalink
Add test for change_state
Browse files Browse the repository at this point in the history
  • Loading branch information
rien committed Feb 19, 2022
1 parent 4f015f8 commit 87c2f20
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions tests/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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("[email protected]"),
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;
}

0 comments on commit 87c2f20

Please sign in to comment.