2020-01-23 00:55:07 +01:00
|
|
|
defmodule Mobilizon.Users.GuardsTest do
|
2019-03-06 18:45:26 +01:00
|
|
|
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
|