Skip to content

Commit 98dd938

Browse files
authored
Add tests to ensure pruning nil values
1 parent 6c29f5b commit 98dd938

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

lib/optimizely/event_builder.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def add_attributes(attributes)
132132
return if attributes.nil?
133133

134134
attributes.keys.each do |attribute_key|
135-
# Omit falsy attribute values
135+
# Omit falsy or nil attribute values
136136
attribute_value = attributes[attribute_key]
137137
next unless attribute_value
138138

spec/event_builder_spec.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,18 @@
125125
expect(conversion_event.http_verb).to eq(:post)
126126
end
127127

128+
it 'should create a valid V2 Event when create_conversion_event is called when an attribute value is nil' do
129+
@expected_conversion_params['userFeatures'] = [
130+
]
131+
132+
attributes = {'browser_type' => nil}
133+
134+
conversion_event = @event_builder.create_conversion_event('test_event', 'test_user', attributes, nil, {'111127' => '111128'})
135+
expect(conversion_event.params).to eq(@expected_conversion_params)
136+
expect(conversion_event.url).to eq(@expected_conversion_url)
137+
expect(conversion_event.http_verb).to eq(:post)
138+
end
139+
128140
it 'should create a valid V2 Event when create_conversion_event is called with revenue event tag' do
129141
@expected_conversion_params['eventMetrics'] = [{
130142
'name' => 'revenue',
@@ -147,6 +159,24 @@
147159
expect(conversion_event.http_verb).to eq(:post)
148160
end
149161

162+
it 'should create a valid V2 Event when create_conversion_event is called when an event tag value is nil' do
163+
@expected_conversion_params['eventFeatures'] = [
164+
{
165+
'name' => 'purchasePrice',
166+
'type' => 'custom',
167+
'value' => 64.32,
168+
'shouldIndex' => false
169+
},
170+
]
171+
172+
event_tags = {'category' => nil,'purchasePrice' => 64.32}
173+
174+
conversion_event = @event_builder.create_conversion_event('test_event', 'test_user', nil, event_tags, {'111127' => '111128'})
175+
expect(conversion_event.params).to eq(@expected_conversion_params)
176+
expect(conversion_event.url).to eq(@expected_conversion_url)
177+
expect(conversion_event.http_verb).to eq(:post)
178+
end
179+
150180
it 'should create a valid V2 Event when create_conversion_event is called with revenue event tag' do
151181
@expected_conversion_params['eventMetrics'] = []
152182
@expected_conversion_params['eventFeatures'] = [

0 commit comments

Comments
 (0)