forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadlooxRtdProvider_spec.js
More file actions
223 lines (177 loc) · 6.01 KB
/
adlooxRtdProvider_spec.js
File metadata and controls
223 lines (177 loc) · 6.01 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
import adapterManager from 'src/adapterManager.js';
import analyticsAdapter from 'modules/adlooxAnalyticsAdapter.js';
import { auctionManager } from 'src/auctionManager.js';
import { expect } from 'chai';
import * as events from 'src/events.js';
import * as prebidGlobal from 'src/prebidGlobal.js';
import { subModuleObj as rtdProvider } from 'modules/adlooxRtdProvider.js';
import * as utils from 'src/utils.js';
import { server } from '../../mocks/xhr.js';
const analyticsAdapterName = 'adloox';
describe('Adloox RTD Provider', function () {
let sandbox;
const adUnit = {
code: 'ad-slot-1',
ortb2Imp: {
ext: {
data: {
pbadslot: '/123456/home/ad-slot-1'
}
}
},
mediaTypes: {
banner: {
sizes: [[300, 250]]
}
},
bids: [
{
bidder: 'dummy'
}
]
};
const analyticsOptions = {
js: 'https://j.adlooxtracking.com/ads/js/tfav_adl_%%clientid%%.js',
client: 'adlooxtest',
clientid: 127,
platformid: 0,
tagid: 0
};
const config = {};
adapterManager.registerAnalyticsAdapter({
code: analyticsAdapterName,
adapter: analyticsAdapter
});
before(function () {
sandbox = sinon.createSandbox();
sandbox.stub(events, 'getEvents').returns([]);
});
after(function () {
sandbox.restore();
sandbox = undefined;
});
describe('invalid config', function () {
it('should require config', function (done) {
const ret = rtdProvider.init();
expect(ret).is.false;
done();
});
it('should reject non-object config.params', function (done) {
const ret = rtdProvider.init({ params: null });
expect(ret).is.false;
done();
});
it('should reject less than one config.params.imps', function (done) {
const ret = rtdProvider.init({ params: { imps: 0 } });
expect(ret).is.false;
done();
});
it('should reject negative config.params.freqcap_ip', function (done) {
const ret = rtdProvider.init({ params: { freqcap_ip: -1 } });
expect(ret).is.false;
done();
});
it('should reject negative integer config.params.freqcap_ipua', function (done) {
const ret = rtdProvider.init({ params: { freqcap_ipua: -1 } });
expect(ret).is.false;
done();
});
it('should reject non-array of integers with value greater than zero config.params.thresholds', function (done) {
const ret = rtdProvider.init({ params: { thresholds: [70, null] } });
expect(ret).is.false;
done();
});
it('should reject non-boolean config.params.slotinpath', function (done) {
const ret = rtdProvider.init({ params: { slotinpath: null } });
expect(ret).is.false;
done();
});
it('should reject invalid config.params.params (legacy/deprecated)', function (done) {
const ret = rtdProvider.init({ params: { params: { clientid: 0, tagid: 0 } } });
expect(ret).is.false;
done();
});
});
describe('process segments', function () {
before(function () {
adapterManager.enableAnalytics({
provider: analyticsAdapterName,
options: analyticsOptions
});
expect(analyticsAdapter.context).is.not.null;
});
after(function () {
analyticsAdapter.disableAnalytics();
expect(analyticsAdapter.context).is.null;
});
let CONFIG = null;
beforeEach(function () {
CONFIG = utils.deepClone(config);
});
afterEach(function () {
CONFIG = null;
});
it('should fetch segments', function (done) {
const req = {
adUnitCodes: [adUnit.code],
ortb2Fragments: {
global: {
site: {
ext: {
data: {
}
}
},
user: {
ext: {
data: {
}
}
}
}
}
};
const adUnitWithSegments = utils.deepClone(adUnit);
const getGlobalStub = sinon.stub(prebidGlobal, 'getGlobal').returns({
adUnits: [adUnitWithSegments]
});
const ret = rtdProvider.init(CONFIG);
expect(ret).is.true;
const callback = function () {
const ortb2 = req.ortb2Fragments.global;
expect(ortb2.site.ext.data.adloox_rtd.ok).is.true;
expect(ortb2.site.ext.data.adloox_rtd.nope).is.undefined;
expect(ortb2.user.ext.data.adloox_rtd.unused).is.false;
expect(ortb2.user.ext.data.adloox_rtd.nope).is.undefined;
expect(adUnitWithSegments.ortb2Imp.ext.data.adloox_rtd.dis.length).is.equal(3);
expect(adUnitWithSegments.ortb2Imp.ext.data.adloox_rtd.nope).is.undefined;
getGlobalStub.restore();
done();
};
rtdProvider.getBidRequestData(req, callback, CONFIG, null);
const request = server.requests[0];
const response = { unused: false, _: [{ d: 77 }] };
request.respond(200, { 'content-type': 'application/json' }, JSON.stringify(response));
});
it('should set ad server targeting', function (done) {
const adUnitWithSegments = utils.deepClone(adUnit);
utils.deepSetValue(adUnitWithSegments, 'ortb2Imp.ext.data.adloox_rtd.dis', [50, 60]);
const getGlobalStub = sinon.stub(prebidGlobal, 'getGlobal').returns({
adUnits: [adUnitWithSegments]
});
const auction = { adUnits: [adUnitWithSegments] };
const getAuctionStub = sinon.stub(auctionManager.index, 'getAuction').returns({
adUnits: [adUnitWithSegments],
getFPD: () => { return { global: { site: { ext: { data: { adloox_rtd: { ok: true } } } } } } }
});
const targetingData = rtdProvider.getTargetingData([adUnitWithSegments.code], CONFIG, null, auction);
expect(Object.keys(targetingData).length).is.equal(1);
expect(Object.keys(targetingData[adUnit.code]).length).is.equal(2);
expect(targetingData[adUnit.code].adl_ok).is.equal(1);
expect(targetingData[adUnit.code].adl_dis.length).is.equal(2);
getAuctionStub.restore();
getGlobalStub.restore();
done();
});
});
});