Skip to content

Commit ed5b552

Browse files
committed
Tracking and testing for donation goal update and create
1 parent 87dedbe commit ed5b552

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

test/controllers/donation_goal_controller_test.exs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,17 @@ defmodule CodeCorps.DonationGoalControllerTest do
4242
end
4343

4444
describe "create" do
45-
@tag authenticated: :admin
46-
test "creates and renders resource when data is valid", %{conn: conn} do
47-
project = insert(:project)
45+
@tag :authenticated
46+
test "creates and renders resource when data is valid", %{conn: conn, current_user: current_user} do
47+
organization = insert(:organization)
48+
insert(:organization_membership, member: current_user, organization: organization, role: "owner")
49+
project = insert(:project, organization: organization)
50+
4851
attrs = @valid_attrs |> Map.merge(%{project: project})
4952
assert conn |> request_create(attrs) |> json_response(201)
53+
54+
user_id = current_user.id
55+
assert_received {:track, ^user_id, "Created Donation Goal", %{}}
5056
end
5157

5258
@tag authenticated: :admin
@@ -65,11 +71,19 @@ defmodule CodeCorps.DonationGoalControllerTest do
6571
end
6672

6773
describe "update" do
68-
@tag authenticated: :admin
69-
test "updates and renders chosen resource when data is valid", %{conn: conn} do
70-
project = insert(:project)
74+
@tag :authenticated
75+
test "updates and renders chosen resource when data is valid", %{conn: conn, current_user: current_user} do
76+
organization = insert(:organization)
77+
insert(:organization_membership, member: current_user, organization: organization, role: "owner")
78+
project = insert(:project, organization: organization)
79+
80+
donation_goal = insert(:donation_goal, project: project)
81+
7182
attrs = @valid_attrs |> Map.merge(%{project: project})
72-
assert conn |> request_update(attrs) |> json_response(200)
83+
assert conn |> request_update(donation_goal, attrs) |> json_response(200)
84+
85+
user_id = current_user.id
86+
assert_received {:track, ^user_id, "Updated Donation Goal", %{}}
7387
end
7488

7589
@tag authenticated: :admin

web/controllers/donation_goal_controller.ex

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ defmodule CodeCorps.DonationGoalController do
1313

1414
def filter(_conn, query, "id", id_list), do: id_filter(query, id_list)
1515

16-
def handle_create(_conn, attributes) do
16+
def handle_create(conn, attributes) do
1717
attributes
1818
|> DonationGoalsService.create
19+
|> CodeCorps.Analytics.Segment.track(:created, conn)
1920
end
2021

21-
def handle_update(_conn, record, attributes) do
22+
def handle_update(conn, record, attributes) do
2223
record
2324
|> DonationGoalsService.update(attributes)
25+
|> CodeCorps.Analytics.Segment.track(:updated, conn)
2426
end
2527
end

0 commit comments

Comments
 (0)