Skip to content

Commit

Permalink
Tracking and testing for donation goal update and create
Browse files Browse the repository at this point in the history
  • Loading branch information
begedin committed Jan 19, 2017
1 parent 87dedbe commit ed5b552
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
28 changes: 21 additions & 7 deletions test/controllers/donation_goal_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,17 @@ defmodule CodeCorps.DonationGoalControllerTest do
end

describe "create" do
@tag authenticated: :admin
test "creates and renders resource when data is valid", %{conn: conn} do
project = insert(:project)
@tag :authenticated
test "creates and renders resource when data is valid", %{conn: conn, current_user: current_user} do
organization = insert(:organization)
insert(:organization_membership, member: current_user, organization: organization, role: "owner")
project = insert(:project, organization: organization)

attrs = @valid_attrs |> Map.merge(%{project: project})
assert conn |> request_create(attrs) |> json_response(201)

user_id = current_user.id
assert_received {:track, ^user_id, "Created Donation Goal", %{}}
end

@tag authenticated: :admin
Expand All @@ -65,11 +71,19 @@ defmodule CodeCorps.DonationGoalControllerTest do
end

describe "update" do
@tag authenticated: :admin
test "updates and renders chosen resource when data is valid", %{conn: conn} do
project = insert(:project)
@tag :authenticated
test "updates and renders chosen resource when data is valid", %{conn: conn, current_user: current_user} do
organization = insert(:organization)
insert(:organization_membership, member: current_user, organization: organization, role: "owner")
project = insert(:project, organization: organization)

donation_goal = insert(:donation_goal, project: project)

attrs = @valid_attrs |> Map.merge(%{project: project})
assert conn |> request_update(attrs) |> json_response(200)
assert conn |> request_update(donation_goal, attrs) |> json_response(200)

user_id = current_user.id
assert_received {:track, ^user_id, "Updated Donation Goal", %{}}
end

@tag authenticated: :admin
Expand Down
6 changes: 4 additions & 2 deletions web/controllers/donation_goal_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ defmodule CodeCorps.DonationGoalController do

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

def handle_create(_conn, attributes) do
def handle_create(conn, attributes) do
attributes
|> DonationGoalsService.create
|> CodeCorps.Analytics.Segment.track(:created, conn)
end

def handle_update(_conn, record, attributes) do
def handle_update(conn, record, attributes) do
record
|> DonationGoalsService.update(attributes)
|> CodeCorps.Analytics.Segment.track(:updated, conn)
end
end

0 comments on commit ed5b552

Please sign in to comment.