logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://anongit.hacktivis.me/git/pleroma.git/
commit: a1b384f63c3587d0463109b74b0bbcc5c5ae82ee
parent b2340b5b776d243f6cf12971393783cc3b7c2dc2
Author: Mark Felder <feld@feld.me>
Date:   Mon, 30 Sep 2024 14:45:41 -0400

Test that a poll refresh is cancelled if updated_at on the object is newer than the poll closing time

Diffstat:

Mtest/pleroma/workers/poll_worker_test.exs61++++++++++++++++++++++++++++++++++++++++---------------------
1 file changed, 40 insertions(+), 21 deletions(-)

diff --git a/test/pleroma/workers/poll_worker_test.exs b/test/pleroma/workers/poll_worker_test.exs @@ -53,32 +53,51 @@ defmodule Pleroma.Workers.PollWorkerTest do end end - test "poll refresh job" do - user = insert(:user, local: false) - question = insert(:question, user: user) - activity = insert(:question_activity, question: question) + describe "poll refresh" do + test "normal job" do + user = insert(:user, local: false) + question = insert(:question, user: user) + activity = insert(:question_activity, question: question) + + PollWorker.new(%{"op" => "refresh", "activity_id" => activity.id}) + |> Oban.insert() + + expected_job_args = %{"activity_id" => activity.id, "op" => "refresh"} + + assert_enqueued(args: expected_job_args) + + with_mocks([ + { + Pleroma.Web.Streamer, + [], + [ + stream: fn _, _ -> nil end + ] + } + ]) do + [job] = all_enqueued(worker: PollWorker) + PollWorker.perform(job) + + # Ensure updates are streamed out + assert called(Pleroma.Web.Streamer.stream(["user", "list", "public", "public:local"], :_)) + end + end - PollWorker.new(%{"op" => "refresh", "activity_id" => activity.id}) - |> Oban.insert() + test "when updated_at is after poll closing" do + poll_closed = DateTime.utc_now() |> DateTime.add(-86_400) |> DateTime.to_iso8601() + user = insert(:user, local: false) + question = insert(:question, user: user, closed: poll_closed) + activity = insert(:question_activity, question: question) - expected_job_args = %{"activity_id" => activity.id, "op" => "refresh"} + PollWorker.new(%{"op" => "refresh", "activity_id" => activity.id}) + |> Oban.insert() - assert_enqueued(args: expected_job_args) + expected_job_args = %{"activity_id" => activity.id, "op" => "refresh"} - with_mocks([ - { - Pleroma.Web.Streamer, - [], - [ - stream: fn _, _ -> nil end - ] - } - ]) do - [job] = all_enqueued(worker: PollWorker) - PollWorker.perform(job) + assert_enqueued(args: expected_job_args) - # Ensure updates are streamed out - assert called(Pleroma.Web.Streamer.stream(["user", "list", "public", "public:local"], :_)) + [job] = all_enqueued(worker: PollWorker) + assert {:cancel, :poll_finalized} = PollWorker.perform(job) end end end