Skip to content

Commit

Permalink
Apply scheduled post limit to future posts instead of past posts, and…
Browse files Browse the repository at this point in the history
… verify this in test (#5054)

* test scheduled_post_count

* fix syntax error

* fix formatting

* fix argument order

* fix user_scheduled_post_count function
  • Loading branch information
dullbananas authored Sep 27, 2024
1 parent 33cbd95 commit 50ce796
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions crates/db_schema/src/impls/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,9 @@ impl Post {
post::table
.inner_join(person::table)
.inner_join(community::table)
// find all posts which have scheduled_publish_time that is in the past
// find all posts which have scheduled_publish_time that is in the future
.filter(post::scheduled_publish_time.is_not_null())
.filter(coalesce(post::scheduled_publish_time, now()).lt(now()))
.filter(coalesce(post::scheduled_publish_time, now()).gt(now()))
// make sure the post and community are still around
.filter(not(post::deleted.or(post::removed)))
.filter(not(community::removed.or(community::deleted)))
Expand Down Expand Up @@ -414,6 +414,7 @@ mod tests {
traits::{Crud, Likeable, Saveable},
utils::build_db_pool_for_tests,
};
use chrono::DateTime;
use pretty_assertions::assert_eq;
use serial_test::serial;
use std::collections::HashSet;
Expand Down Expand Up @@ -456,6 +457,12 @@ mod tests {
);
let inserted_post2 = Post::create(pool, &new_post2).await.unwrap();

let new_scheduled_post = PostInsertForm {
scheduled_publish_time: Some(DateTime::from_timestamp_nanos(i64::MAX)),
..PostInsertForm::new("beans".into(), inserted_person.id, inserted_community.id)
};
let inserted_scheduled_post = Post::create(pool, &new_scheduled_post).await.unwrap();

let expected_post = Post {
id: inserted_post.id,
name: "A test post".into(),
Expand Down Expand Up @@ -535,6 +542,12 @@ mod tests {
.await
.unwrap();

// Scheduled post count
let scheduled_post_count = Post::user_scheduled_post_count(inserted_person.id, pool)
.await
.unwrap();
assert_eq!(1, scheduled_post_count);

let like_removed = PostLike::remove(pool, inserted_person.id, inserted_post.id)
.await
.unwrap();
Expand All @@ -551,8 +564,11 @@ mod tests {
assert_eq!(2, read_removed);

let num_deleted = Post::delete(pool, inserted_post.id).await.unwrap()
+ Post::delete(pool, inserted_post2.id).await.unwrap();
assert_eq!(2, num_deleted);
+ Post::delete(pool, inserted_post2.id).await.unwrap()
+ Post::delete(pool, inserted_scheduled_post.id)
.await
.unwrap();
assert_eq!(3, num_deleted);
Community::delete(pool, inserted_community.id)
.await
.unwrap();
Expand Down

0 comments on commit 50ce796

Please sign in to comment.