removed try/rescue
[akkoma] / test / workers / cron / purge_expired_activities_worker_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Workers.Cron.PurgeExpiredActivitiesWorkerTest do
6 use Pleroma.DataCase
7
8 alias Pleroma.ActivityExpiration
9 alias Pleroma.Workers.Cron.PurgeExpiredActivitiesWorker
10
11 import Pleroma.Factory
12 import ExUnit.CaptureLog
13
14 clear_config([ActivityExpiration, :enabled])
15
16 test "deletes an expiration activity" do
17 Pleroma.Config.put([ActivityExpiration, :enabled], true)
18 activity = insert(:note_activity)
19
20 naive_datetime =
21 NaiveDateTime.add(
22 NaiveDateTime.utc_now(),
23 -:timer.minutes(2),
24 :millisecond
25 )
26
27 expiration =
28 insert(
29 :expiration_in_the_past,
30 %{activity_id: activity.id, scheduled_at: naive_datetime}
31 )
32
33 Pleroma.Workers.Cron.PurgeExpiredActivitiesWorker.perform(:ops, :pid)
34
35 refute Pleroma.Repo.get(Pleroma.Activity, activity.id)
36 refute Pleroma.Repo.get(Pleroma.ActivityExpiration, expiration.id)
37 end
38
39 describe "delete_activity/1" do
40 test "adds log message if activity isn't find" do
41 assert capture_log([level: :error], fn ->
42 PurgeExpiredActivitiesWorker.delete_activity(%ActivityExpiration{
43 activity_id: "test-activity"
44 })
45 end) =~ "Couldn't delete expired activity: not found activity"
46 end
47
48 test "adds log message if actor isn't find" do
49 assert capture_log([level: :error], fn ->
50 PurgeExpiredActivitiesWorker.delete_activity(%ActivityExpiration{
51 activity_id: "test-activity"
52 })
53 end) =~ "Couldn't delete expired activity: not found activity"
54 end
55 end
56 end