-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Expand file tree
/
Copy pathadhashBidAdapter_spec.js
More file actions
339 lines (305 loc) · 13.7 KB
/
adhashBidAdapter_spec.js
File metadata and controls
339 lines (305 loc) · 13.7 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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
import { expect } from 'chai';
import { spec } from 'modules/adhashBidAdapter.js';
describe('adhashBidAdapter', function () {
describe('isBidRequestValid', function () {
const validBid = {
bidder: 'adhash',
params: {
publisherId: '0xc3b09b27e9c6ef73957901aa729b9e69e5bbfbfb',
platformURL: 'https://adhash.com/p/struma/'
},
mediaTypes: {
banner: {
sizes: [[300, 250]]
}
},
adUnitCode: 'adunit-code',
sizes: [[300, 250]],
bidId: '12345678901234',
bidderRequestId: '98765432109876',
auctionId: '01234567891234',
};
it('should return true when all mandatory parameters are there', function () {
expect(spec.isBidRequestValid(validBid)).to.equal(true);
});
it('should return false when there are no params', function () {
const bid = { ...validBid };
delete bid.params;
expect(spec.isBidRequestValid(bid)).to.equal(false);
});
it('should return false when unsupported media type is requested', function () {
const bid = { ...validBid };
bid.mediaTypes = { native: { sizes: [[300, 250]] } };
expect(spec.isBidRequestValid(bid)).to.equal(false);
});
it('should return false when publisherId is not a string', function () {
const bid = { ...validBid };
bid.params.publisherId = 123;
expect(spec.isBidRequestValid(bid)).to.equal(false);
});
it('should return false when publisherId is not valid', function () {
const bid = { ...validBid };
bid.params.publisherId = 'short string';
expect(spec.isBidRequestValid(bid)).to.equal(false);
});
it('should return false when publisherId is not a string', function () {
const bid = { ...validBid };
bid.params.platformURL = 123;
expect(spec.isBidRequestValid(bid)).to.equal(false);
});
it('should return false when publisherId is not valid', function () {
const bid = { ...validBid };
bid.params.platformURL = 'https://';
expect(spec.isBidRequestValid(bid)).to.equal(false);
});
it('should return false when bidderURL is present but not https://', function () {
const bid = { ...validBid };
bid.params.bidderURL = 'http://example.com/';
expect(spec.isBidRequestValid(bid)).to.equal(false);
});
});
describe('buildRequests', function () {
const bidRequest = {
params: {
publisherId: '0xc3b09b27e9c6ef73957901aa729b9e69e5bbfbfb'
},
sizes: [[300, 250]],
adUnitCode: 'adUnitCode',
mediaTypes: {
banner: {
sizes: [[300, 250]]
}
}
};
it('should build the request correctly', function () {
const result = spec.buildRequests(
[ bidRequest ],
{ gdprConsent: { gdprApplies: true, consentString: 'example' }, refererInfo: { topmostLocation: 'https://example.com/path.html' } }
);
expect(result.length).to.equal(1);
expect(result[0].method).to.equal('POST');
expect(result[0].url).to.equal('https://bidder.adhash.com/rtb?version=3.6&prebid=true&publisher=0xc3b09b27e9c6ef73957901aa729b9e69e5bbfbfb');
expect(result[0].bidRequest).to.equal(bidRequest);
expect(result[0].data).to.have.property('timezone');
expect(result[0].data).to.have.property('location');
expect(result[0].data).to.have.property('publisherId');
expect(result[0].data).to.have.property('size');
expect(result[0].data).to.have.property('navigator');
expect(result[0].data).to.have.property('creatives');
expect(result[0].data).to.have.property('blockedCreatives');
expect(result[0].data).to.have.property('currentTimestamp');
expect(result[0].data).to.have.property('recentAds');
});
it('should build the request correctly without referer', function () {
const result = spec.buildRequests([ bidRequest ], { gdprConsent: { gdprApplies: true, consentString: 'example' } });
expect(result.length).to.equal(1);
expect(result[0].method).to.equal('POST');
expect(result[0].url).to.equal('https://bidder.adhash.com/rtb?version=3.6&prebid=true&publisher=0xc3b09b27e9c6ef73957901aa729b9e69e5bbfbfb');
expect(result[0].bidRequest).to.equal(bidRequest);
expect(result[0].data).to.have.property('timezone');
expect(result[0].data).to.have.property('location');
expect(result[0].data).to.have.property('publisherId');
expect(result[0].data).to.have.property('size');
expect(result[0].data).to.have.property('navigator');
expect(result[0].data).to.have.property('creatives');
expect(result[0].data).to.have.property('blockedCreatives');
expect(result[0].data).to.have.property('currentTimestamp');
expect(result[0].data).to.have.property('recentAds');
});
});
describe('interpretResponse', function () {
const request = {
data: { some: 'data' },
bidRequest: {
bidId: '12345678901234',
adUnitCode: 'adunit-code',
sizes: [[300, 250]],
params: {
platformURL: 'https://adhash.com/p/struma/'
},
mediaTypes: {
banner: {
sizes: [[300, 250]]
}
}
}
};
let bodyStub;
const serverResponse = {
body: {
creatives: [{ costEUR: 1.234 }],
advertiserDomains: 'adhash.com',
badWords: [
['onqjbeq', 'full', 1],
['onqjbeqo', 'partial', 1],
['tbbqjbeq', 'full', -1],
['fgnegf', 'starts', 1],
['raqf', 'ends', 1],
['kkk[no]lll', 'regexp', 1],
['дума', 'full', 1],
['старт', 'starts', 1],
['край', 'ends', 1],
['onq jbeq', 'partial', 1],
['dhrra qvrf', 'combo', 2],
],
maxScore: 2
}
};
afterEach(function() {
if (bodyStub) {
bodyStub.restore();
}
});
it('should interpret the response correctly', function () {
const result = spec.interpretResponse(serverResponse, request);
expect(result.length).to.equal(1);
expect(result[0].requestId).to.equal('12345678901234');
expect(result[0].cpm).to.equal(1.234);
expect(result[0].width).to.equal(300);
expect(result[0].height).to.equal(250);
expect(result[0].creativeId).to.equal('adunit-code');
expect(result[0].netRevenue).to.equal(true);
expect(result[0].currency).to.equal('EUR');
expect(result[0].ttl).to.equal(60);
expect(result[0].meta.advertiserDomains).to.eql(['adhash.com']);
});
it('should return empty array when there are bad words (full)', function () {
bodyStub = sinon.stub(window.top.document.body, 'textContent').get(function() {
return 'example text badword badword example badword text' + ' word'.repeat(993);
});
expect(spec.interpretResponse(serverResponse, request).length).to.equal(0);
});
it('should return empty array when there are bad words (full cyrillic)', function () {
bodyStub = sinon.stub(window.top.document.body, 'textContent').get(function() {
return 'example text дума дума example дума text' + ' текст'.repeat(993);
});
expect(spec.interpretResponse(serverResponse, request).length).to.equal(0);
});
it('should return empty array when there are bad words (partial)', function () {
bodyStub = sinon.stub(window.top.document.body, 'textContent').get(function() {
return 'example text partialbadwordb badwordb example badwordbtext' + ' word'.repeat(994);
});
expect(spec.interpretResponse(serverResponse, request).length).to.equal(0);
});
it('should return empty array when there are bad words (partial, compound phrase)', function () {
bodyStub = sinon.stub(window.top.document.body, 'textContent').get(function() {
return 'example text partialbad wordb bad wordb example bad wordbtext' + ' word'.repeat(994);
});
expect(spec.interpretResponse(serverResponse, request).length).to.equal(0);
});
it('should return empty array when there are bad words (starts)', function () {
bodyStub = sinon.stub(window.top.document.body, 'textContent').get(function() {
return 'example text startsWith starts text startsAgain' + ' word'.repeat(994);
});
expect(spec.interpretResponse(serverResponse, request).length).to.equal(0);
});
it('should return empty array when there are bad words (starts cyrillic)', function () {
bodyStub = sinon.stub(window.top.document.body, 'textContent').get(function() {
return 'example text стартТекст старт text стартТекст' + ' дума'.repeat(994);
});
expect(spec.interpretResponse(serverResponse, request).length).to.equal(0);
});
it('should return empty array when there are bad words (ends)', function () {
bodyStub = sinon.stub(window.top.document.body, 'textContent').get(function() {
return 'example text wordEnds ends text anotherends' + ' word'.repeat(994);
});
expect(spec.interpretResponse(serverResponse, request).length).to.equal(0);
});
it('should return empty array when there are bad words (ends cyrillic)', function () {
bodyStub = sinon.stub(window.top.document.body, 'textContent').get(function() {
return 'example text ДругКрай край text ощеединкрай' + ' дума'.repeat(994);
});
expect(spec.interpretResponse(serverResponse, request).length).to.equal(0);
});
it('should return empty array when there are bad words (combo)', function () {
bodyStub = sinon.stub(window.top.document.body, 'textContent').get(function() {
return 'queen of england dies, the queen dies' + ' word'.repeat(993);
});
expect(spec.interpretResponse(serverResponse, request).length).to.equal(0);
});
it('should return empty array when there are bad words (regexp)', function () {
bodyStub = sinon.stub(window.top.document.body, 'textContent').get(function() {
return 'example text xxxayyy zzxxxAyyyzz text xxxbyyy' + ' word'.repeat(994);
});
expect(spec.interpretResponse(serverResponse, request).length).to.equal(0);
});
it('should return non-empty array when there are not enough bad words (full)', function () {
bodyStub = sinon.stub(window.top.document.body, 'textContent').get(function() {
return 'example text badword badword example text' + ' word'.repeat(994);
});
expect(spec.interpretResponse(serverResponse, request).length).to.equal(1);
});
it('should return non-empty array when there are not enough bad words (partial)', function () {
bodyStub = sinon.stub(window.top.document.body, 'textContent').get(function() {
return 'example text partialbadwordb example' + ' word'.repeat(996);
});
expect(spec.interpretResponse(serverResponse, request).length).to.equal(1);
});
it('should return non-empty array when there are no-bad word matches', function () {
bodyStub = sinon.stub(window.top.document.body, 'textContent').get(function() {
return 'example text partialbadword example text' + ' word'.repeat(995);
});
expect(spec.interpretResponse(serverResponse, request).length).to.equal(1);
});
it('should return non-empty array when there are bad words and good words', function () {
bodyStub = sinon.stub(window.top.document.body, 'textContent').get(function() {
return 'example text badword badword example badword goodWord goodWord ' + ' word'.repeat(992);
});
expect(spec.interpretResponse(serverResponse, request).length).to.equal(1);
});
it('should return non-empty array when there is a problem with the brand-safety', function () {
bodyStub = sinon.stub(window.top.document.body, 'textContent').get(function() {
return null;
});
expect(spec.interpretResponse(serverResponse, request).length).to.equal(1);
});
it('should return empty array when there are no creatives returned', function () {
expect(spec.interpretResponse({body: {creatives: []}}, request).length).to.equal(0);
});
it('should return empty array when there is no creatives key in the response', function () {
expect(spec.interpretResponse({body: {}}, request).length).to.equal(0);
});
it('should return empty array when something is not right', function () {
expect(spec.interpretResponse(null, request).length).to.equal(0);
});
it('should interpret the video response correctly', function () {
const result = spec.interpretResponse({
body: {
creatives: [{ costEUR: 1.234, vastURL: 'https://example.com/vast' }],
advertiserDomains: 'adhash.com'
}
}, {
data: { some: 'data' },
bidRequest: {
bidId: '12345678901234',
adUnitCode: 'adunit-code',
sizes: [[300, 250]],
params: {
platformURL: 'https://adhash.com/p/struma/'
},
mediaTypes: {
video: {
context: 'instream',
playerSize: [300, 250],
mimes: ['video/mp4'],
protocols: [1, 2, 3, 4, 5, 6, 7, 8],
playbackmethod: [2],
skip: 1
}
}
}
});
expect(result.length).to.equal(1);
expect(result[0].requestId).to.equal('12345678901234');
expect(result[0].cpm).to.equal(1.234);
expect(result[0].width).to.equal(300);
expect(result[0].height).to.equal(250);
expect(result[0].creativeId).to.equal('adunit-code');
expect(result[0].netRevenue).to.equal(true);
expect(result[0].currency).to.equal('EUR');
expect(result[0].ttl).to.equal(60);
expect(result[0].meta.advertiserDomains).to.eql(['adhash.com']);
expect(result[0].vastUrl).to.equal('https://example.com/vast');
});
});
});