test: add tests to bot routes

This commit is contained in:
Paul Makles
2023-08-27 15:01:22 +01:00
parent 0542788567
commit 7568f49755
13 changed files with 473 additions and 38 deletions

View File

@@ -20,3 +20,45 @@ pub async fn delete_bot(
bot.delete(db).await.map(|_| EmptyResponse)
}
#[cfg(test)]
mod test {
use crate::{rocket, util::test::TestHarness};
use revolt_database::{events::client::EventV1, Bot};
use rocket::http::{Header, Status};
#[rocket::async_test]
async fn delete_bot() {
let mut harness = TestHarness::new().await;
let (_, session, user) = harness.new_user().await;
let bot = Bot::create(&harness.db, TestHarness::rand_string(), &user, None)
.await
.expect("`Bot`");
let response = harness
.client
.delete(format!("/bots/{}", bot.id))
.header(Header::new("x-session-token", session.token.to_string()))
.dispatch()
.await;
assert_eq!(response.status(), Status::NoContent);
assert!(harness.db.fetch_bot(&bot.id).await.is_err());
drop(response);
let event = harness
.wait_for_event(|event| match event {
EventV1::UserUpdate { id, .. } => id == &bot.id,
_ => false,
})
.await;
match event {
EventV1::UserUpdate { data, .. } => {
assert_eq!(data.flags, Some(2));
}
_ => unreachable!(),
}
}
}