projects
/
akkoma
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge develop
[akkoma]
/
test
/
notification_test.exs
diff --git
a/test/notification_test.exs
b/test/notification_test.exs
index 907b9e6697c9bd31ddfa1686ac5f6f6f24d24aa3..eec0a48292ccb382aa587c32775cc909fe6715cb 100644
(file)
--- a/
test/notification_test.exs
+++ b/
test/notification_test.exs
@@
-4,12
+4,14
@@
defmodule Pleroma.NotificationTest do
use Pleroma.DataCase
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.TwitterAPI.TwitterAPI
alias Pleroma.Notification
alias Pleroma.User
alias Pleroma.Web.ActivityPub.Transmogrifier
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.TwitterAPI.TwitterAPI
- import Pleroma.Factory
describe "create_notifications" do
test "notifies someone when they are directly addressed" do
describe "create_notifications" do
test "notifies someone when they are directly addressed" do
@@
-46,7
+48,7
@@
defmodule Pleroma.NotificationTest do
describe "create_notification" do
test "it doesn't create a notification for user if the user blocks the activity author" do
activity = insert(:note_activity)
describe "create_notification" do
test "it doesn't create a notification for user if the user blocks the activity author" do
activity = insert(:note_activity)
- author = User.get_by_ap_id(activity.data["actor"])
+ author = User.get_
cached_
by_ap_id(activity.data["actor"])
user = insert(:user)
{:ok, user} = User.block(user, author)
user = insert(:user)
{:ok, user} = User.block(user, author)
@@
-124,7
+126,7
@@
defmodule Pleroma.NotificationTest do
test "it doesn't create a notification for user if he is the activity author" do
activity = insert(:note_activity)
test "it doesn't create a notification for user if he is the activity author" do
activity = insert(:note_activity)
- author = User.get_by_ap_id(activity.data["actor"])
+ author = User.get_
cached_
by_ap_id(activity.data["actor"])
assert nil == Notification.create_notification(activity, author)
end
assert nil == Notification.create_notification(activity, author)
end
@@
-300,27
+302,49
@@
defmodule Pleroma.NotificationTest do
assert n2.seen == true
assert n3.seen == false
end
assert n2.seen == true
assert n3.seen == false
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 "
Updates `updated_at` field
" do
+ test "
Returns recent notifications
" do
user1 = insert(:user)
user2 = insert(:user)
Enum.each(0..10, fn i ->
{:ok, _activity} =
user1 = insert(:user)
user2 = insert(:user)
Enum.each(0..10, fn i ->
{:ok, _activity} =
-
TwitterAPI.create_status
(user1, %{
- "status" => "
#{i} hi @#{user2.nickname}
"
+
CommonAPI.post
(user1, %{
+ "status" => "
hey ##{i} @#{user2.nickname}!
"
})
end)
})
end)
-
Process.sleep(1000
)
+
{old, new} = Enum.split(Notification.for_user(user2), 5
)
- [notification | _] = Notification.for_user(user2)
+ Enum.each(old, fn notification ->
+ notification
+ |> cast(%{updated_at: days_ago(10)}, [:updated_at])
+ |> Pleroma.Repo.update!()
+ end)
- Notification.set_read_up_to(user2, notification.id)
+ 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)
- Notification.for_user(user2)
- |> Enum.each(fn notification ->
- assert notification.updated_at > notification.inserted_at
+ Enum.each(new, fn %{id: id} ->
+ assert id in recent_notifications_ids
end)
end
end
end)
end
end