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 @@ test "is_suggested param" 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

View file

@ -2023,80 +2023,49 @@ test "returns true when the account is unconfirmed and being viewed by a privile
}
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