diff options
author | Roman Chvanikov <chvanikoff@gmail.com> | 2019-04-19 22:16:17 +0700 |
---|---|---|
committer | Roman Chvanikov <chvanikoff@gmail.com> | 2019-04-19 22:16:17 +0700 |
commit | aeafa0b2ef996f15f9ff4a6ade70a693b12b208f (patch) | |
tree | 3c7c46964542b55182012c40d31a2eed2f5a7ed9 /test | |
parent | 2f0203a4a1c7a507aa5cf50be2fd372536ebfc81 (diff) | |
download | pleroma-aeafa0b2ef996f15f9ff4a6ade70a693b12b208f.tar.gz |
Add Notification.for_user_since/2
Diffstat (limited to 'test')
-rw-r--r-- | test/notification_test.exs | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/test/notification_test.exs b/test/notification_test.exs index 27d8cace7..dbc4f48f6 100644 --- a/test/notification_test.exs +++ b/test/notification_test.exs @@ -331,6 +331,51 @@ defmodule Pleroma.NotificationTest do end end + describe "for_user_since/2" do + defp days_ago(days) do + NaiveDateTime.add( + NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second), + -days * 60 * 60 * 24, + :second + ) + end + + test "Returns recent notifications" do + user1 = insert(:user) + user2 = insert(:user) + + Enum.each(0..10, fn i -> + {:ok, _activity} = + CommonAPI.post(user1, %{ + "status" => "hey ##{i} @#{user2.nickname}!" + }) + end) + + {old, new} = Enum.split(Notification.for_user(user2), 5) + + Enum.each(old, fn notification -> + notification + |> cast(%{updated_at: days_ago(10)}, [:updated_at]) + |> Pleroma.Repo.update!() + end) + + recent_notifications_ids = + user2 + |> Notification.for_user_since( + NaiveDateTime.add(NaiveDateTime.utc_now(), -5 * 86400, :second) + ) + |> Enum.map(& &1.id) + + Enum.each(old, fn %{id: id} -> + refute id in recent_notifications_ids + end) + + Enum.each(new, fn %{id: id} -> + assert id in recent_notifications_ids + end) + end + end + describe "notification target determination" do test "it sends notifications to addressed users in new messages" do user = insert(:user) |