2019-08-09 17:08:01 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
|
|
|
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2019-08-13 17:20:26 +00:00
|
|
|
defmodule Pleroma.Tests.ObanHelpers do
|
2019-08-09 17:08:01 +00:00
|
|
|
@moduledoc """
|
|
|
|
Oban test helpers.
|
|
|
|
"""
|
|
|
|
|
|
|
|
alias Pleroma.Repo
|
|
|
|
|
2019-08-10 17:38:31 +00:00
|
|
|
def perform_all do
|
|
|
|
Oban.Job
|
|
|
|
|> Repo.all()
|
|
|
|
|> perform()
|
|
|
|
end
|
|
|
|
|
2019-08-09 17:08:01 +00:00
|
|
|
def perform(%Oban.Job{} = job) do
|
2019-08-23 06:23:10 +00:00
|
|
|
res = apply(String.to_existing_atom("Elixir." <> job.worker), :perform, [job.args, job])
|
2019-08-09 17:08:01 +00:00
|
|
|
Repo.delete(job)
|
|
|
|
res
|
|
|
|
end
|
|
|
|
|
|
|
|
def perform(jobs) when is_list(jobs) do
|
|
|
|
for job <- jobs, do: perform(job)
|
|
|
|
end
|
|
|
|
|
|
|
|
def member?(%{} = job_args, jobs) when is_list(jobs) do
|
|
|
|
Enum.any?(jobs, fn job ->
|
|
|
|
member?(job_args, job.args)
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
|
|
|
def member?(%{} = test_attrs, %{} = attrs) do
|
|
|
|
Enum.all?(
|
|
|
|
test_attrs,
|
|
|
|
fn {k, _v} -> member?(test_attrs[k], attrs[k]) end
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def member?(x, y), do: x == y
|
|
|
|
end
|