Skip to content

Commit

Permalink
create test/auth/people_roles_test.exs to test both happy path and 40…
Browse files Browse the repository at this point in the history
…1 for #90 & #27 #31 #82
  • Loading branch information
nelsonic committed Aug 20, 2020
1 parent 506d365 commit 1d6a259
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
27 changes: 27 additions & 0 deletions test/auth/people_roles_test.exs
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
15 changes: 1 addition & 14 deletions test/auth_web/controllers/role_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 1d6a259

Please sign in to comment.