From f100fce0da57d21f77b4bdd7713ed2e8d5bf2a05 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Fri, 4 Jun 2021 16:32:26 +0200 Subject: [PATCH] Finally fix backend tests Signed-off-by: Thomas Citharel --- lib/mix/tasks/mobilizon/common.ex | 2 +- test/graphql/resolvers/activity_test.exs | 1 + .../service/workers/activity_builder_test.exs | 3 ++- .../workers/legacy_notifier_builder_test.exs | 23 +++++++++++-------- test/support/factory.ex | 4 +++- 5 files changed, 21 insertions(+), 12 deletions(-) diff --git a/lib/mix/tasks/mobilizon/common.ex b/lib/mix/tasks/mobilizon/common.ex index b46fe3d27..4ee5d96f9 100644 --- a/lib/mix/tasks/mobilizon/common.ex +++ b/lib/mix/tasks/mobilizon/common.ex @@ -12,7 +12,7 @@ defmodule Mix.Tasks.Mobilizon.Common do def start_mobilizon do if mix_task?(), do: Mix.Task.run("app.config") - unless System.get_env("DEBUG") do + unless System.get_env("DEBUG") || Application.fetch_env!(:mobilizon, :env) == :test do Logger.configure(level: :error) end diff --git a/test/graphql/resolvers/activity_test.exs b/test/graphql/resolvers/activity_test.exs index 3555f6fc0..7dd8f3bb1 100644 --- a/test/graphql/resolvers/activity_test.exs +++ b/test/graphql/resolvers/activity_test.exs @@ -260,6 +260,7 @@ defmodule Mobilizon.GraphQL.Resolvers.ActivityTest do group: %Actor{preferred_username: preferred_username, id: group_id} = group } do user = insert(:user) + insert(:settings, user_id: user.id, user: user) actor = insert(:actor, user: user) insert(:member, diff --git a/test/service/workers/activity_builder_test.exs b/test/service/workers/activity_builder_test.exs index 480ddaa5f..7bf7912ec 100644 --- a/test/service/workers/activity_builder_test.exs +++ b/test/service/workers/activity_builder_test.exs @@ -10,6 +10,7 @@ defmodule Mobilizon.Service.Workers.ActivityBuilderTest do alias Mobilizon.Users.User use Mobilizon.DataCase + use Mobilizon.Tests.Helpers import Mobilizon.Factory import Mox @@ -17,7 +18,7 @@ defmodule Mobilizon.Service.Workers.ActivityBuilderTest do setup_all do Mox.defmock(NotifierMock, for: Mobilizon.Service.Notifier) - Mobilizon.Config.put([Mobilizon.Service.Notifier, :notifiers], [ + clear_config([Mobilizon.Service.Notifier, :notifiers], [ NotifierMock ]) diff --git a/test/service/workers/legacy_notifier_builder_test.exs b/test/service/workers/legacy_notifier_builder_test.exs index e6ffb6d28..754657a01 100644 --- a/test/service/workers/legacy_notifier_builder_test.exs +++ b/test/service/workers/legacy_notifier_builder_test.exs @@ -9,17 +9,18 @@ defmodule Mobilizon.Service.Workers.LegacyNotifierBuilderTest do alias Mobilizon.Events.Event alias Mobilizon.Service.Notifier.Mock, as: NotifierMock alias Mobilizon.Service.Workers.LegacyNotifierBuilder - alias Mobilizon.Users.User + alias Mobilizon.Users.{Setting, User} - use Mobilizon.DataCase, async: true + use Mobilizon.DataCase + use Mobilizon.Tests.Helpers import Mox import Mobilizon.Factory setup_all do - Mox.defmock(Mobilizon.Service.Notifier.Mock, for: Mobilizon.Service.Notifier) + Mox.defmock(NotifierMock, for: Mobilizon.Service.Notifier) - Mobilizon.Config.put([Mobilizon.Service.Notifier, :notifiers], [ - Mobilizon.Service.Notifier.Mock + clear_config([Mobilizon.Service.Notifier, :notifiers], [ + NotifierMock ]) :ok @@ -56,8 +57,8 @@ defmodule Mobilizon.Service.Workers.LegacyNotifierBuilderTest do args = Map.merge(@mentionned, %{ "subject_params" => %{ - event_uuid: uuid, - event_title: title + "event_uuid" => uuid, + "event_title" => title }, "author_id" => actor_id, "object_id" => to_string(comment_id), @@ -82,6 +83,8 @@ defmodule Mobilizon.Service.Workers.LegacyNotifierBuilderTest do test "if the actor mentionned is local" do %User{} = user1 = insert(:user) %User{} = user2 = insert(:user) + %Setting{} = settings2 = insert(:settings, user: user2, user_id: user2.id) + user2 = %User{user2 | settings: settings2} %Actor{id: actor_id} = actor = insert(:actor, user: user1) %Actor{id: actor_id_2} = insert(:actor, user: user2) @@ -92,8 +95,8 @@ defmodule Mobilizon.Service.Workers.LegacyNotifierBuilderTest do args = Map.merge(@mentionned, %{ "subject_params" => %{ - event_uuid: uuid, - event_title: title + "event_uuid" => uuid, + "event_title" => title }, "author_id" => actor_id, "object_id" => to_string(comment_id), @@ -155,6 +158,8 @@ defmodule Mobilizon.Service.Workers.LegacyNotifierBuilderTest do test "if there's some participants" do %User{} = user1 = insert(:user) %User{} = user2 = insert(:user) + %Setting{} = settings2 = insert(:settings, user: user2, user_id: user2.id) + user2 = %User{user2 | settings: settings2} %Actor{id: actor_id} = actor = insert(:actor, user: user1) %Actor{} = actor2 = insert(:actor, user: user2) diff --git a/test/support/factory.ex b/test/support/factory.ex index c55039ac0..585376cbf 100644 --- a/test/support/factory.ex +++ b/test/support/factory.ex @@ -31,7 +31,9 @@ defmodule Mobilizon.Factory do notification_before_event: false, notification_pending_participation: :one_day, notification_pending_membership: :one_day, - user_id: nil + group_notifications: :one_day, + last_notification_sent: nil, + user: build(:user) } end