mirror of
https://github.com/LukeMathWalker/zero-to-production.git
synced 2025-01-19 05:25:37 +00:00
cargo fmt.
This commit is contained in:
parent
50798e8e67
commit
b7ed1b4c28
4 changed files with 15 additions and 14 deletions
|
@ -5,7 +5,7 @@ use actix_web::{web, HttpResponse};
|
||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
use rand::distributions::Alphanumeric;
|
use rand::distributions::Alphanumeric;
|
||||||
use rand::{thread_rng, Rng};
|
use rand::{thread_rng, Rng};
|
||||||
use sqlx::{PgPool, Transaction, Postgres};
|
use sqlx::{PgPool, Postgres, Transaction};
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
@ -43,7 +43,10 @@ pub async fn subscribe(
|
||||||
.0
|
.0
|
||||||
.try_into()
|
.try_into()
|
||||||
.map_err(|_| HttpResponse::BadRequest().finish())?;
|
.map_err(|_| HttpResponse::BadRequest().finish())?;
|
||||||
let mut transaction = pool.begin().await.map_err(|_| HttpResponse::InternalServerError().finish())?;
|
let mut transaction = pool
|
||||||
|
.begin()
|
||||||
|
.await
|
||||||
|
.map_err(|_| HttpResponse::InternalServerError().finish())?;
|
||||||
let subscriber_id = insert_subscriber(&mut transaction, &new_subscriber)
|
let subscriber_id = insert_subscriber(&mut transaction, &new_subscriber)
|
||||||
.await
|
.await
|
||||||
.map_err(|_| HttpResponse::InternalServerError().finish())?;
|
.map_err(|_| HttpResponse::InternalServerError().finish())?;
|
||||||
|
@ -52,7 +55,10 @@ pub async fn subscribe(
|
||||||
store_token(&mut transaction, subscriber_id, &subscription_token)
|
store_token(&mut transaction, subscriber_id, &subscription_token)
|
||||||
.await
|
.await
|
||||||
.map_err(|_| HttpResponse::InternalServerError().finish())?;
|
.map_err(|_| HttpResponse::InternalServerError().finish())?;
|
||||||
transaction.commit().await.map_err(|_| HttpResponse::InternalServerError().finish())?;
|
transaction
|
||||||
|
.commit()
|
||||||
|
.await
|
||||||
|
.map_err(|_| HttpResponse::InternalServerError().finish())?;
|
||||||
let _ = send_confirmation_email(
|
let _ = send_confirmation_email(
|
||||||
&email_client,
|
&email_client,
|
||||||
new_subscriber,
|
new_subscriber,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::configuration::{DatabaseSettings, Settings};
|
use crate::configuration::{DatabaseSettings, Settings};
|
||||||
use crate::email_client::EmailClient;
|
use crate::email_client::EmailClient;
|
||||||
use crate::routes::{health_check, subscribe, confirm};
|
use crate::routes::{confirm, health_check, subscribe};
|
||||||
use actix_web::dev::Server;
|
use actix_web::dev::Server;
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use actix_web::{web, App, HttpServer};
|
use actix_web::{web, App, HttpServer};
|
||||||
|
|
|
@ -24,7 +24,7 @@ pub struct TestApp {
|
||||||
/// Confirmation links embedded in the request to the email API.
|
/// Confirmation links embedded in the request to the email API.
|
||||||
pub struct ConfirmationLinks {
|
pub struct ConfirmationLinks {
|
||||||
pub html: reqwest::Url,
|
pub html: reqwest::Url,
|
||||||
pub plain_text: reqwest::Url
|
pub plain_text: reqwest::Url,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TestApp {
|
impl TestApp {
|
||||||
|
@ -59,10 +59,7 @@ impl TestApp {
|
||||||
|
|
||||||
let html = get_link(&body["HtmlBody"].as_str().unwrap());
|
let html = get_link(&body["HtmlBody"].as_str().unwrap());
|
||||||
let plain_text = get_link(&body["TextBody"].as_str().unwrap());
|
let plain_text = get_link(&body["TextBody"].as_str().unwrap());
|
||||||
ConfirmationLinks {
|
ConfirmationLinks { html, plain_text }
|
||||||
html,
|
|
||||||
plain_text
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::helpers::spawn_app;
|
use crate::helpers::spawn_app;
|
||||||
use wiremock::{ResponseTemplate, Mock};
|
use wiremock::matchers::{method, path};
|
||||||
use wiremock::matchers::{path, method};
|
use wiremock::{Mock, ResponseTemplate};
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn confirmations_without_token_are_rejected_with_a_400() {
|
async fn confirmations_without_token_are_rejected_with_a_400() {
|
||||||
|
@ -33,9 +33,7 @@ async fn the_link_returned_by_subscribe_returns_a_200_if_called() {
|
||||||
let confirmation_links = app.get_confirmation_links(&email_request);
|
let confirmation_links = app.get_confirmation_links(&email_request);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
let response = reqwest::get(confirmation_links.html)
|
let response = reqwest::get(confirmation_links.html).await.unwrap();
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
assert_eq!(response.status().as_u16(), 200);
|
assert_eq!(response.status().as_u16(), 200);
|
||||||
|
|
Loading…
Reference in a new issue