fix tests

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak 2022-11-21 15:43:15 +01:00
parent 86d1358b4f
commit 0a3f523329
3 changed files with 16 additions and 6 deletions

View file

@ -1190,7 +1190,10 @@ def update_and_set_cache(%{data: %Pleroma.User{} = user} = changeset) do
was_superuser_before_update = User.superuser?(user)
with {:ok, user} <- Repo.update(changeset, stale_error_field: :id) do
BackgroundWorker.enqueue("verify_fields_links", %{"user_id" => user.id})
if get_change(changeset, :raw_fields) do
BackgroundWorker.enqueue("verify_fields_links", %{"user_id" => user.id})
end
set_cache(user)
end
|> maybe_remove_report_notifications(was_superuser_before_update)

View file

@ -12,7 +12,7 @@ defmodule Pleroma.Webhook.Notify do
def trigger_webhooks(%Activity{} = activity, :"report.created" = type) do
webhooks = Webhook.get_by_type(type)
Enum.each(webhooks, fn webhook ->
Enum.map(webhooks, fn webhook ->
ConcurrentLimiter.limit(Webhook.Notify, fn ->
Task.start(fn -> report_created(webhook, activity) end)
end)
@ -22,7 +22,7 @@ def trigger_webhooks(%Activity{} = activity, :"report.created" = type) do
def trigger_webhooks(%User{} = user, :"account.created" = type) do
webhooks = Webhook.get_by_type(type)
Enum.each(webhooks, fn webhook ->
Enum.map(webhooks, fn webhook ->
ConcurrentLimiter.limit(Webhook.Notify, fn ->
Task.start(fn -> account_created(webhook, user) end)
end)

View file

@ -14,9 +14,10 @@ test "notifies have a valid signature" do
activity = insert(:report_activity)
%{secret: secret} =
webhook = Webhook.create(%{url: "https://example.com/webhook", events: [:"report.created"]})
Webhook.create(%{url: "https://example.com/webhook", events: [:"report.created"]})
Tesla.Mock.mock(fn %{url: "https://example.com/webhook", body: body, headers: headers} = _ ->
Tesla.Mock.mock_global(fn %{url: "https://example.com/webhook", body: body, headers: headers} =
_ ->
{"X-Hub-Signature", "sha256=" <> signature} =
Enum.find(headers, fn {key, _} -> key == "X-Hub-Signature" end)
@ -24,6 +25,12 @@ test "notifies have a valid signature" do
%Tesla.Env{status: 200, body: ""}
end)
Notify.report_created(webhook, activity)
[{:ok, task}] = Notify.trigger_webhooks(activity, :"report.created")
ref = Process.monitor(task)
receive do
{:DOWN, ^ref, _, _, _} -> nil
end
end
end