More tests, not found page and dashboard fixes
Some checks failed
Rust / Test (push) Has been cancelled
Rust / Rustfmt (push) Has been cancelled
Rust / Clippy (push) Has been cancelled
Rust / Code coverage (push) Has been cancelled

When post was deleted, website shows a 404 page insead of an 500 page.
Also made the dashboard empty page message more explicit.
This commit is contained in:
Alphonse Paix
2025-09-26 20:31:30 +02:00
parent 0f6b479af9
commit f9ae3f42a6
10 changed files with 233 additions and 48 deletions

View File

@@ -82,3 +82,86 @@ async fn confirmed_subscribers_are_notified_when_a_new_post_is_published(connect
app.dispatch_all_pending_emails().await;
}
#[sqlx::test]
async fn new_posts_are_visible_on_the_website(connection_pool: PgPool) {
let app = TestApp::spawn(connection_pool).await;
let html = app.get_posts_html().await;
assert!(html.contains("No posts yet"));
let title = subject();
let content = content();
let body = serde_json::json!({
"title": title,
"content": content,
"idempotency_key": Uuid::new_v4(),
});
app.admin_login().await;
app.post_create_post(&body).await;
app.logout().await;
let html = app.get_posts_html().await;
assert!(html.contains(&title));
let post = sqlx::query!("SELECT post_id FROM posts")
.fetch_one(&app.connection_pool)
.await
.unwrap();
let html = app.get_post_html(post.post_id).await;
assert!(html.contains(&title));
}
#[sqlx::test]
async fn visitor_can_read_a_blog_post(connection_pool: PgPool) {
let app = TestApp::spawn(connection_pool).await;
let title = subject();
let content = content();
let body = serde_json::json!({
"title": title,
"content": content,
"idempotency_key": Uuid::new_v4(),
});
app.admin_login().await;
app.post_create_post(&body).await;
app.logout().await;
let html = app.get_posts_html().await;
assert!(html.contains(&title));
let post = sqlx::query!("SELECT post_id FROM posts")
.fetch_one(&app.connection_pool)
.await
.unwrap();
let html = app.get_post_html(post.post_id).await;
assert!(html.contains(&title));
}
#[sqlx::test]
async fn a_deleted_blog_post_returns_404(connection_pool: PgPool) {
let app = TestApp::spawn(connection_pool).await;
app.admin_login().await;
let title = subject();
let content = content();
let body = serde_json::json!({
"title": title,
"content": content,
"idempotency_key": Uuid::new_v4(),
});
app.post_create_post(&body).await;
let post = sqlx::query!("SELECT post_id FROM posts")
.fetch_one(&app.connection_pool)
.await
.unwrap();
app.delete_post(post.post_id).await;
let html = app.get_post_html(post.post_id).await;
assert!(html.contains("Not Found"));
}