Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions app/controllers/frontend_log_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,12 @@ class FrontendLogController < ApplicationController
EVENT_MAP = ALLOWED_EVENTS.index_by(&:to_s).merge(LEGACY_EVENT_MAP).freeze

def create
result = frontend_logger.track_event(log_params[:event], log_params[:payload].to_h)
success = frontend_logger.track_event(log_params[:event], log_params[:payload].to_h)

if result
render json: { success: true }, status: :ok
if success
render json: { success: }, status: :ok
else
render json: { success: false, error_message: 'invalid event' },
status: :bad_request
render json: { success:, error_message: 'invalid event' }, status: :bad_request
end
end

Expand Down
2 changes: 0 additions & 2 deletions app/services/frontend_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ def track_event(name, attributes)
analytics_method.call(**hash_from_kwargs(attributes, analytics_method))
true
else
# 2023-10-31 - Temporary
analytics.track_event("Frontend (warning): #{name}", attributes)
false
end
end
Expand Down
6 changes: 2 additions & 4 deletions spec/controllers/frontend_log_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@
end

context 'with invalid event name' do
it 'logs with warning' do
it 'responds as unsuccessful' do
action

expect(fake_analytics).to have_logged_event('Frontend (warning): Custom Event')
expect(response).to have_http_status(:bad_request)
expect(json[:success]).to eq(false)
expect(json[:error_message]).to eq('invalid event')
Expand Down Expand Up @@ -239,10 +238,9 @@
end

context 'with invalid event name' do
it 'logs with warning' do
it 'responds as unsuccessful' do
action

expect(fake_analytics).to have_logged_event('Frontend (warning): Custom Event')
expect(response).to have_http_status(:bad_request)
expect(json[:success]).to eq(false)
expect(json[:error_message]).to eq('invalid event')
Expand Down
10 changes: 5 additions & 5 deletions spec/services/frontend_logger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,14 @@ def example_method_handler(ok:, **rest)
context 'with unknown event' do
let(:name) { :test_event }

it 'logs unknown event with warning' do
call

expect(analytics).to have_logged_event('Frontend (warning): test_event')
end
it { expect(call).to eq(false) }
end

context 'with method handler' do
let(:name) { 'method' }

it { expect(call).to eq(true) }

it 'calls method with attributes based on signature' do
call

Expand All @@ -57,6 +55,8 @@ def example_method_handler(ok:, **rest)
context 'with proc handler' do
let(:name) { 'proc' }

it { expect(call).to eq(true) }

it 'calls the method and passes analytics and attributes' do
call

Expand Down