Test for user system and comments

This commit is contained in:
Alphonse Paix
2025-10-06 02:08:26 +02:00
parent d96a29ee73
commit 04c2d2b7f5
12 changed files with 501 additions and 29 deletions

View File

@@ -130,6 +130,26 @@ impl TestApp {
app
}
pub async fn create_user(
&self,
username: &str,
password: &str,
admin: bool,
) -> reqwest::Response {
let body = serde_json::json!({
"username": username,
"password": password,
"password_check": password,
"admin": admin,
});
self.api_client
.post(format!("{}/admin/users", self.address))
.form(&body)
.send()
.await
.unwrap()
}
pub async fn create_unconfirmed_subscriber(&self) -> ConfirmationLinks {
let email: String = SafeEmail().fake();
let body = format!("email={email}");
@@ -166,7 +186,7 @@ impl TestApp {
.unwrap();
}
pub async fn delete_subscriber(&self, subscriber_id: Uuid) {
pub async fn delete_subscriber(&self, subscriber_id: Uuid) -> reqwest::Response {
self.api_client
.delete(format!(
"{}/admin/subscribers/{}",
@@ -174,7 +194,15 @@ impl TestApp {
))
.send()
.await
.expect("Could not delete subscriber");
.expect("Could not delete subscriber")
}
pub async fn delete_user(&self, user_id: Uuid) -> reqwest::Response {
self.api_client
.delete(format!("{}/admin/users/{}", self.address, user_id))
.send()
.await
.expect("Could not delete user")
}
pub async fn dispatch_all_pending_emails(&self) {
@@ -371,12 +399,20 @@ impl TestApp {
.expect("Failed to execute request")
}
pub async fn delete_post(&self, post_id: Uuid) {
pub async fn delete_post(&self, post_id: Uuid) -> reqwest::Response {
self.api_client
.delete(format!("{}/admin/posts/{}", self.address, post_id))
.send()
.await
.expect("Could not delete post");
.expect("Could not delete post")
}
pub async fn delete_comment(&self, comment_id: Uuid) -> reqwest::Response {
self.api_client
.delete(format!("{}/admin/comments/{}", self.address, comment_id))
.send()
.await
.expect("Could not delete comment")
}
pub async fn post_unsubscribe<Body>(&self, body: &Body) -> reqwest::Response
@@ -418,8 +454,7 @@ pub fn fake_post_body() -> serde_json::Value {
serde_json::json!({
"title": "Post title",
"content": "Post content",
"idempotency_key": Uuid::new_v4().to_string(),
"idempotency_key": Uuid::new_v4().to_string()
})
}