From 0a3f52332923d58bde63d2e8a078a67167dace0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Mon, 21 Nov 2022 15:43:15 +0100 Subject: [PATCH] fix tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- lib/pleroma/user.ex | 5 ++++- lib/pleroma/webhook/notify.ex | 4 ++-- test/pleroma/webhook/notify_test.exs | 13 ++++++++++--- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 1a5626f828..5784100721 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -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) diff --git a/lib/pleroma/webhook/notify.ex b/lib/pleroma/webhook/notify.ex index ec84b89ef5..f55fa55ec1 100644 --- a/lib/pleroma/webhook/notify.ex +++ b/lib/pleroma/webhook/notify.ex @@ -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) diff --git a/test/pleroma/webhook/notify_test.exs b/test/pleroma/webhook/notify_test.exs index 8aa9de08c6..4190b1a170 100644 --- a/test/pleroma/webhook/notify_test.exs +++ b/test/pleroma/webhook/notify_test.exs @@ -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