Commit 9239b148 authored by Mikko Ahlroth's avatar Mikko Ahlroth

Add tests for permission utils

parent 14adf7be
......@@ -9,6 +9,20 @@ defmodule CodeStats.Profile.PermissionUtils do
Can the given user access the target's profile? They can if the profile is public or
if they are the same user as the target user. Use nil as user to signify unauthenticated
users.
## Examples
iex> CodeStats.Profile.PermissionUtils.can_access_profile?(nil, %CodeStats.User{private_profile: true})
false
iex> CodeStats.Profile.PermissionUtils.can_access_profile?(nil, %CodeStats.User{private_profile: false})
true
iex> CodeStats.Profile.PermissionUtils.can_access_profile?(%CodeStats.User{id: 1}, %CodeStats.User{id: 2, private_profile: true})
false
iex> CodeStats.Profile.PermissionUtils.can_access_profile?(%CodeStats.User{id: 1}, %CodeStats.User{id: 1, private_profile: true})
true
"""
@spec can_access_profile?(%User{} | nil, %User{}) :: boolean
def can_access_profile?(user, target) do
......
defmodule CodeStats.Profile.PermissionUtilsTest do
use ExUnit.Case, async: true
doctest CodeStats.Profile.PermissionUtils
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment