Merge branch 'develop' into tests/mastodon_api_controller.ex
[akkoma] / test / support / oban_helpers.ex
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.Tests.ObanHelpers do
6 @moduledoc """
7 Oban test helpers.
8 """
9
10 alias Pleroma.Repo
11
12 def perform_all do
13 Oban.Job
14 |> Repo.all()
15 |> perform()
16 end
17
18 def perform(%Oban.Job{} = job) do
19 res = apply(String.to_existing_atom("Elixir." <> job.worker), :perform, [job.args, job])
20 Repo.delete(job)
21 res
22 end
23
24 def perform(jobs) when is_list(jobs) do
25 for job <- jobs, do: perform(job)
26 end
27
28 def member?(%{} = job_args, jobs) when is_list(jobs) do
29 Enum.any?(jobs, fn job ->
30 member?(job_args, job.args)
31 end)
32 end
33
34 def member?(%{} = test_attrs, %{} = attrs) do
35 Enum.all?(
36 test_attrs,
37 fn {k, _v} -> member?(test_attrs[k], attrs[k]) end
38 )
39 end
40
41 def member?(x, y), do: x == y
42 end