Update test suite to drop database automatically when test is successfull
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
use crate::helpers::{TestApp, assert_is_redirect_to, when_sending_an_email};
|
||||
use sqlx::PgPool;
|
||||
use std::time::Duration;
|
||||
use uuid::Uuid;
|
||||
use wiremock::ResponseTemplate;
|
||||
|
||||
#[tokio::test]
|
||||
async fn newsletters_are_not_delivered_to_unconfirmed_subscribers() {
|
||||
let app = TestApp::spawn().await;
|
||||
#[sqlx::test]
|
||||
async fn newsletters_are_not_delivered_to_unconfirmed_subscribers(connection_pool: PgPool) {
|
||||
let app = TestApp::spawn(connection_pool).await;
|
||||
app.create_unconfirmed_subscriber().await;
|
||||
app.admin_login().await;
|
||||
|
||||
@@ -25,9 +26,9 @@ async fn newsletters_are_not_delivered_to_unconfirmed_subscribers() {
|
||||
app.dispatch_all_pending_emails().await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn requests_without_authentication_are_redirected() {
|
||||
let app = TestApp::spawn().await;
|
||||
#[sqlx::test]
|
||||
async fn requests_without_authentication_are_redirected(connection_pool: PgPool) {
|
||||
let app = TestApp::spawn(connection_pool).await;
|
||||
|
||||
when_sending_an_email()
|
||||
.respond_with(ResponseTemplate::new(200))
|
||||
@@ -44,9 +45,9 @@ async fn requests_without_authentication_are_redirected() {
|
||||
assert_is_redirect_to(&response, "/login");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn newsletters_are_delivered_to_confirmed_subscribers() {
|
||||
let app = TestApp::spawn().await;
|
||||
#[sqlx::test]
|
||||
async fn newsletters_are_delivered_to_confirmed_subscribers(connection_pool: PgPool) {
|
||||
let app = TestApp::spawn(connection_pool).await;
|
||||
app.create_confirmed_subscriber().await;
|
||||
app.admin_login().await;
|
||||
|
||||
@@ -68,17 +69,14 @@ async fn newsletters_are_delivered_to_confirmed_subscribers() {
|
||||
assert!(response.status().is_success());
|
||||
|
||||
let html_fragment = response.text().await.unwrap();
|
||||
assert!(html_fragment.contains(&format!(
|
||||
r#"The newsletter issue "{}" has been published"#,
|
||||
newsletter_title
|
||||
)));
|
||||
assert!(html_fragment.contains("Your email has been queued for delivery"));
|
||||
|
||||
app.dispatch_all_pending_emails().await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn form_shows_error_for_invalid_data() {
|
||||
let app = TestApp::spawn().await;
|
||||
#[sqlx::test]
|
||||
async fn form_shows_error_for_invalid_data(connection_pool: PgPool) {
|
||||
let app = TestApp::spawn(connection_pool).await;
|
||||
app.admin_login().await;
|
||||
|
||||
when_sending_an_email()
|
||||
@@ -119,9 +117,9 @@ async fn form_shows_error_for_invalid_data() {
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn newsletter_creation_is_idempotent() {
|
||||
let app = TestApp::spawn().await;
|
||||
#[sqlx::test]
|
||||
async fn newsletter_creation_is_idempotent(connection_pool: PgPool) {
|
||||
let app = TestApp::spawn(connection_pool).await;
|
||||
app.create_confirmed_subscriber().await;
|
||||
app.admin_login().await;
|
||||
|
||||
@@ -143,26 +141,20 @@ async fn newsletter_creation_is_idempotent() {
|
||||
assert!(response.status().is_success());
|
||||
|
||||
let html_fragment = response.text().await.unwrap();
|
||||
assert!(html_fragment.contains(&format!(
|
||||
r#"The newsletter issue "{}" has been published"#,
|
||||
newsletter_title
|
||||
)));
|
||||
assert!(html_fragment.contains("Your email has been queued for delivery"));
|
||||
|
||||
let response = app.post_newsletters(&newsletter_request_body).await;
|
||||
assert!(response.status().is_success());
|
||||
|
||||
let html_fragment = response.text().await.unwrap();
|
||||
assert!(html_fragment.contains(&format!(
|
||||
r#"The newsletter issue "{}" has been published"#,
|
||||
newsletter_title
|
||||
)));
|
||||
assert!(html_fragment.contains("Your email has been queued for delivery"));
|
||||
|
||||
app.dispatch_all_pending_emails().await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn concurrent_form_submission_is_handled_gracefully() {
|
||||
let app = TestApp::spawn().await;
|
||||
#[sqlx::test]
|
||||
async fn concurrent_form_submission_is_handled_gracefully(connection_pool: PgPool) {
|
||||
let app = TestApp::spawn(connection_pool).await;
|
||||
app.create_confirmed_subscriber().await;
|
||||
app.admin_login().await;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user