Test for user system and comments
This commit is contained in:
@@ -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()
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user