Skip to content

Commit

Permalink
Merge pull request #780 from code-corps/445-assert-id-helper
Browse files Browse the repository at this point in the history
Fixes 445 with assert-id helper change
  • Loading branch information
joshsmith authored Mar 31, 2017
2 parents 09693c5 + f3f5210 commit 124bd7b
Show file tree
Hide file tree
Showing 24 changed files with 35 additions and 59 deletions.
3 changes: 1 addition & 2 deletions test/controllers/category_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ defmodule CodeCorps.CategoryControllerTest do
conn
|> request_show(category)
|> json_response(200)
|> Map.get("data")
|> assert_result_id(category.id)
|> assert_id_from_response(category.id)
end

test "renders 404 when id is nonexistent", %{conn: conn} do
Expand Down
3 changes: 1 addition & 2 deletions test/controllers/comment_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ defmodule CodeCorps.CommentControllerTest do
conn
|> request_show(comment)
|> json_response(200)
|> Map.get("data")
|> assert_result_id(comment.id)
|> assert_id_from_response(comment.id)
end

test "renders 404 when id is nonexistent", %{conn: conn} do
Expand Down
3 changes: 1 addition & 2 deletions test/controllers/donation_goal_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ defmodule CodeCorps.DonationGoalControllerTest do
conn
|> request_show(donation_goal)
|> json_response(200)
|> Map.get("data")
|> assert_result_id(donation_goal.id)
|> assert_id_from_response(donation_goal.id)
end

test "renders 404 when id is nonexistent", %{conn: conn} do
Expand Down
3 changes: 1 addition & 2 deletions test/controllers/organization_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ defmodule CodeCorps.OrganizationControllerTest do
conn
|> request_show(organization)
|> json_response(200)
|> Map.get("data")
|> assert_result_id(organization.id)
|> assert_id_from_response(organization.id)
end

test "renders 404 when id is nonexistent", %{conn: conn} do
Expand Down
3 changes: 1 addition & 2 deletions test/controllers/project_category_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ defmodule CodeCorps.ProjectCategoryControllerTest do
conn
|> request_show(project_category)
|> json_response(200)
|> Map.get("data")
|> assert_result_id(project_category.id)
|> assert_id_from_response(project_category.id)
end

test "renders 404 when id is nonexistent", %{conn: conn} do
Expand Down
6 changes: 2 additions & 4 deletions test/controllers/project_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ defmodule CodeCorps.ProjectControllerTest do
conn
|> request_show(project)
|> json_response(200)
|> Map.get("data")
|> assert_result_id(project.id)
|> assert_id_from_response(project.id)
end

test "shows chosen resource retrieved by slug", %{conn: conn} do
Expand All @@ -57,8 +56,7 @@ defmodule CodeCorps.ProjectControllerTest do
conn
|> get(path)
|> json_response(200)
|> Map.get("data")
|> assert_result_id(project.id)
|> assert_id_from_response(project.id)
end

test "retrieval by slug is case insensitive", %{conn: conn} do
Expand Down
3 changes: 1 addition & 2 deletions test/controllers/project_skill_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ defmodule CodeCorps.ProjectSkillControllerTest do
conn
|> request_show(project_skill)
|> json_response(200)
|> Map.get("data")
|> assert_result_id(project_skill.id)
|> assert_id_from_response(project_skill.id)
end

test "renders 404 error when id is nonexistent", %{conn: conn} do
Expand Down
3 changes: 1 addition & 2 deletions test/controllers/project_user_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ defmodule CodeCorps.ProjectUserControllerTest do
conn
|> request_show(record)
|> json_response(200)
|> Map.get("data")
|> assert_result_id(record.id)
|> assert_id_from_response(record.id)
end

test "renders 404 when id is nonexistent", %{conn: conn} do
Expand Down
3 changes: 1 addition & 2 deletions test/controllers/role_skill_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ defmodule CodeCorps.RoleSkillControllerTest do
conn
|> request_show(role_skill)
|> json_response(200)
|> Map.get("data")
|> assert_result_id(role_skill.id)
|> assert_id_from_response(role_skill.id)
end

test "renders 404", %{conn: conn} do
Expand Down
3 changes: 1 addition & 2 deletions test/controllers/skill_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ defmodule CodeCorps.SkillControllerTest do
conn
|> request_show(skill)
|> json_response(200)
|> Map.get("data")
|> assert_result_id(skill.id)
|> assert_id_from_response(skill.id)
end

test "renders 404 when id is nonexistent", %{conn: conn} do
Expand Down
3 changes: 1 addition & 2 deletions test/controllers/slugged_route_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ defmodule CodeCorps.SluggedRouteControllerTest do
conn
|> get("/#{slug}")
|> json_response(200)
|> Map.get("data")
|> assert_result_id(slugged_route.id)
|> assert_id_from_response(slugged_route.id)
end

test "is case insensitive", %{conn: conn} do
Expand Down
3 changes: 1 addition & 2 deletions test/controllers/stripe_connect_account_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ defmodule CodeCorps.StripeConnectAccountControllerTest do
conn
|> request_show(stripe_connect_account)
|> json_response(200)
|> Map.get("data")
|> assert_result_id(stripe_connect_account.id)
|> assert_id_from_response(stripe_connect_account.id)
end

test "renders 401 when unauthenticated", %{conn: conn} do
Expand Down
3 changes: 1 addition & 2 deletions test/controllers/stripe_connect_plan_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ defmodule CodeCorps.StripeConnectPlanControllerTest do
conn
|> request_show(stripe_connect_plan)
|> json_response(200)
|> Map.get("data")
|> assert_result_id(stripe_connect_plan.id)
|> assert_id_from_response(stripe_connect_plan.id)
end

test "renders 401 when unauthenticated", %{conn: conn} do
Expand Down
3 changes: 1 addition & 2 deletions test/controllers/stripe_platform_card_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ defmodule CodeCorps.StripePlatformCardControllerTest do
conn
|> request_show(stripe_platform_card)
|> json_response(200)
|> Map.get("data")
|> assert_result_id(stripe_platform_card.id)
|> assert_id_from_response(stripe_platform_card.id)
end

test "renders 401 when unauthenticated", %{conn: conn} do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ defmodule CodeCorps.StripePlatformCustomerControllerTest do
conn
|> request_show(stripe_platform_customer)
|> json_response(200)
|> Map.get("data")
|> assert_result_id(stripe_platform_customer.id)
|> assert_id_from_response(stripe_platform_customer.id)
end

test "renders 401 when unauthenticated", %{conn: conn} do
Expand Down
9 changes: 4 additions & 5 deletions test/controllers/task_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,17 @@ defmodule CodeCorps.TaskControllerTest do
conn
|> request_show(task)
|> json_response(200)
|> Map.get("data")
|> assert_result_id(task.id)
|> assert_id_from_response(task.id)
end

test "shows task by number for project", %{conn: conn} do
task = insert(:task)

path = conn |> project_task_path(:show, task.project_id, task.number)
data = conn |> get(path) |> json_response(200) |> Map.get("data")
data = conn |> get(path) |> json_response(200)

assert data["id"] == "#{task.id}"
assert data["type"] == "task"
assert data["data"]["id"] == "#{task.id}"
assert data["data"]["type"] == "task"
end

test "renders 404 when id is nonexistent", %{conn: conn} do
Expand Down
9 changes: 4 additions & 5 deletions test/controllers/task_list_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,17 @@ defmodule CodeCorps.TaskListControllerTest do
conn
|> request_show(task_list)
|> json_response(200)
|> Map.get("data")
|> assert_result_id(task_list.id)
|> assert_id_from_response(task_list.id)
end

test "shows task list by id for project", %{conn: conn} do
task_list = insert(:task_list)

path = conn |> project_task_list_path(:show, task_list.project_id, task_list.id)
data = conn |> get(path) |> json_response(200) |> Map.get("data")
data = conn |> get(path) |> json_response(200)

assert data["id"] == "#{task_list.id}"
assert data["type"] == "task-list"
assert data["data"]["id"] == "#{task_list.id}"
assert data["data"]["type"] == "task-list"
end

test "renders 404 when id is nonexistent", %{conn: conn} do
Expand Down
3 changes: 1 addition & 2 deletions test/controllers/task_skill_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ defmodule CodeCorps.TaskSkillControllerTest do
conn
|> request_show(task_skill)
|> json_response(200)
|> Map.get("data")
|> assert_result_id(task_skill.id)
|> assert_id_from_response(task_skill.id)
end

test "renders 404 error when id is nonexistent", %{conn: conn} do
Expand Down
3 changes: 1 addition & 2 deletions test/controllers/user_category_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ defmodule CodeCorps.UserCategoryControllerTest do
conn
|> request_show(user_category)
|> json_response(200)
|> Map.get("data")
|> assert_result_id(user_category.id)
|> assert_id_from_response(user_category.id)
end

test "renders 404 when id is nonexistent", %{conn: conn} do
Expand Down
3 changes: 1 addition & 2 deletions test/controllers/user_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ defmodule CodeCorps.UserControllerTest do
conn
|> request_show(user)
|> json_response(200)
|> Map.get("data")
|> assert_result_id(user.id)
|> assert_id_from_response(user.id)
end

@tag :authenticated
Expand Down
3 changes: 1 addition & 2 deletions test/controllers/user_role_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ defmodule CodeCorps.UserRoleControllerTest do
conn
|> request_show(user_role)
|> json_response(200)
|> Map.get("data")
|> assert_result_id(user_role.id)
|> assert_id_from_response(user_role.id)
end

test "renders 404 when id is nonexistent", %{conn: conn} do
Expand Down
3 changes: 1 addition & 2 deletions test/controllers/user_skill_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ defmodule CodeCorps.UserSkillControllerTest do
conn
|> request_show(user_skill)
|> json_response(200)
|> Map.get("data")
|> assert_result_id(user_skill.id)
|> assert_id_from_response(user_skill.id)
end

test "renders 404 error when id is nonexistent", %{conn: conn} do
Expand Down
3 changes: 1 addition & 2 deletions test/controllers/user_task_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ defmodule CodeCorps.UserTaskControllerTest do
conn
|> request_show(user_task)
|> json_response(200)
|> Map.get("data")
|> assert_result_id(user_task.id)
|> assert_id_from_response(user_task.id)
end

test "renders 404 error when id is nonexistent", %{conn: conn} do
Expand Down
10 changes: 5 additions & 5 deletions test/support/test_helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ defmodule CodeCorps.TestHelpers do
end
end

def assert_id_from_response(response, id) do
assert String.to_integer(response["data"]["id"]) == id
response
end

def assert_ids_from_response(response, ids) do
assert ids_from_response(response) == ids
response
Expand All @@ -28,11 +33,6 @@ defmodule CodeCorps.TestHelpers do
json
end

def assert_result_id(result, id) do
assert String.to_integer(result["id"]) == id
result
end

def put_id(payload, id), do: put_in(payload, ["data", "id"], id)
def put_attributes(payload, attributes), do: put_in(payload, ["data", "attributes"], attributes)
def put_relationships(payload, record_1, record_2), do: put_relationships(payload, [record_1, record_2])
Expand Down

0 comments on commit 124bd7b

Please sign in to comment.