Skip to content

Commit 124bd7b

Browse files
authored
Merge pull request #780 from code-corps/445-assert-id-helper
Fixes 445 with assert-id helper change
2 parents 09693c5 + f3f5210 commit 124bd7b

24 files changed

+35
-59
lines changed

test/controllers/category_controller_test.exs

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ defmodule CodeCorps.CategoryControllerTest do
2222
conn
2323
|> request_show(category)
2424
|> json_response(200)
25-
|> Map.get("data")
26-
|> assert_result_id(category.id)
25+
|> assert_id_from_response(category.id)
2726
end
2827

2928
test "renders 404 when id is nonexistent", %{conn: conn} do

test/controllers/comment_controller_test.exs

+1-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ defmodule CodeCorps.CommentControllerTest do
3232
conn
3333
|> request_show(comment)
3434
|> json_response(200)
35-
|> Map.get("data")
36-
|> assert_result_id(comment.id)
35+
|> assert_id_from_response(comment.id)
3736
end
3837

3938
test "renders 404 when id is nonexistent", %{conn: conn} do

test/controllers/donation_goal_controller_test.exs

+1-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ defmodule CodeCorps.DonationGoalControllerTest do
3232
conn
3333
|> request_show(donation_goal)
3434
|> json_response(200)
35-
|> Map.get("data")
36-
|> assert_result_id(donation_goal.id)
35+
|> assert_id_from_response(donation_goal.id)
3736
end
3837

3938
test "renders 404 when id is nonexistent", %{conn: conn} do

test/controllers/organization_controller_test.exs

+1-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ defmodule CodeCorps.OrganizationControllerTest do
3333
conn
3434
|> request_show(organization)
3535
|> json_response(200)
36-
|> Map.get("data")
37-
|> assert_result_id(organization.id)
36+
|> assert_id_from_response(organization.id)
3837
end
3938

4039
test "renders 404 when id is nonexistent", %{conn: conn} do

test/controllers/project_category_controller_test.exs

+1-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ defmodule CodeCorps.ProjectCategoryControllerTest do
3232
conn
3333
|> request_show(project_category)
3434
|> json_response(200)
35-
|> Map.get("data")
36-
|> assert_result_id(project_category.id)
35+
|> assert_id_from_response(project_category.id)
3736
end
3837

3938
test "renders 404 when id is nonexistent", %{conn: conn} do

test/controllers/project_controller_test.exs

+2-4
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ defmodule CodeCorps.ProjectControllerTest do
4444
conn
4545
|> request_show(project)
4646
|> json_response(200)
47-
|> Map.get("data")
48-
|> assert_result_id(project.id)
47+
|> assert_id_from_response(project.id)
4948
end
5049

5150
test "shows chosen resource retrieved by slug", %{conn: conn} do
@@ -57,8 +56,7 @@ defmodule CodeCorps.ProjectControllerTest do
5756
conn
5857
|> get(path)
5958
|> json_response(200)
60-
|> Map.get("data")
61-
|> assert_result_id(project.id)
59+
|> assert_id_from_response(project.id)
6260
end
6361

6462
test "retrieval by slug is case insensitive", %{conn: conn} do

test/controllers/project_skill_controller_test.exs

+1-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ defmodule CodeCorps.ProjectSkillControllerTest do
3232
conn
3333
|> request_show(project_skill)
3434
|> json_response(200)
35-
|> Map.get("data")
36-
|> assert_result_id(project_skill.id)
35+
|> assert_id_from_response(project_skill.id)
3736
end
3837

3938
test "renders 404 error when id is nonexistent", %{conn: conn} do

test/controllers/project_user_controller_test.exs

+1-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ defmodule CodeCorps.ProjectUserControllerTest do
3232
conn
3333
|> request_show(record)
3434
|> json_response(200)
35-
|> Map.get("data")
36-
|> assert_result_id(record.id)
35+
|> assert_id_from_response(record.id)
3736
end
3837

3938
test "renders 404 when id is nonexistent", %{conn: conn} do

test/controllers/role_skill_controller_test.exs

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ defmodule CodeCorps.RoleSkillControllerTest do
3030
conn
3131
|> request_show(role_skill)
3232
|> json_response(200)
33-
|> Map.get("data")
34-
|> assert_result_id(role_skill.id)
33+
|> assert_id_from_response(role_skill.id)
3534
end
3635

3736
test "renders 404", %{conn: conn} do

test/controllers/skill_controller_test.exs

+1-2
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ defmodule CodeCorps.SkillControllerTest do
6161
conn
6262
|> request_show(skill)
6363
|> json_response(200)
64-
|> Map.get("data")
65-
|> assert_result_id(skill.id)
64+
|> assert_id_from_response(skill.id)
6665
end
6766

6867
test "renders 404 when id is nonexistent", %{conn: conn} do

test/controllers/slugged_route_controller_test.exs

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ defmodule CodeCorps.SluggedRouteControllerTest do
77
conn
88
|> get("/#{slug}")
99
|> json_response(200)
10-
|> Map.get("data")
11-
|> assert_result_id(slugged_route.id)
10+
|> assert_id_from_response(slugged_route.id)
1211
end
1312

1413
test "is case insensitive", %{conn: conn} do

test/controllers/stripe_connect_account_controller_test.exs

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ defmodule CodeCorps.StripeConnectAccountControllerTest do
1212
conn
1313
|> request_show(stripe_connect_account)
1414
|> json_response(200)
15-
|> Map.get("data")
16-
|> assert_result_id(stripe_connect_account.id)
15+
|> assert_id_from_response(stripe_connect_account.id)
1716
end
1817

1918
test "renders 401 when unauthenticated", %{conn: conn} do

test/controllers/stripe_connect_plan_controller_test.exs

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ defmodule CodeCorps.StripeConnectPlanControllerTest do
1111
conn
1212
|> request_show(stripe_connect_plan)
1313
|> json_response(200)
14-
|> Map.get("data")
15-
|> assert_result_id(stripe_connect_plan.id)
14+
|> assert_id_from_response(stripe_connect_plan.id)
1615
end
1716

1817
test "renders 401 when unauthenticated", %{conn: conn} do

test/controllers/stripe_platform_card_controller_test.exs

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ defmodule CodeCorps.StripePlatformCardControllerTest do
88
conn
99
|> request_show(stripe_platform_card)
1010
|> json_response(200)
11-
|> Map.get("data")
12-
|> assert_result_id(stripe_platform_card.id)
11+
|> assert_id_from_response(stripe_platform_card.id)
1312
end
1413

1514
test "renders 401 when unauthenticated", %{conn: conn} do

test/controllers/stripe_platform_customer_controller_test.exs

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ defmodule CodeCorps.StripePlatformCustomerControllerTest do
99
conn
1010
|> request_show(stripe_platform_customer)
1111
|> json_response(200)
12-
|> Map.get("data")
13-
|> assert_result_id(stripe_platform_customer.id)
12+
|> assert_id_from_response(stripe_platform_customer.id)
1413
end
1514

1615
test "renders 401 when unauthenticated", %{conn: conn} do

test/controllers/task_controller_test.exs

+4-5
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,17 @@ defmodule CodeCorps.TaskControllerTest do
8989
conn
9090
|> request_show(task)
9191
|> json_response(200)
92-
|> Map.get("data")
93-
|> assert_result_id(task.id)
92+
|> assert_id_from_response(task.id)
9493
end
9594

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

9998
path = conn |> project_task_path(:show, task.project_id, task.number)
100-
data = conn |> get(path) |> json_response(200) |> Map.get("data")
99+
data = conn |> get(path) |> json_response(200)
101100

102-
assert data["id"] == "#{task.id}"
103-
assert data["type"] == "task"
101+
assert data["data"]["id"] == "#{task.id}"
102+
assert data["data"]["type"] == "task"
104103
end
105104

106105
test "renders 404 when id is nonexistent", %{conn: conn} do

test/controllers/task_list_controller_test.exs

+4-5
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,17 @@ defmodule CodeCorps.TaskListControllerTest do
5050
conn
5151
|> request_show(task_list)
5252
|> json_response(200)
53-
|> Map.get("data")
54-
|> assert_result_id(task_list.id)
53+
|> assert_id_from_response(task_list.id)
5554
end
5655

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

6059
path = conn |> project_task_list_path(:show, task_list.project_id, task_list.id)
61-
data = conn |> get(path) |> json_response(200) |> Map.get("data")
60+
data = conn |> get(path) |> json_response(200)
6261

63-
assert data["id"] == "#{task_list.id}"
64-
assert data["type"] == "task-list"
62+
assert data["data"]["id"] == "#{task_list.id}"
63+
assert data["data"]["type"] == "task-list"
6564
end
6665

6766
test "renders 404 when id is nonexistent", %{conn: conn} do

test/controllers/task_skill_controller_test.exs

+1-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ defmodule CodeCorps.TaskSkillControllerTest do
3434
conn
3535
|> request_show(task_skill)
3636
|> json_response(200)
37-
|> Map.get("data")
38-
|> assert_result_id(task_skill.id)
37+
|> assert_id_from_response(task_skill.id)
3938
end
4039

4140
test "renders 404 error when id is nonexistent", %{conn: conn} do

test/controllers/user_category_controller_test.exs

+1-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ defmodule CodeCorps.UserCategoryControllerTest do
2929
conn
3030
|> request_show(user_category)
3131
|> json_response(200)
32-
|> Map.get("data")
33-
|> assert_result_id(user_category.id)
32+
|> assert_id_from_response(user_category.id)
3433
end
3534

3635
test "renders 404 when id is nonexistent", %{conn: conn} do

test/controllers/user_controller_test.exs

+1-2
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ defmodule CodeCorps.UserControllerTest do
7878
conn
7979
|> request_show(user)
8080
|> json_response(200)
81-
|> Map.get("data")
82-
|> assert_result_id(user.id)
81+
|> assert_id_from_response(user.id)
8382
end
8483

8584
@tag :authenticated

test/controllers/user_role_controller_test.exs

+1-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ defmodule CodeCorps.UserRoleControllerTest do
2929
conn
3030
|> request_show(user_role)
3131
|> json_response(200)
32-
|> Map.get("data")
33-
|> assert_result_id(user_role.id)
32+
|> assert_id_from_response(user_role.id)
3433
end
3534

3635
test "renders 404 when id is nonexistent", %{conn: conn} do

test/controllers/user_skill_controller_test.exs

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ defmodule CodeCorps.UserSkillControllerTest do
3030
conn
3131
|> request_show(user_skill)
3232
|> json_response(200)
33-
|> Map.get("data")
34-
|> assert_result_id(user_skill.id)
33+
|> assert_id_from_response(user_skill.id)
3534
end
3635

3736
test "renders 404 error when id is nonexistent", %{conn: conn} do

test/controllers/user_task_controller_test.exs

+1-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ defmodule CodeCorps.UserTaskControllerTest do
3636
conn
3737
|> request_show(user_task)
3838
|> json_response(200)
39-
|> Map.get("data")
40-
|> assert_result_id(user_task.id)
39+
|> assert_id_from_response(user_task.id)
4140
end
4241

4342
test "renders 404 error when id is nonexistent", %{conn: conn} do

test/support/test_helpers.ex

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ defmodule CodeCorps.TestHelpers do
88
end
99
end
1010

11+
def assert_id_from_response(response, id) do
12+
assert String.to_integer(response["data"]["id"]) == id
13+
response
14+
end
15+
1116
def assert_ids_from_response(response, ids) do
1217
assert ids_from_response(response) == ids
1318
response
@@ -28,11 +33,6 @@ defmodule CodeCorps.TestHelpers do
2833
json
2934
end
3035

31-
def assert_result_id(result, id) do
32-
assert String.to_integer(result["id"]) == id
33-
result
34-
end
35-
3636
def put_id(payload, id), do: put_in(payload, ["data", "id"], id)
3737
def put_attributes(payload, attributes), do: put_in(payload, ["data", "attributes"], attributes)
3838
def put_relationships(payload, record_1, record_2), do: put_relationships(payload, [record_1, record_2])

0 commit comments

Comments
 (0)