From 6ef38c6523fc8b7f28ef92d38b9ca829d8a7248e Mon Sep 17 00:00:00 2001 From: Ilja Date: Tue, 5 Jul 2022 08:57:50 +0200 Subject: [PATCH] Improve tests after code review --- test/pleroma/user/query_test.exs | 47 ++++++-------------------------- test/pleroma/user_test.exs | 47 ++++++-------------------------- 2 files changed, 16 insertions(+), 78 deletions(-) diff --git a/test/pleroma/user/query_test.exs b/test/pleroma/user/query_test.exs index 7e443536b..30a4637f2 100644 --- a/test/pleroma/user/query_test.exs +++ b/test/pleroma/user/query_test.exs @@ -58,80 +58,49 @@ defmodule Pleroma.User.QueryTest do } end - test "doesn't return any users when there are no privileged roles", %{ - user: user, - moderator_user: moderator_user, - admin_user: admin_user, - admin_moderator_user: admin_moderator_user, - remote_user: remote_user, - non_active_user: non_active_user - } do + test "doesn't return any users when there are no privileged roles" do clear_config([:instance, :admin_privileges], []) clear_config([:instance, :moderator_privileges], []) - refute user in (User.Query.build(%{is_privileged: :cofe}) |> Repo.all()) - refute admin_user in (User.Query.build(%{is_privileged: :cofe}) |> Repo.all()) - refute moderator_user in (User.Query.build(%{is_privileged: :cofe}) |> Repo.all()) - refute admin_moderator_user in (User.Query.build(%{is_privileged: :cofe}) |> Repo.all()) - refute remote_user in (User.Query.build(%{is_privileged: :cofe}) |> Repo.all()) - refute non_active_user in (User.Query.build(%{is_privileged: :cofe}) |> Repo.all()) + assert [] = User.Query.build(%{is_privileged: :cofe}) |> Repo.all() end test "returns moderator users if they are privileged", %{ - user: user, moderator_user: moderator_user, - admin_user: admin_user, - admin_moderator_user: admin_moderator_user, - remote_user: remote_user, - non_active_user: non_active_user + admin_moderator_user: admin_moderator_user } do clear_config([:instance, :admin_privileges], []) clear_config([:instance, :moderator_privileges], [:cofe]) - refute user in (User.Query.build(%{is_privileged: :cofe}) |> Repo.all()) - refute admin_user in (User.Query.build(%{is_privileged: :cofe}) |> Repo.all()) + assert [_, _] = User.Query.build(%{is_privileged: :cofe}) |> Repo.all() assert moderator_user in (User.Query.build(%{is_privileged: :cofe}) |> Repo.all()) assert admin_moderator_user in (User.Query.build(%{is_privileged: :cofe}) |> Repo.all()) - refute remote_user in (User.Query.build(%{is_privileged: :cofe}) |> Repo.all()) - refute non_active_user in (User.Query.build(%{is_privileged: :cofe}) |> Repo.all()) end test "returns admin users if they are privileged", %{ - user: user, - moderator_user: moderator_user, admin_user: admin_user, - admin_moderator_user: admin_moderator_user, - remote_user: remote_user, - non_active_user: non_active_user + admin_moderator_user: admin_moderator_user } do clear_config([:instance, :admin_privileges], [:cofe]) clear_config([:instance, :moderator_privileges], []) - refute user in (User.Query.build(%{is_privileged: :cofe}) |> Repo.all()) + assert [_, _] = User.Query.build(%{is_privileged: :cofe}) |> Repo.all() assert admin_user in (User.Query.build(%{is_privileged: :cofe}) |> Repo.all()) - refute moderator_user in (User.Query.build(%{is_privileged: :cofe}) |> Repo.all()) assert admin_moderator_user in (User.Query.build(%{is_privileged: :cofe}) |> Repo.all()) - refute remote_user in (User.Query.build(%{is_privileged: :cofe}) |> Repo.all()) - refute non_active_user in (User.Query.build(%{is_privileged: :cofe}) |> Repo.all()) end test "returns admin and moderator users if they are both privileged", %{ - user: user, moderator_user: moderator_user, admin_user: admin_user, - admin_moderator_user: admin_moderator_user, - remote_user: remote_user, - non_active_user: non_active_user + admin_moderator_user: admin_moderator_user } do clear_config([:instance, :admin_privileges], [:cofe]) clear_config([:instance, :moderator_privileges], [:cofe]) - refute user in (User.Query.build(%{is_privileged: :cofe}) |> Repo.all()) + assert [_, _, _] = User.Query.build(%{is_privileged: :cofe}) |> Repo.all() assert admin_user in (User.Query.build(%{is_privileged: :cofe}) |> Repo.all()) assert moderator_user in (User.Query.build(%{is_privileged: :cofe}) |> Repo.all()) assert admin_moderator_user in (User.Query.build(%{is_privileged: :cofe}) |> Repo.all()) - refute remote_user in (User.Query.build(%{is_privileged: :cofe}) |> Repo.all()) - refute non_active_user in (User.Query.build(%{is_privileged: :cofe}) |> Repo.all()) end end end diff --git a/test/pleroma/user_test.exs b/test/pleroma/user_test.exs index 98e00cecb..25ec44834 100644 --- a/test/pleroma/user_test.exs +++ b/test/pleroma/user_test.exs @@ -2023,80 +2023,49 @@ defmodule Pleroma.UserTest do } end - test "doesn't return any users when there are no privileged roles", %{ - user: user, - moderator_user: moderator_user, - admin_user: admin_user, - admin_moderator_user: admin_moderator_user, - remote_user: remote_user, - non_active_user: non_active_user - } do + test "doesn't return any users when there are no privileged roles" do clear_config([:instance, :admin_privileges], []) clear_config([:instance, :moderator_privileges], []) - refute user in User.all_users_with_privilege(:cofe) - refute admin_user in User.all_users_with_privilege(:cofe) - refute moderator_user in User.all_users_with_privilege(:cofe) - refute admin_moderator_user in User.all_users_with_privilege(:cofe) - refute remote_user in User.all_users_with_privilege(:cofe) - refute non_active_user in User.all_users_with_privilege(:cofe) + assert [] = User.Query.build(%{is_privileged: :cofe}) |> Repo.all() end test "returns moderator users if they are privileged", %{ - user: user, moderator_user: moderator_user, - admin_user: admin_user, - admin_moderator_user: admin_moderator_user, - remote_user: remote_user, - non_active_user: non_active_user + admin_moderator_user: admin_moderator_user } do clear_config([:instance, :admin_privileges], []) clear_config([:instance, :moderator_privileges], [:cofe]) - refute user in User.all_users_with_privilege(:cofe) - refute admin_user in User.all_users_with_privilege(:cofe) + assert [_, _] = User.Query.build(%{is_privileged: :cofe}) |> Repo.all() assert moderator_user in User.all_users_with_privilege(:cofe) assert admin_moderator_user in User.all_users_with_privilege(:cofe) - refute remote_user in User.all_users_with_privilege(:cofe) - refute non_active_user in User.all_users_with_privilege(:cofe) end test "returns admin users if they are privileged", %{ - user: user, - moderator_user: moderator_user, admin_user: admin_user, - admin_moderator_user: admin_moderator_user, - remote_user: remote_user, - non_active_user: non_active_user + admin_moderator_user: admin_moderator_user } do clear_config([:instance, :admin_privileges], [:cofe]) clear_config([:instance, :moderator_privileges], []) - refute user in User.all_users_with_privilege(:cofe) + assert [_, _] = User.Query.build(%{is_privileged: :cofe}) |> Repo.all() assert admin_user in User.all_users_with_privilege(:cofe) - refute moderator_user in User.all_users_with_privilege(:cofe) assert admin_moderator_user in User.all_users_with_privilege(:cofe) - refute remote_user in User.all_users_with_privilege(:cofe) - refute non_active_user in User.all_users_with_privilege(:cofe) end test "returns admin and moderator users if they are both privileged", %{ - user: user, moderator_user: moderator_user, admin_user: admin_user, - admin_moderator_user: admin_moderator_user, - remote_user: remote_user, - non_active_user: non_active_user + admin_moderator_user: admin_moderator_user } do clear_config([:instance, :admin_privileges], [:cofe]) clear_config([:instance, :moderator_privileges], [:cofe]) - refute user in User.all_users_with_privilege(:cofe) + assert [_, _, _] = User.Query.build(%{is_privileged: :cofe}) |> Repo.all() assert admin_user in User.all_users_with_privilege(:cofe) assert moderator_user in User.all_users_with_privilege(:cofe) assert admin_moderator_user in User.all_users_with_privilege(:cofe) - refute remote_user in User.all_users_with_privilege(:cofe) - refute non_active_user in User.all_users_with_privilege(:cofe) end end