First
[anni] / test / pleroma / workers / receiver_worker_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Workers.ReceiverWorkerTest do
6   use Pleroma.DataCase, async: true
7   use Oban.Testing, repo: Pleroma.Repo
8
9   import Mock
10   import Pleroma.Factory
11
12   alias Pleroma.Workers.ReceiverWorker
13
14   test "it does not retry MRF reject" do
15     params = insert(:note).data
16
17     with_mock Pleroma.Web.ActivityPub.Transmogrifier,
18       handle_incoming: fn _ -> {:reject, "MRF"} end do
19       assert {:cancel, "MRF"} =
20                ReceiverWorker.perform(%Oban.Job{
21                  args: %{"op" => "incoming_ap_doc", "params" => params}
22                })
23     end
24   end
25
26   test "it does not retry ObjectValidator reject" do
27     params =
28       insert(:note_activity).data
29       |> Map.put("id", Pleroma.Web.ActivityPub.Utils.generate_activity_id())
30       |> Map.put("object", %{
31         "type" => "Note",
32         "id" => Pleroma.Web.ActivityPub.Utils.generate_object_id()
33       })
34
35     with_mock Pleroma.Web.ActivityPub.ObjectValidator, [:passthrough],
36       validate: fn _, _ -> {:error, %Ecto.Changeset{}} end do
37       assert {:cancel, {:error, %Ecto.Changeset{}}} =
38                ReceiverWorker.perform(%Oban.Job{
39                  args: %{"op" => "incoming_ap_doc", "params" => params}
40                })
41     end
42   end
43
44   test "it does not retry duplicates" do
45     params = insert(:note_activity).data
46
47     assert {:cancel, :already_present} =
48              ReceiverWorker.perform(%Oban.Job{
49                args: %{"op" => "incoming_ap_doc", "params" => params}
50              })
51   end
52 end