diff options
author | Mark Felder <feld@feld.me> | 2024-06-11 15:59:48 -0400 |
---|---|---|
committer | Mark Felder <feld@feld.me> | 2024-06-11 15:59:48 -0400 |
commit | 2fd155fb9bb82401131b40cc62dd17fc44086361 (patch) | |
tree | 6767cfabaa20967bd0642b5f21183757b61fca02 | |
parent | 51eeb8082257c152f26a3abed68c009fd3d1e262 (diff) | |
download | pleroma-2fd155fb9bb82401131b40cc62dd17fc44086361.tar.gz pleroma-2fd155fb9bb82401131b40cc62dd17fc44086361.zip |
Add PollWorker test; move the streaming notification test to it
-rw-r--r-- | test/pleroma/notification_test.exs | 27 | ||||
-rw-r--r-- | test/pleroma/workers/poll_worker_test.exs | 49 |
2 files changed, 51 insertions, 25 deletions
diff --git a/test/pleroma/notification_test.exs b/test/pleroma/notification_test.exs index 02ae06c63..2c582c708 100644 --- a/test/pleroma/notification_test.exs +++ b/test/pleroma/notification_test.exs @@ -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) - - Enum.each(notifications, fn notification -> - assert called(Pleroma.Web.Streamer.stream(["user", "user:notification"], notification)) - assert called(Pleroma.Web.Push.send(notification)) - end) + {:ok, notifications} = Notification.create_poll_notifications(activity) - 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 diff --git a/test/pleroma/workers/poll_worker_test.exs b/test/pleroma/workers/poll_worker_test.exs new file mode 100644 index 000000000..749df8aff --- /dev/null +++ b/test/pleroma/workers/poll_worker_test.exs @@ -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 |