Add PollWorker test; move the streaming notification test to it

This commit is contained in:
Mark Felder 2024-06-11 15:59:48 -04:00
parent 51eeb80822
commit 2fd155fb9b
2 changed files with 51 additions and 25 deletions

View File

@ -5,7 +5,6 @@
defmodule Pleroma.NotificationTest do
use Pleroma.DataCase, async: false
import Mock
import Pleroma.Factory
alias Pleroma.FollowingRelationship
@ -184,31 +183,9 @@ defmodule Pleroma.NotificationTest do
{:ok, _, _} = CommonAPI.vote(user2, question, [0])
{:ok, _, _} = CommonAPI.vote(user3, question, [1])
with_mocks([
{
Pleroma.Web.Streamer,
[],
[
stream: fn _, _ -> nil end
]
},
{
Pleroma.Web.Push,
[],
[
send: fn _ -> nil end
]
}
]) do
{:ok, notifications} = Notification.create_poll_notifications(activity)
{:ok, notifications} = Notification.create_poll_notifications(activity)
Enum.each(notifications, fn notification ->
assert called(Pleroma.Web.Streamer.stream(["user", "user:notification"], notification))
assert called(Pleroma.Web.Push.send(notification))
end)
assert [user2.id, user3.id, user1.id] == Enum.map(notifications, & &1.user_id)
end
assert [user2.id, user3.id, user1.id] == Enum.map(notifications, & &1.user_id)
end
describe "create_notification" do

View File

@ -0,0 +1,49 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Workers.PollWorkerTest do
use Pleroma.DataCase
use Oban.Testing, repo: Pleroma.Repo
import Mock
import Pleroma.Factory
alias Pleroma.Workers.PollWorker
test "poll notification job" do
user = insert(:user)
question = insert(:question, user: user)
activity = insert(:question_activity, question: question)
PollWorker.schedule_poll_end(activity)
expected_job_args = %{"activity_id" => activity.id, "op" => "poll_end"}
assert_enqueued(args: expected_job_args)
with_mocks([
{
Pleroma.Web.Streamer,
[],
[
stream: fn _, _ -> nil end
]
},
{
Pleroma.Web.Push,
[],
[
send: fn _ -> nil end
]
}
]) do
[job] = all_enqueued(worker: PollWorker)
PollWorker.perform(job)
# Ensure notifications were streamed out when job executes
assert called(Pleroma.Web.Streamer.stream(["user", "user:notification"], :_))
assert called(Pleroma.Web.Push.send(:_))
end
end
end