Skip to content

Commit d9ddb68

Browse files
committed
Implement changes and add new tests
1 parent 56bc8cd commit d9ddb68

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

lib/optimizely/event/entity/event_batch.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ def as_json
3030
anonymize_ip: @anonymize_ip,
3131
enrich_decisions: @enrich_decisions,
3232
visitors: @visitors,
33-
region: @region
3433
}
3534
end
3635

lib/optimizely/event/event_factory.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ def create_log_event(user_events, logger)
6767
builder.with_client_name(user_context[:client_name])
6868
builder.with_anonymize_ip(user_context[:anonymize_ip])
6969
builder.with_enrich_decisions(true)
70-
builder.with_region(user_context[:region])
7170

7271
builder.with_visitors(visitors)
7372
event_batch = builder.build

spec/event/event_factory_spec.rb

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,22 @@
120120
expect(log_event.http_verb).to eq(:post)
121121
end
122122

123+
it 'should create valid Event when create_impression_event is called without attributes and with EU' do
124+
@expected_impression_params[:region] = 'EU'
125+
experiment = project_config.get_experiment_from_key('test_experiment')
126+
metadata = {
127+
flag_key: '',
128+
rule_key: 'test_experiment',
129+
rule_type: 'experiment',
130+
variation_key: '111128'
131+
}
132+
impression_event = Optimizely::UserEventFactory.create_impression_event(project_config, experiment, '111128', metadata, 'test_user', nil)
133+
log_event = Optimizely::EventFactory.create_log_event(impression_event, spy_logger)
134+
expect(log_event.params).to eq(@expected_impression_params)
135+
expect(log_event.url).to eq(@expected_endpoints[:EU])
136+
expect(log_event.http_verb).to eq(:post)
137+
end
138+
123139
it 'should create a valid Event when create_impression_event is called with attributes as a string value' do
124140
@expected_impression_params[:visitors][0][:attributes].unshift(
125141
entity_id: '111094',
@@ -629,6 +645,33 @@
629645
expect(log_event.http_verb).to eq(:post)
630646
end
631647

648+
it 'should create valid Event when create_conversion_event is called with Bucketing ID attribute and with EU' do
649+
@expected_conversion_params[:visitors][0][:attributes].unshift(
650+
{
651+
entity_id: '111094',
652+
key: 'browser_type',
653+
type: 'custom',
654+
value: 'firefox'
655+
},
656+
entity_id: Optimizely::Helpers::Constants::CONTROL_ATTRIBUTES['BUCKETING_ID'],
657+
key: Optimizely::Helpers::Constants::CONTROL_ATTRIBUTES['BUCKETING_ID'],
658+
type: 'custom',
659+
value: 'variation'
660+
)
661+
662+
@expected_conversion_params[:region] = 'EU'
663+
664+
user_attributes = {
665+
'browser_type' => 'firefox',
666+
'$opt_bucketing_id' => 'variation'
667+
}
668+
conversion_event = Optimizely::UserEventFactory.create_conversion_event(project_config, event, 'test_user', user_attributes, nil)
669+
log_event = Optimizely::EventFactory.create_log_event(conversion_event, spy_logger)
670+
expect(log_event.params).to eq(@expected_conversion_params)
671+
expect(log_event.url).to eq(@expected_endpoints[:EU])
672+
expect(log_event.http_verb).to eq(:post)
673+
end
674+
632675
it 'should create valid Event with user agent when bot_filtering is enabled' do
633676
# Test that create_conversion_event creates Event object
634677
# with right params when user agent attribute is provided and

0 commit comments

Comments
 (0)