Skip to content

Commit

Permalink
add test for find clinician route of team member controller #1 #6
Browse files Browse the repository at this point in the history
  • Loading branch information
RobStallion committed Jul 29, 2017
1 parent d1d142b commit 4adcfe0
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/epjs_app/clinician_connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule EpjsApp.ClinicianConnection do
import Ecto.Query
alias EpjsApp.{EPJSUser, EPJSTeamMember, Repo, DecryptUser}

def find_clinician(%{"user_data" => user_data}) do
def find_clinician(user_data) do
[decrypted_user_guid, decrypted_time_str] = DecryptUser.decrypt_user_data(user_data)
query = from etm in EPJSTeamMember, where: etm."User_Guid" == ^decrypted_user_guid

Expand Down
41 changes: 41 additions & 0 deletions test/controllers/team_member_controller_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
defmodule EpjsApp.TeamMemberControllerTest do
use EpjsApp.ConnCase
alias EpjsApp.{EPJSTeamMember, Repo}

describe "team member controller returns json response with valid user data" do
setup %{} do
Repo.insert!(%EPJSTeamMember{
Patient_ID: 123,
Staff_ID: 321,
Staff_Name: "rob stallion",
Job_Title: "clinician",
Team_Member_Role_Desc: "care team lead",
Email: "[email protected]",
User_Guid: "randomstringtotestwith"
})

:ok
end

test "GET /epjsteammember/clinician-connection/find-clinician?user_data=", %{conn: conn} do
user_data = "[email protected]&UserId=randomstringtotestwith&tokenexpiry=3000-06-23T11:15:53"
conn = get conn, "http://localhost:4001/epjsteammember/clinician-connection/find-clinician?user_data=" <> user_data
clinician = conn.resp_body
|> Poison.decode!
|> Map.get("clinician")
|> Enum.at(0)
assert clinician["Staff_ID"] == 321
end
end

describe "team member controller returns empty clinician list with invalid user_data" do
test "GET /epjsteammember/clinician-connection/find-clinician?user_data=", %{conn: conn} do
user_data = "[email protected]&UserId=randomstringtotestwith&tokenexpiry=3000-06-23T11:15:53"
conn = get conn, "http://localhost:4001/epjsteammember/clinician-connection/find-clinician?user_data=" <> user_data
assert conn.resp_body == "{\"decrypted_user_guid\":\"randomstringtotestwith\",\"decrypted_time_str\":\"3000-06-23T11:15:53\",\"clinician\":[]}"
assert conn.resp_body
|> Poison.decode!
|> Map.get("clinician") == []
end
end
end
1 change: 0 additions & 1 deletion web/controllers/team_member_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ defmodule EpjsApp.TeamMemberController do

def find_clinician(conn, %{"user_data" => user_data}) do
decrypted_user_data = user_data
|> Poison.decode
|> ClinicianConnection.find_clinician

json conn, decrypted_user_data
Expand Down

0 comments on commit 4adcfe0

Please sign in to comment.