-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create test/auth/people_roles_test.exs to test both happy path and 40…
- Loading branch information
Showing
2 changed files
with
28 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
defmodule AuthWeb.PeopleRolesTest do | ||
use AuthWeb.ConnCase | ||
|
||
test "grant_role/3 happy path", %{conn: conn} do | ||
# login as superadmin | ||
conn = AuthTest.admin_login(conn) | ||
# create a new person | ||
alex = %{email: "[email protected]", auth_provider: "email"} | ||
grantee = Auth.Person.create_person(alex) | ||
role_id = 4 | ||
Auth.PeopleRoles.grant_role(conn, grantee.id, role_id) | ||
person_with_role = Auth.Person.get_person_by_id(grantee.id) | ||
role = List.first(person_with_role.roles) | ||
assert role_id == role.id | ||
end | ||
|
||
test "attempt to grant_role/3 without admin should 401", %{conn: conn} do | ||
alex = %{email: "[email protected]", auth_provider: "email"} | ||
grantee = Auth.Person.create_person(alex) | ||
conn = assign(conn, :person, grantee) # | ||
role_id = 4 | ||
conn = Auth.PeopleRoles.grant_role(conn, grantee.id, role_id) | ||
|
||
assert conn.status == 401 | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,18 +91,5 @@ defmodule AuthWeb.RoleControllerTest do | |
role = fixture(:role) | ||
%{role: role} | ||
end | ||
|
||
|
||
test "grant_role/3 happy path", %{conn: conn} do | ||
# login as superadmin | ||
conn = AuthTest.admin_login(conn) | ||
# create a new person | ||
alex = %{email: "[email protected]", auth_provider: "email"} | ||
grantee = Auth.Person.create_person(alex) | ||
role_id = 4 | ||
Auth.PeopleRoles.grant_role(conn, grantee.id, role_id) | ||
person_with_role = Auth.Person.get_person_by_id(grantee.id) | ||
role = List.first(person_with_role.roles) | ||
assert role_id == role.id | ||
end | ||
|
||
end |