Test the final refresh behavior of a PollWorker poll_end job

This commit is contained in:
Mark Felder 2024-10-09 20:15:00 -04:00
parent 03a6e33b81
commit 5b04c2bf13
2 changed files with 30 additions and 5 deletions

View file

@ -11,10 +11,10 @@ defmodule Pleroma.Workers.PollWorkerTest do
alias Pleroma.Workers.PollWorker
test "poll notification job" do
test "local poll ending notification job" do
user = insert(:user)
question = insert(:question, user: user)
activity = insert(:question_activity, question: question)
activity = insert(:question_activity, question: question, user: user)
PollWorker.schedule_poll_end(activity)
@ -45,14 +45,38 @@ test "poll notification job" do
assert called(Pleroma.Web.Streamer.stream(["user", "user:notification"], :_))
assert called(Pleroma.Web.Push.send(:_))
# Ensure we scheduled a final refresh of the poll
assert_enqueued(
# Skip refreshing polls for local activities
assert activity.local
refute_enqueued(
worker: PollWorker,
args: %{"op" => "refresh", "activity_id" => activity.id}
)
end
end
test "remote poll ending notification job schedules refresh" do
user = insert(:user, local: false)
question = insert(:question, user: user)
activity = insert(:question_activity, question: question, user: user)
PollWorker.schedule_poll_end(activity)
expected_job_args = %{"activity_id" => activity.id, "op" => "poll_end"}
assert_enqueued(args: expected_job_args)
[job] = all_enqueued(worker: PollWorker)
PollWorker.perform(job)
refute activity.local
assert_enqueued(
worker: PollWorker,
args: %{"op" => "refresh", "activity_id" => activity.id}
)
end
test "poll refresh" do
user = insert(:user, local: false)
question = insert(:question, user: user)

View file

@ -510,7 +510,8 @@ def question_activity_factory(attrs \\ %{}) do
%Pleroma.Activity{
data: data,
actor: data["actor"],
recipients: data["to"]
recipients: data["to"],
local: user.local
}
|> Map.merge(attrs)
end