Improve tests after code review

This commit is contained in:
Ilja 2022-07-05 08:57:50 +02:00
parent 42d4bd3a5d
commit 6ef38c6523
2 changed files with 16 additions and 78 deletions

View file

@ -58,80 +58,49 @@ defmodule Pleroma.User.QueryTest do
} }
end end
test "doesn't return any users when there are no privileged roles", %{ test "doesn't return any users when there are no privileged roles" do
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
clear_config([:instance, :admin_privileges], []) clear_config([:instance, :admin_privileges], [])
clear_config([:instance, :moderator_privileges], []) 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()
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())
end end
test "returns moderator users if they are privileged", %{ test "returns moderator users if they are privileged", %{
user: user,
moderator_user: moderator_user, moderator_user: moderator_user,
admin_user: admin_user, admin_moderator_user: admin_moderator_user
admin_moderator_user: admin_moderator_user,
remote_user: remote_user,
non_active_user: non_active_user
} do } do
clear_config([:instance, :admin_privileges], []) clear_config([:instance, :admin_privileges], [])
clear_config([:instance, :moderator_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()
refute admin_user in (User.Query.build(%{is_privileged: :cofe}) |> Repo.all())
assert moderator_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()) 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
test "returns admin users if they are privileged", %{ test "returns admin users if they are privileged", %{
user: user,
moderator_user: moderator_user,
admin_user: admin_user, admin_user: admin_user,
admin_moderator_user: admin_moderator_user, admin_moderator_user: admin_moderator_user
remote_user: remote_user,
non_active_user: non_active_user
} do } do
clear_config([:instance, :admin_privileges], [:cofe]) clear_config([:instance, :admin_privileges], [:cofe])
clear_config([:instance, :moderator_privileges], []) 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()) 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()) 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
test "returns admin and moderator users if they are both privileged", %{ test "returns admin and moderator users if they are both privileged", %{
user: user,
moderator_user: moderator_user, moderator_user: moderator_user,
admin_user: admin_user, admin_user: admin_user,
admin_moderator_user: admin_moderator_user, admin_moderator_user: admin_moderator_user
remote_user: remote_user,
non_active_user: non_active_user
} do } do
clear_config([:instance, :admin_privileges], [:cofe]) clear_config([:instance, :admin_privileges], [:cofe])
clear_config([:instance, :moderator_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 admin_user in (User.Query.build(%{is_privileged: :cofe}) |> Repo.all())
assert moderator_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()) 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 end
end end

View file

@ -2023,80 +2023,49 @@ defmodule Pleroma.UserTest do
} }
end end
test "doesn't return any users when there are no privileged roles", %{ test "doesn't return any users when there are no privileged roles" do
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
clear_config([:instance, :admin_privileges], []) clear_config([:instance, :admin_privileges], [])
clear_config([:instance, :moderator_privileges], []) clear_config([:instance, :moderator_privileges], [])
refute user in User.all_users_with_privilege(:cofe) assert [] = User.Query.build(%{is_privileged: :cofe}) |> Repo.all()
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)
end end
test "returns moderator users if they are privileged", %{ test "returns moderator users if they are privileged", %{
user: user,
moderator_user: moderator_user, moderator_user: moderator_user,
admin_user: admin_user, admin_moderator_user: admin_moderator_user
admin_moderator_user: admin_moderator_user,
remote_user: remote_user,
non_active_user: non_active_user
} do } do
clear_config([:instance, :admin_privileges], []) clear_config([:instance, :admin_privileges], [])
clear_config([:instance, :moderator_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()
refute admin_user in User.all_users_with_privilege(:cofe)
assert moderator_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) 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
test "returns admin users if they are privileged", %{ test "returns admin users if they are privileged", %{
user: user,
moderator_user: moderator_user,
admin_user: admin_user, admin_user: admin_user,
admin_moderator_user: admin_moderator_user, admin_moderator_user: admin_moderator_user
remote_user: remote_user,
non_active_user: non_active_user
} do } do
clear_config([:instance, :admin_privileges], [:cofe]) clear_config([:instance, :admin_privileges], [:cofe])
clear_config([:instance, :moderator_privileges], []) 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) 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) 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
test "returns admin and moderator users if they are both privileged", %{ test "returns admin and moderator users if they are both privileged", %{
user: user,
moderator_user: moderator_user, moderator_user: moderator_user,
admin_user: admin_user, admin_user: admin_user,
admin_moderator_user: admin_moderator_user, admin_moderator_user: admin_moderator_user
remote_user: remote_user,
non_active_user: non_active_user
} do } do
clear_config([:instance, :admin_privileges], [:cofe]) clear_config([:instance, :admin_privileges], [:cofe])
clear_config([:instance, :moderator_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 admin_user in User.all_users_with_privilege(:cofe)
assert moderator_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) 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
end end