Skip to content

Commit

Permalink
Added task close tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
begedin committed Oct 23, 2017
1 parent e5f6040 commit 31c5749
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/code_corps_web/controllers/task_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ defmodule CodeCorpsWeb.TaskController do
current_user |> maybe_track_connected(updated_task, task)
current_user |> maybe_track_list_move(updated_task, task)
current_user |> maybe_track_title_change(updated_task, task)
current_user |> maybe_track_close(updated_task, task)

conn |> render("show.json-api", data: updated_task)
end
Expand Down Expand Up @@ -102,4 +103,14 @@ defmodule CodeCorpsWeb.TaskController do
user_id |> SegmentTracker.track("Edited Task Title", task)
end
defp maybe_track_title_change(%User{}, %Task{}, %Task{}), do: :nothing

@spec maybe_track_close(User.t, Task.t, Task.t) :: any
defp maybe_track_close(
%User{id: user_id},
%Task{status: "closed"} = task,
%Task{status: "open"}) do

user_id |> SegmentTracker.track("Closed Task", task)
end
defp maybe_track_close(%User{}, %Task{}, %Task{}), do: :nothing
end
21 changes: 21 additions & 0 deletions test/lib/code_corps_web/controllers/task_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,27 @@ defmodule CodeCorpsWeb.TaskControllerTest do
refute_received {:track, ^user_id, "Edited Task Title", _}
end

@tag :authenticated
test "tracks closing task", %{conn: conn, current_user: current_user} do
task = insert(:task, user: current_user, status: "open")
attrs = @valid_attrs |> Map.put(:status, "closed")
conn |> request_update(task, attrs)

traits = Task |> Repo.get(task.id) |> SegmentTraitsBuilder.build
user_id = current_user.id
assert_received {:track, ^user_id, "Closed Task", ^traits}
end

@tag :authenticated
test "does not track closing task if no close took place", %{conn: conn, current_user: current_user} do
task = insert(:task, user: current_user, status: "open")
attrs = @valid_attrs |> Map.delete(:status)
conn |> request_update(task, attrs)

user_id = current_user.id
refute_received {:track, ^user_id, "Closed Task", _}
end

@tag :authenticated
test "renders 422 when data is invalid", %{conn: conn, current_user: current_user} do
task = insert(:task, user: current_user)
Expand Down

0 comments on commit 31c5749

Please sign in to comment.