Skip to content

Commit e9211e6

Browse files
mauerbacMatt Auerbach
authored andcommitted
Add tests to ensure pruning nil values
1 parent 222aa09 commit e9211e6

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
@@ -122,6 +122,18 @@
122122
expect(conversion_event.http_verb).to eq(:post)
123123
end
124124

125+
it 'should create a valid V2 Event when create_conversion_event is called when an attribute value is nil' do
126+
@expected_conversion_params['userFeatures'] = [
127+
]
128+
129+
attributes = {'browser_type' => nil}
130+
131+
conversion_event = @event_builder.create_conversion_event('test_event', 'test_user', attributes, nil, {'111127' => '111128'})
132+
expect(conversion_event.params).to eq(@expected_conversion_params)
133+
expect(conversion_event.url).to eq(@expected_conversion_url)
134+
expect(conversion_event.http_verb).to eq(:post)
135+
end
136+
125137
it 'should create a valid V2 Event when create_conversion_event is called with revenue event tag' do
126138
@expected_conversion_params['eventMetrics'] = [{
127139
'name' => 'revenue',
@@ -144,6 +156,24 @@
144156
expect(conversion_event.http_verb).to eq(:post)
145157
end
146158

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

0 commit comments

Comments
 (0)