Skip to content

Commit

Permalink
Added Task archive tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
begedin committed Oct 23, 2017
1 parent 31c5749 commit 09350f3
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 @@ -47,6 +47,7 @@ defmodule CodeCorpsWeb.TaskController do
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)
current_user |> maybe_track_archive(updated_task, task)

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

@spec maybe_track_archive(User.t, Task.t, Task.t) :: any
defp maybe_track_archive(
%User{id: user_id},
%Task{archived: true} = task,
%Task{archived: false}) do

user_id |> SegmentTracker.track("Archived Task", task)
end
defp maybe_track_archive(%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 @@ -264,6 +264,27 @@ defmodule CodeCorpsWeb.TaskControllerTest do
refute_received {:track, ^user_id, "Closed Task", _}
end

@tag :authenticated
test "tracks archiving task", %{conn: conn, current_user: current_user} do
task = insert(:task, user: current_user, archived: false)
attrs = @valid_attrs |> Map.put(:archived, true)
conn |> request_update(task, attrs)

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

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

user_id = current_user.id
refute_received {:track, ^user_id, "Archived 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 09350f3

Please sign in to comment.