Skip to content

Commit

Permalink
chore: refactored code for formatting CI
Browse files Browse the repository at this point in the history
  • Loading branch information
Utilitycoder committed Jul 19, 2023
1 parent a84d066 commit b844644
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/routes/admin/newsletters/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -23,12 +23,12 @@ name = "Publish a newsletter issue",
fields(user_id = %*user_id)
)]
pub async fn publish_newsletter(
form: web::Form<FormData>,
form: web::Form<NewsletterContent>,
pool: web::Data<PgPool>,
user_id: ReqData<UserId>,
) -> Result<HttpResponse, actix_web::Error> {
let user_id = user_id.into_inner();
let FormData {
let NewsletterContent {
title,
text_content,
html_content,
Expand Down
16 changes: 6 additions & 10 deletions tests/api/newsletter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<String>();
Expand Down Expand Up @@ -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
Expand All @@ -70,7 +66,7 @@ async fn you_must_be_logged_in_to_publish_a_newsletter() {
"title": "Newsletter title",
"text_content": "Newsletter content",
"html_content": "<p>Newsletter content</p>",
"idempotency_key": uuid::Uuid::new_v4().to_string()
"idempotency_key": Uuid::new_v4().to_string()
}
);

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

Expand Down Expand Up @@ -130,7 +126,7 @@ async fn newsletters_are_delivered_to_confirmed_subscribers() {
"title": "Newsletter title",
"text_content": "Newsletter body as plain text",
"html_content": "<p>Newsletter body as HTML</p>",
"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;
Expand Down Expand Up @@ -167,7 +163,7 @@ async fn newsletter_creation_is_idempotent() {
"html_content": "<p>Newsletter body as HTML</p>",
// 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;
Expand Down Expand Up @@ -208,7 +204,7 @@ async fn concurrent_form_submission_is_handled_gracefully() {
"title": "Newsletter title",
"text_content": "Newsletter body as plain text",
"html_content": "<p>Newsletter body as HTML</p>",
"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);
Expand Down

0 comments on commit b844644

Please sign in to comment.