2022-08-06 04:31:36 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
|
|
|
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Workers.ReceiverWorkerTest do
|
|
|
|
use Pleroma.DataCase, async: true
|
|
|
|
use Oban.Testing, repo: Pleroma.Repo
|
|
|
|
|
|
|
|
import Mock
|
|
|
|
import Pleroma.Factory
|
|
|
|
|
|
|
|
alias Pleroma.Workers.ReceiverWorker
|
|
|
|
|
2023-03-05 06:37:59 +00:00
|
|
|
test "it does not retry MRF reject" do
|
2022-08-06 04:31:36 +00:00
|
|
|
params = insert(:note).data
|
|
|
|
|
|
|
|
with_mock Pleroma.Web.ActivityPub.Transmogrifier,
|
|
|
|
handle_incoming: fn _ -> {:reject, "MRF"} end do
|
|
|
|
assert {:cancel, "MRF"} =
|
|
|
|
ReceiverWorker.perform(%Oban.Job{
|
|
|
|
args: %{"op" => "incoming_ap_doc", "params" => params}
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
2023-03-05 06:37:59 +00:00
|
|
|
|
|
|
|
test "it does not retry ObjectValidator reject" do
|
|
|
|
params =
|
|
|
|
insert(:note_activity).data
|
|
|
|
|> Map.put("id", Pleroma.Web.ActivityPub.Utils.generate_activity_id())
|
|
|
|
|> Map.put("object", %{
|
|
|
|
"type" => "Note",
|
|
|
|
"id" => Pleroma.Web.ActivityPub.Utils.generate_object_id()
|
|
|
|
})
|
|
|
|
|
|
|
|
with_mock Pleroma.Web.ActivityPub.ObjectValidator, [:passthrough],
|
|
|
|
validate: fn _, _ -> {:error, %Ecto.Changeset{}} end do
|
|
|
|
assert {:cancel, {:error, %Ecto.Changeset{}}} =
|
|
|
|
ReceiverWorker.perform(%Oban.Job{
|
|
|
|
args: %{"op" => "incoming_ap_doc", "params" => params}
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it does not retry duplicates" do
|
|
|
|
params = insert(:note_activity).data
|
|
|
|
|
|
|
|
assert {:cancel, :already_present} =
|
|
|
|
ReceiverWorker.perform(%Oban.Job{
|
|
|
|
args: %{"op" => "incoming_ap_doc", "params" => params}
|
|
|
|
})
|
|
|
|
end
|
2022-08-06 04:31:36 +00:00
|
|
|
end
|