From f3f52101b204def37645016bab7d4e1dea80d5c0 Mon Sep 17 00:00:00 2001 From: Josh Smith Date: Thu, 30 Mar 2017 17:14:53 -0700 Subject: [PATCH] Fixes 445 with assert-id helper change --- test/controllers/category_controller_test.exs | 3 +-- test/controllers/comment_controller_test.exs | 3 +-- test/controllers/donation_goal_controller_test.exs | 3 +-- test/controllers/organization_controller_test.exs | 3 +-- test/controllers/project_category_controller_test.exs | 3 +-- test/controllers/project_controller_test.exs | 6 ++---- test/controllers/project_skill_controller_test.exs | 3 +-- test/controllers/project_user_controller_test.exs | 3 +-- test/controllers/role_skill_controller_test.exs | 3 +-- test/controllers/skill_controller_test.exs | 3 +-- test/controllers/slugged_route_controller_test.exs | 3 +-- .../stripe_connect_account_controller_test.exs | 3 +-- .../stripe_connect_plan_controller_test.exs | 3 +-- .../stripe_platform_card_controller_test.exs | 3 +-- .../stripe_platform_customer_controller_test.exs | 3 +-- test/controllers/task_controller_test.exs | 9 ++++----- test/controllers/task_list_controller_test.exs | 9 ++++----- test/controllers/task_skill_controller_test.exs | 3 +-- test/controllers/user_category_controller_test.exs | 3 +-- test/controllers/user_controller_test.exs | 3 +-- test/controllers/user_role_controller_test.exs | 3 +-- test/controllers/user_skill_controller_test.exs | 3 +-- test/controllers/user_task_controller_test.exs | 3 +-- test/support/test_helpers.ex | 10 +++++----- 24 files changed, 35 insertions(+), 59 deletions(-) diff --git a/test/controllers/category_controller_test.exs b/test/controllers/category_controller_test.exs index a55f07c91..eb39b1fa8 100644 --- a/test/controllers/category_controller_test.exs +++ b/test/controllers/category_controller_test.exs @@ -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 diff --git a/test/controllers/comment_controller_test.exs b/test/controllers/comment_controller_test.exs index abf975d20..71f36c7f4 100644 --- a/test/controllers/comment_controller_test.exs +++ b/test/controllers/comment_controller_test.exs @@ -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 diff --git a/test/controllers/donation_goal_controller_test.exs b/test/controllers/donation_goal_controller_test.exs index 6f30c002b..0c5b86678 100644 --- a/test/controllers/donation_goal_controller_test.exs +++ b/test/controllers/donation_goal_controller_test.exs @@ -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 diff --git a/test/controllers/organization_controller_test.exs b/test/controllers/organization_controller_test.exs index 0237e7a1d..9842a9968 100644 --- a/test/controllers/organization_controller_test.exs +++ b/test/controllers/organization_controller_test.exs @@ -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 diff --git a/test/controllers/project_category_controller_test.exs b/test/controllers/project_category_controller_test.exs index 0bf8477dd..aa45ee5d8 100644 --- a/test/controllers/project_category_controller_test.exs +++ b/test/controllers/project_category_controller_test.exs @@ -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 diff --git a/test/controllers/project_controller_test.exs b/test/controllers/project_controller_test.exs index 4877a564b..2362e184e 100644 --- a/test/controllers/project_controller_test.exs +++ b/test/controllers/project_controller_test.exs @@ -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 @@ -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 diff --git a/test/controllers/project_skill_controller_test.exs b/test/controllers/project_skill_controller_test.exs index 58b2f3fdb..0ae335804 100644 --- a/test/controllers/project_skill_controller_test.exs +++ b/test/controllers/project_skill_controller_test.exs @@ -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 diff --git a/test/controllers/project_user_controller_test.exs b/test/controllers/project_user_controller_test.exs index 9741090c9..aab0f51fc 100644 --- a/test/controllers/project_user_controller_test.exs +++ b/test/controllers/project_user_controller_test.exs @@ -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 diff --git a/test/controllers/role_skill_controller_test.exs b/test/controllers/role_skill_controller_test.exs index 4818dbac7..72d3be220 100644 --- a/test/controllers/role_skill_controller_test.exs +++ b/test/controllers/role_skill_controller_test.exs @@ -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 diff --git a/test/controllers/skill_controller_test.exs b/test/controllers/skill_controller_test.exs index 4c93688fa..73455003c 100644 --- a/test/controllers/skill_controller_test.exs +++ b/test/controllers/skill_controller_test.exs @@ -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 diff --git a/test/controllers/slugged_route_controller_test.exs b/test/controllers/slugged_route_controller_test.exs index bc8a8a79c..d9eb9cce8 100644 --- a/test/controllers/slugged_route_controller_test.exs +++ b/test/controllers/slugged_route_controller_test.exs @@ -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 diff --git a/test/controllers/stripe_connect_account_controller_test.exs b/test/controllers/stripe_connect_account_controller_test.exs index 6e8f32708..e22b1d026 100644 --- a/test/controllers/stripe_connect_account_controller_test.exs +++ b/test/controllers/stripe_connect_account_controller_test.exs @@ -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 diff --git a/test/controllers/stripe_connect_plan_controller_test.exs b/test/controllers/stripe_connect_plan_controller_test.exs index 198bcd077..416f42461 100644 --- a/test/controllers/stripe_connect_plan_controller_test.exs +++ b/test/controllers/stripe_connect_plan_controller_test.exs @@ -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 diff --git a/test/controllers/stripe_platform_card_controller_test.exs b/test/controllers/stripe_platform_card_controller_test.exs index 09a44217c..68707f6b3 100644 --- a/test/controllers/stripe_platform_card_controller_test.exs +++ b/test/controllers/stripe_platform_card_controller_test.exs @@ -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 diff --git a/test/controllers/stripe_platform_customer_controller_test.exs b/test/controllers/stripe_platform_customer_controller_test.exs index 800f2b2a3..4154c23b7 100644 --- a/test/controllers/stripe_platform_customer_controller_test.exs +++ b/test/controllers/stripe_platform_customer_controller_test.exs @@ -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 diff --git a/test/controllers/task_controller_test.exs b/test/controllers/task_controller_test.exs index 3f16fafd8..7930c80eb 100644 --- a/test/controllers/task_controller_test.exs +++ b/test/controllers/task_controller_test.exs @@ -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 diff --git a/test/controllers/task_list_controller_test.exs b/test/controllers/task_list_controller_test.exs index 49b437ec7..a66d7114f 100644 --- a/test/controllers/task_list_controller_test.exs +++ b/test/controllers/task_list_controller_test.exs @@ -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 diff --git a/test/controllers/task_skill_controller_test.exs b/test/controllers/task_skill_controller_test.exs index 72220878d..b045f2556 100644 --- a/test/controllers/task_skill_controller_test.exs +++ b/test/controllers/task_skill_controller_test.exs @@ -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 diff --git a/test/controllers/user_category_controller_test.exs b/test/controllers/user_category_controller_test.exs index 0db71b96a..52dde71eb 100644 --- a/test/controllers/user_category_controller_test.exs +++ b/test/controllers/user_category_controller_test.exs @@ -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 diff --git a/test/controllers/user_controller_test.exs b/test/controllers/user_controller_test.exs index da7f70e6e..ee2205eb8 100644 --- a/test/controllers/user_controller_test.exs +++ b/test/controllers/user_controller_test.exs @@ -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 diff --git a/test/controllers/user_role_controller_test.exs b/test/controllers/user_role_controller_test.exs index 72d2c2095..e3e1d64e7 100644 --- a/test/controllers/user_role_controller_test.exs +++ b/test/controllers/user_role_controller_test.exs @@ -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 diff --git a/test/controllers/user_skill_controller_test.exs b/test/controllers/user_skill_controller_test.exs index ea7ac0efc..6c9eb0a9b 100644 --- a/test/controllers/user_skill_controller_test.exs +++ b/test/controllers/user_skill_controller_test.exs @@ -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 diff --git a/test/controllers/user_task_controller_test.exs b/test/controllers/user_task_controller_test.exs index 5042c8d1a..bd7dc3e22 100644 --- a/test/controllers/user_task_controller_test.exs +++ b/test/controllers/user_task_controller_test.exs @@ -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 diff --git a/test/support/test_helpers.ex b/test/support/test_helpers.ex index a263a2919..d203853e9 100644 --- a/test/support/test_helpers.ex +++ b/test/support/test_helpers.ex @@ -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 @@ -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])