2019-08-09 10:08:01 -07:00
|
|
|
# Pleroma: A lightweight social networking server
|
2021-01-12 22:49:20 -08:00
|
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
2019-08-09 10:08:01 -07:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2019-08-13 10:20:26 -07:00
|
|
|
defmodule Pleroma.Tests.ObanHelpers do
|
2019-08-09 10:08:01 -07:00
|
|
|
@moduledoc """
|
|
|
|
Oban test helpers.
|
|
|
|
"""
|
|
|
|
|
2020-09-04 10:48:52 -07:00
|
|
|
require Ecto.Query
|
|
|
|
|
2019-08-09 10:08:01 -07:00
|
|
|
alias Pleroma.Repo
|
|
|
|
|
2020-01-24 23:47:30 -08:00
|
|
|
def wipe_all do
|
|
|
|
Repo.delete_all(Oban.Job)
|
|
|
|
end
|
|
|
|
|
2019-08-10 10:38:31 -07:00
|
|
|
def perform_all do
|
|
|
|
Oban.Job
|
2020-09-04 10:48:52 -07:00
|
|
|
|> Ecto.Query.where(state: "available")
|
2019-08-10 10:38:31 -07:00
|
|
|
|> Repo.all()
|
|
|
|
|> perform()
|
|
|
|
end
|
|
|
|
|
2019-08-09 10:08:01 -07:00
|
|
|
def perform(%Oban.Job{} = job) do
|
2020-06-23 05:09:01 -07:00
|
|
|
res = apply(String.to_existing_atom("Elixir." <> job.worker), :perform, [job])
|
2019-08-09 10:08:01 -07: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
|