diff options
| author | lain <lain@soykaf.club> | 2019-08-08 14:38:33 +0000 |
|---|---|---|
| committer | lain <lain@soykaf.club> | 2019-08-08 14:38:33 +0000 |
| commit | 29807ef6a5b43a528ffca08b4f721b251f331c8d (patch) | |
| tree | 76930c3a3dc12b95bcb57a9b4832f861dd68d960 /test/notification_test.exs | |
| parent | b18234e04c76daa564e0d8157dcd09566485da24 (diff) | |
| parent | 9d4f34fbcb1a8e2eca424b3a3374c9f9af972574 (diff) | |
| download | pleroma-29807ef6a5b43a528ffca08b4f721b251f331c8d.tar.gz pleroma-29807ef6a5b43a528ffca08b4f721b251f331c8d.zip | |
Merge branch 'feature/digest-email' into 'develop'
Feature/digest email
See merge request pleroma/pleroma!1078
Diffstat (limited to 'test/notification_test.exs')
| -rw-r--r-- | test/notification_test.exs | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/test/notification_test.exs b/test/notification_test.exs index c88ac54bd..80ea2a085 100644 --- a/test/notification_test.exs +++ b/test/notification_test.exs @@ -4,13 +4,15 @@ defmodule Pleroma.NotificationTest do use Pleroma.DataCase + + import Pleroma.Factory + alias Pleroma.Notification alias Pleroma.User alias Pleroma.Web.ActivityPub.Transmogrifier alias Pleroma.Web.CommonAPI alias Pleroma.Web.Streamer alias Pleroma.Web.TwitterAPI.TwitterAPI - import Pleroma.Factory describe "create_notifications" do test "notifies someone when they are directly addressed" do @@ -352,6 +354,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 * 86_400, :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) |
