Test for user system and comments
This commit is contained in:
@@ -40,7 +40,7 @@ async fn subscribers_are_visible_on_the_dashboard(connection_pool: PgPool) {
|
||||
app.admin_login().await;
|
||||
|
||||
let response = app.get_admin_dashboard_html().await;
|
||||
assert!(response.contains("No data available"));
|
||||
assert!(response.contains("No subscribers to display"));
|
||||
|
||||
app.create_confirmed_subscriber().await;
|
||||
let subscriber = sqlx::query!("SELECT id, email FROM subscriptions")
|
||||
@@ -53,10 +53,90 @@ async fn subscribers_are_visible_on_the_dashboard(connection_pool: PgPool) {
|
||||
|
||||
app.delete_subscriber(subscriber.id).await;
|
||||
let response = app.get_admin_dashboard_html().await;
|
||||
assert!(response.contains("No data available"));
|
||||
assert!(response.contains("No subscribers to display"));
|
||||
assert!(!response.contains(&subscriber.email));
|
||||
}
|
||||
|
||||
#[sqlx::test]
|
||||
async fn posts_are_visible_on_the_dashboard(connection_pool: PgPool) {
|
||||
let app = TestApp::spawn(connection_pool).await;
|
||||
app.admin_login().await;
|
||||
|
||||
let response = app.get_admin_dashboard_html().await;
|
||||
assert!(response.contains("No posts to display"));
|
||||
|
||||
let response = app.post_create_post(&fake_post_body()).await;
|
||||
assert!(
|
||||
response
|
||||
.text()
|
||||
.await
|
||||
.unwrap()
|
||||
.contains("Your new post has been published")
|
||||
);
|
||||
|
||||
let (post_id, post_title) = {
|
||||
let record = sqlx::query!("SELECT post_id, title FROM posts")
|
||||
.fetch_one(&app.connection_pool)
|
||||
.await
|
||||
.unwrap();
|
||||
(record.post_id, record.title)
|
||||
};
|
||||
|
||||
let html = app.get_admin_dashboard_html().await;
|
||||
assert!(html.contains(&post_title));
|
||||
|
||||
app.delete_post(post_id).await;
|
||||
let response = app.get_admin_dashboard_html().await;
|
||||
assert!(response.contains("No posts to display"));
|
||||
}
|
||||
|
||||
#[sqlx::test]
|
||||
async fn comments_are_visible_on_the_dashboard(connection_pool: PgPool) {
|
||||
let app = TestApp::spawn(connection_pool).await;
|
||||
app.admin_login().await;
|
||||
|
||||
let response = app.get_admin_dashboard_html().await;
|
||||
assert!(response.contains("No comments to display"));
|
||||
|
||||
app.post_create_post(&fake_post_body()).await;
|
||||
|
||||
let (post_id, post_title) = {
|
||||
let record = sqlx::query!("SELECT post_id, title FROM posts")
|
||||
.fetch_one(&app.connection_pool)
|
||||
.await
|
||||
.unwrap();
|
||||
(record.post_id, record.title)
|
||||
};
|
||||
|
||||
let author = "author";
|
||||
let content = "comment";
|
||||
let comment_body = serde_json::json!({
|
||||
"author": author,
|
||||
"content": content,
|
||||
"idempotency_key": "key"
|
||||
});
|
||||
app.post_comment(&post_id, &comment_body).await;
|
||||
|
||||
let response = app.get_admin_dashboard_html().await;
|
||||
assert!(response.contains(author));
|
||||
assert!(response.contains(content));
|
||||
|
||||
let html = app.get_admin_dashboard_html().await;
|
||||
assert!(html.contains(&post_title));
|
||||
|
||||
let comment_id = {
|
||||
let record = sqlx::query!("SELECT comment_id FROM comments")
|
||||
.fetch_one(&app.connection_pool)
|
||||
.await
|
||||
.unwrap();
|
||||
record.comment_id
|
||||
};
|
||||
|
||||
app.delete_comment(comment_id).await;
|
||||
let response = app.get_admin_dashboard_html().await;
|
||||
assert!(response.contains("No comments to display"));
|
||||
}
|
||||
|
||||
#[sqlx::test]
|
||||
async fn dashboard_shows_correct_stats(connection_pool: PgPool) {
|
||||
let app = TestApp::spawn(connection_pool).await;
|
||||
|
||||
Reference in New Issue
Block a user