forked from railslove/rack-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcriteo_spec.rb
More file actions
122 lines (96 loc) · 2.89 KB
/
criteo_spec.rb
File metadata and controls
122 lines (96 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
RSpec.describe Rack::Tracker::Criteo do
describe Rack::Tracker::Criteo::Event do
subject { described_class.new(event: "viewItem", item: 'P001') }
describe '#write' do
specify { expect(subject.write).to eq("{\"event\":\"viewItem\",\"item\":\"P001\"}") }
end
end
def env
{}
end
it 'will be placed in the body' do
expect(described_class.position).to eq(:body)
expect(described_class.new(env).position).to eq(:body)
end
describe '#render' do
context 'with events' do
let(:env) {
{
'tracker' => {
'criteo' =>
[
{
'event' => 'viewItem',
'item' => 'P001',
'class_name' => 'Event'
}
]
}
}
}
subject { described_class.new(env).render }
it 'will push the tracking events to the queue' do
expect(subject).to include 'window.criteo_q.push({"event":"viewItem","item":"P001"});'
end
end
context 'without events' do
let(:env) {
{
'tracker' => {
'criteo' => []
}
}
}
subject { described_class.new(env, { user_id: ->(env){ '123' } }).render }
it 'should render nothing' do
expect(subject).to eql ""
end
end
end
describe '#tracker_events' do
subject { described_class.new(env, options) }
context 'nil value' do
let(:options) { { set_account: nil } }
it 'should ignore option' do
expect(subject.tracker_events).to match_array []
end
end
context 'static string value' do
let(:options) { { set_account: '1234' } }
it 'should set the value' do
expect(subject.tracker_events).to match_array [
Rack::Tracker::Criteo::Event.new(event: 'setAccount', account: '1234')
]
end
end
context 'static integer value' do
let(:options) { { set_customer_id: 1234 } }
it 'should set the value as string' do
expect(subject.tracker_events).to match_array [
Rack::Tracker::Criteo::Event.new(event: 'setCustomerId', id: '1234')
]
end
end
context 'unsupported option' do
let(:options) { { unsupported: "option" } }
subject { described_class.new(env, options) }
it 'should ignore the option' do
expect(subject.tracker_events).to match_array []
end
end
context 'proc returning value' do
let(:options) { { set_site_type: ->(env){ 'm' } } }
it 'should set the value' do
expect(subject.tracker_events).to match_array [
Rack::Tracker::Criteo::Event.new(event: 'setSiteType', type: 'm')
]
end
end
context 'proc returning nil' do
let(:options) { { set_account: ->(env){ nil } } }
it 'should ignore the option' do
expect(subject.tracker_events).to match_array []
end
end
end
end