Merge remote-tracking branch 'origin/translations' into develop
[akkoma] / test / pleroma / workers / publisher_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.PublisherWorkerTest do
6 use Pleroma.DataCase, async: true
7 use Oban.Testing, repo: Pleroma.Repo
8
9 import Pleroma.Factory
10
11 alias Pleroma.Object
12 alias Pleroma.Web.ActivityPub.ActivityPub
13 alias Pleroma.Web.ActivityPub.Builder
14 alias Pleroma.Web.CommonAPI
15 alias Pleroma.Web.Federator
16
17 describe "Oban job priority:" do
18 setup do
19 user = insert(:user)
20
21 {:ok, post} = CommonAPI.post(user, %{status: "Regrettable post"})
22 object = Object.normalize(post, fetch: false)
23 {:ok, delete_data, _meta} = Builder.delete(user, object.data["id"])
24 {:ok, delete, _meta} = ActivityPub.persist(delete_data, local: true)
25
26 %{
27 post: post,
28 delete: delete
29 }
30 end
31
32 test "Deletions are lower priority", %{delete: delete} do
33 assert {:ok, %Oban.Job{priority: 3}} = Federator.publish(delete)
34 end
35
36 test "Creates are normal priority", %{post: post} do
37 assert {:ok, %Oban.Job{priority: 0}} = Federator.publish(post)
38 end
39 end
40
41 describe "Oban job timeout" do
42 test "should have a timeout" do
43 clear_config([:workers, :timeout, :federator_outgoing], :timer.minutes(2))
44 assert Pleroma.Workers.PublisherWorker.timeout(nil) == :timer.minutes(2)
45 end
46
47 test "should use a default timeout if none specified" do
48 clear_config([:workers, :timeout, :federator_outgoing])
49 assert Pleroma.Workers.PublisherWorker.timeout(nil) == :timer.seconds(10)
50 end
51 end
52 end