Skip to content

Commit

Permalink
Added test for max_events_per_request
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Jun 17, 2024
1 parent 6f53a99 commit a30a44a
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions test/api_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,23 @@ def test_max_content_length
end
end

def test_max_events_per_request
visit = random_visit
events = 10.times.map { random_event }

with_options(max_events_per_request: 5) do
event_params = {
visit_token: visit.visit_token,
visitor_token: visit.visitor_token,
events_json: events.to_json
}
post ahoy_engine.events_url, params: event_params
assert_response :success

assert_equal 5, Ahoy::Event.count
end
end

def test_missing_params
post ahoy_engine.events_url
assert_response :bad_request
Expand All @@ -149,6 +166,15 @@ def random_visit(started_at: nil)
)
end

def random_event
{
id: random_token,
name: "Test",
properties: {},
time: Time.current.round
}
end

def random_token
SecureRandom.uuid
end
Expand Down

0 comments on commit a30a44a

Please sign in to comment.