Fix formatting and add delete idempotency test

This commit is contained in:
Alex Selimov 2026-03-19 13:46:40 -04:00
parent ea0c26a151
commit 3812563a5b

View file

@ -76,15 +76,42 @@ mod postgres_tests {
pub async fn postgres_tests() { pub async fn postgres_tests() {
let db = test_pool().await; let db = test_pool().await;
let votes = vec![ let votes = vec![
("postgres_tests_blog_post1".to_string(), Uuid::from_u128(0x1)), (
("postgres_tests_blog_post1".to_string(), Uuid::from_u128(0x2)), "postgres_tests_blog_post1".to_string(),
("postgres_tests_blog_post2".to_string(), Uuid::from_u128(0x3)), Uuid::from_u128(0x1),
("postgres_tests_blog_post2".to_string(), Uuid::from_u128(0x4)), ),
("postgres_tests_blog_post3".to_string(), Uuid::from_u128(0x5)), (
("postgres_tests_blog_post3".to_string(), Uuid::from_u128(0x6)), "postgres_tests_blog_post1".to_string(),
("postgres_tests_blog_post1".to_string(), Uuid::from_u128(0x7)), Uuid::from_u128(0x2),
("postgres_tests_blog_post1".to_string(), Uuid::from_u128(0x8)), ),
("postgres_tests_blog_post3".to_string(), Uuid::from_u128(0x9)), (
"postgres_tests_blog_post2".to_string(),
Uuid::from_u128(0x3),
),
(
"postgres_tests_blog_post2".to_string(),
Uuid::from_u128(0x4),
),
(
"postgres_tests_blog_post3".to_string(),
Uuid::from_u128(0x5),
),
(
"postgres_tests_blog_post3".to_string(),
Uuid::from_u128(0x6),
),
(
"postgres_tests_blog_post1".to_string(),
Uuid::from_u128(0x7),
),
(
"postgres_tests_blog_post1".to_string(),
Uuid::from_u128(0x8),
),
(
"postgres_tests_blog_post3".to_string(),
Uuid::from_u128(0x9),
),
]; ];
cleanup(&db, &votes).await; cleanup(&db, &votes).await;
@ -156,12 +183,24 @@ mod postgres_tests {
)]; )];
cleanup(&db, &votes).await; cleanup(&db, &votes).await;
insert_new_vote(&votes[0].0, &votes[0].1, &db).await.unwrap(); insert_new_vote(&votes[0].0, &votes[0].1, &db)
insert_new_vote(&votes[0].0, &votes[0].1, &db).await.unwrap(); .await
insert_new_vote(&votes[0].0, &votes[0].1, &db).await.unwrap(); .unwrap();
insert_new_vote(&votes[0].0, &votes[0].1, &db).await.unwrap(); insert_new_vote(&votes[0].0, &votes[0].1, &db)
insert_new_vote(&votes[0].0, &votes[0].1, &db).await.unwrap(); .await
insert_new_vote(&votes[0].0, &votes[0].1, &db).await.unwrap(); .unwrap();
insert_new_vote(&votes[0].0, &votes[0].1, &db)
.await
.unwrap();
insert_new_vote(&votes[0].0, &votes[0].1, &db)
.await
.unwrap();
insert_new_vote(&votes[0].0, &votes[0].1, &db)
.await
.unwrap();
insert_new_vote(&votes[0].0, &votes[0].1, &db)
.await
.unwrap();
let votes_count = get_vote_count_for_slug(&votes[0].0, &db).await.unwrap(); let votes_count = get_vote_count_for_slug(&votes[0].0, &db).await.unwrap();
@ -169,4 +208,29 @@ mod postgres_tests {
cleanup(&db, &votes).await; cleanup(&db, &votes).await;
} }
#[tokio::test]
#[ignore]
pub async fn delete_idempotency_test() {
let db = test_pool().await;
let votes = vec![(
"delete_idempotency_test_blog_post1".to_string(),
Uuid::from_u128(0x1),
)];
cleanup(&db, &votes).await;
insert_new_vote(&votes[0].0, &votes[0].1, &db)
.await
.unwrap();
delete_vote(&votes[0].0, &votes[0].1, &db).await.unwrap();
delete_vote(&votes[0].0, &votes[0].1, &db).await.unwrap();
delete_vote(&votes[0].0, &votes[0].1, &db).await.unwrap();
let votes_count = get_vote_count_for_slug(&votes[0].0, &db).await.unwrap();
assert_eq!(votes_count, 0);
cleanup(&db, &votes).await;
}
} }