     |> Enum.into(%{})
   end
 
-  def log_active(user) do
-    now = DateTime.utc_now
+  def log_active(user, timestamp \\ DateTime.utc_now) do
     record = get_user_record(user)
 
     unless record[:meta] do

      case record.entries do
        # First session seen.
        [] ->
          [{now, nil}]

        # Already have an open session.
        [{_, e} | _] when is_nil e ->


        [{b, e} | rest] ->
        # Being inactive < 5 minutes just merges into one record
        if Timex.diff(timestamp, e, :minutes) < 5 do
          [{b, nil} | rest]
        else
          [{timestamp, nil}, {b, e} | rest]
        end
      end

