mobilizon.chapril.org-mobil.../test/mobilizon/users/service/tools.exs
Thomas Citharel cb0808dbad
Introduce admin and moderator role, check role on list_users action
Signed-off-by: Thomas Citharel <tcit@tcit.fr>

Add test for guards
2019-03-07 14:18:11 +01:00

29 lines
850 B
Elixir

defmodule Mobilizon.Users.Service.ToolsTest do
use Mobilizon.DataCase
import Mobilizon.Factory
setup do
user = insert(:user)
moderator = insert(:user, role: :moderator)
administrator = insert(:user, role: :administrator)
{:ok, user: user, moderator: moderator, administrator: administrator}
end
describe "test guards" do
import Mobilizon.Users.Guards
test "is_moderator/1 guard", %{user: user, moderator: moderator, administrator: administrator} do
refute is_moderator(user.role)
assert is_moderator(moderator.role)
assert is_moderator(administrator.role)
end
test "is_admin/1 guard", %{user: user, moderator: moderator, administrator: administrator} do
refute is_admin(user.role)
refute is_admin(moderator.role)
assert is_admin(administrator.role)
end
end
end