From a30a44ad2cea15b13a98e554f2e6260469087fd0 Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Sun, 16 Jun 2024 17:04:37 -0700 Subject: [PATCH] Added test for max_events_per_request --- test/api_test.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/api_test.rb b/test/api_test.rb index d15b7935..9c49b5d0 100644 --- a/test/api_test.rb +++ b/test/api_test.rb @@ -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 @@ -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