From b8446443e6bf47c710c479a748e4b729176cf3ad Mon Sep 17 00:00:00 2001 From: Lawal Abubakar Babatunde Date: Wed, 19 Jul 2023 09:36:14 +0100 Subject: [PATCH] chore: refactored code for formatting CI --- src/routes/admin/newsletters/post.rs | 6 +++--- tests/api/newsletter.rs | 16 ++++++---------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/routes/admin/newsletters/post.rs b/src/routes/admin/newsletters/post.rs index 834a918..d2f1587 100644 --- a/src/routes/admin/newsletters/post.rs +++ b/src/routes/admin/newsletters/post.rs @@ -10,7 +10,7 @@ use sqlx::{PgPool, Postgres, Transaction}; use uuid::Uuid; #[derive(serde::Deserialize)] -pub struct FormData { +pub struct NewsletterContent { title: String, text_content: String, html_content: String, @@ -23,12 +23,12 @@ name = "Publish a newsletter issue", fields(user_id = %*user_id) )] pub async fn publish_newsletter( - form: web::Form, + form: web::Form, pool: web::Data, user_id: ReqData, ) -> Result { let user_id = user_id.into_inner(); - let FormData { + let NewsletterContent { title, text_content, html_content, diff --git a/tests/api/newsletter.rs b/tests/api/newsletter.rs index 8571615..a10b2e6 100644 --- a/tests/api/newsletter.rs +++ b/tests/api/newsletter.rs @@ -5,7 +5,7 @@ use fake::Fake; use std::time::Duration; use uuid::Uuid; use wiremock::matchers::{any, method, path}; -use wiremock::{Mock, MockBuilder, ResponseTemplate}; +use wiremock::{Mock, ResponseTemplate}; async fn create_unconfirmed_subscriber(app: &TestApp) -> ConfirmationLinks { let name = Name().fake::(); @@ -46,10 +46,6 @@ async fn create_confirmed_subscriber(app: &TestApp) { .unwrap(); } -fn when_sending_an_email() -> MockBuilder { - Mock::given(path("/email")).and(method("POST")) -} - #[tokio::test] async fn you_must_be_logged_in_to_see_the_newsletter_form() { // Arrange @@ -70,7 +66,7 @@ async fn you_must_be_logged_in_to_publish_a_newsletter() { "title": "Newsletter title", "text_content": "Newsletter content", "html_content": "

Newsletter content

", - "idempotency_key": uuid::Uuid::new_v4().to_string() + "idempotency_key": Uuid::new_v4().to_string() } ); @@ -97,7 +93,7 @@ async fn newsletters_are_not_delivered_to_unconfirmed_subscribers() { "title": "Newsletter title", "text_content": "Newsletter content", "html_content": "

Newsletter content

", - "idempotency_key": uuid::Uuid::new_v4().to_string() + "idempotency_key": Uuid::new_v4().to_string() } ); @@ -130,7 +126,7 @@ async fn newsletters_are_delivered_to_confirmed_subscribers() { "title": "Newsletter title", "text_content": "Newsletter body as plain text", "html_content": "

Newsletter body as HTML

", - "idempotency_key": uuid::Uuid::new_v4().to_string() + "idempotency_key": Uuid::new_v4().to_string() }); let response = app.post_publish_newsletters(&newsletter_request_body).await; @@ -167,7 +163,7 @@ async fn newsletter_creation_is_idempotent() { "html_content": "

Newsletter body as HTML

", // We expect the idempotency key as part of the // form data, not as an header - "idempotency_key": uuid::Uuid::new_v4().to_string() + "idempotency_key": Uuid::new_v4().to_string() }); let response = app.post_publish_newsletters(&newsletter_request_body).await; @@ -208,7 +204,7 @@ async fn concurrent_form_submission_is_handled_gracefully() { "title": "Newsletter title", "text_content": "Newsletter body as plain text", "html_content": "

Newsletter body as HTML

", - "idempotency_key": uuid::Uuid::new_v4().to_string() + "idempotency_key": Uuid::new_v4().to_string() }); let response_1 = app.post_publish_newsletters(&newsletter_request_body);