Merge remote-tracking branch 'origin/translations' into develop
[akkoma] / test / pleroma / workers / purge_expired_activity_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Workers.PurgeExpiredActivityTest do
6 use Pleroma.DataCase, async: true
7 use Oban.Testing, repo: Pleroma.Repo
8
9 import Pleroma.Factory
10
11 alias Pleroma.Workers.PurgeExpiredActivity
12
13 test "enqueue job" do
14 activity = insert(:note_activity)
15
16 assert {:ok, _} =
17 PurgeExpiredActivity.enqueue(%{
18 activity_id: activity.id,
19 expires_at: DateTime.add(DateTime.utc_now(), 3601)
20 })
21
22 assert_enqueued(
23 worker: Pleroma.Workers.PurgeExpiredActivity,
24 args: %{activity_id: activity.id}
25 )
26
27 assert {:ok, _} =
28 perform_job(Pleroma.Workers.PurgeExpiredActivity, %{activity_id: activity.id})
29
30 assert %Oban.Job{} = Pleroma.Workers.PurgeExpiredActivity.get_expiration(activity.id)
31 end
32
33 test "error if user was not found" do
34 activity = insert(:note_activity)
35
36 assert {:ok, _} =
37 PurgeExpiredActivity.enqueue(%{
38 activity_id: activity.id,
39 expires_at: DateTime.add(DateTime.utc_now(), 3601)
40 })
41
42 user = Pleroma.User.get_by_ap_id(activity.actor)
43 Pleroma.Repo.delete(user)
44
45 assert {:error, :user_not_found} =
46 perform_job(Pleroma.Workers.PurgeExpiredActivity, %{activity_id: activity.id})
47 end
48
49 test "error if actiivity was not found" do
50 assert {:ok, _} =
51 PurgeExpiredActivity.enqueue(%{
52 activity_id: "some_id",
53 expires_at: DateTime.add(DateTime.utc_now(), 3601)
54 })
55
56 assert {:error, :activity_not_found} =
57 perform_job(Pleroma.Workers.PurgeExpiredActivity, %{activity_id: "some_if"})
58 end
59
60 test "has a timeout" do
61 clear_config([:workers, :timeout, :activity_expiration], 50)
62 assert Pleroma.Workers.PurgeExpiredActivity.timeout(%Oban.Job{}) == 50
63 end
64 end