Update test suite to drop database automatically when test is successfull
This commit is contained in:
@@ -3,6 +3,7 @@ use fake::{
|
||||
Fake,
|
||||
faker::lorem::en::{Paragraph, Sentence},
|
||||
};
|
||||
use sqlx::PgPool;
|
||||
use uuid::Uuid;
|
||||
use wiremock::ResponseTemplate;
|
||||
|
||||
@@ -14,9 +15,9 @@ fn content() -> String {
|
||||
Paragraph(1..10).fake()
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn you_must_be_logged_in_to_create_a_new_post() {
|
||||
let app = TestApp::spawn().await;
|
||||
#[sqlx::test]
|
||||
async fn you_must_be_logged_in_to_create_a_new_post(connection_pool: PgPool) {
|
||||
let app = TestApp::spawn(connection_pool).await;
|
||||
|
||||
let title = subject();
|
||||
let content = content();
|
||||
@@ -29,9 +30,9 @@ async fn you_must_be_logged_in_to_create_a_new_post() {
|
||||
assert_is_redirect_to(&response, "/login");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn new_posts_are_stored_in_the_database() {
|
||||
let app = TestApp::spawn().await;
|
||||
#[sqlx::test]
|
||||
async fn new_posts_are_stored_in_the_database(connection_pool: PgPool) {
|
||||
let app = TestApp::spawn(connection_pool).await;
|
||||
app.admin_login().await;
|
||||
|
||||
let title = subject();
|
||||
@@ -45,7 +46,7 @@ async fn new_posts_are_stored_in_the_database() {
|
||||
|
||||
assert!(response.status().is_success());
|
||||
let html_fragment = response.text().await.unwrap();
|
||||
assert!(html_fragment.contains("Your new post has been saved"));
|
||||
assert!(html_fragment.contains("Your new post has been published"));
|
||||
|
||||
let saved = sqlx::query!("SELECT title, content FROM posts")
|
||||
.fetch_one(&app.connection_pool)
|
||||
@@ -56,9 +57,9 @@ async fn new_posts_are_stored_in_the_database() {
|
||||
assert_eq!(saved.content, content);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn confirmed_subscribers_are_notified_when_a_new_post_is_published() {
|
||||
let app = TestApp::spawn().await;
|
||||
#[sqlx::test]
|
||||
async fn confirmed_subscribers_are_notified_when_a_new_post_is_published(connection_pool: PgPool) {
|
||||
let app = TestApp::spawn(connection_pool).await;
|
||||
app.create_unconfirmed_subscriber().await;
|
||||
app.create_confirmed_subscriber().await;
|
||||
app.admin_login().await;
|
||||
|
||||
Reference in New Issue
Block a user