forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathakceloBidAdapter_spec.js
More file actions
263 lines (234 loc) · 10.1 KB
/
akceloBidAdapter_spec.js
File metadata and controls
263 lines (234 loc) · 10.1 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
import { converter, spec } from 'modules/akceloBidAdapter.js';
import * as utils from '../../../src/utils.js';
import { deepClone } from '../../../src/utils.js';
import sinon from 'sinon';
describe('Akcelo bid adapter tests', () => {
let sandBox;
beforeEach(() => {
sandBox = sinon.createSandbox();
sandBox.stub(utils, 'logError');
});
afterEach(() => sandBox.restore());
const DEFAULT_BANNER_BID_REQUESTS = [
{
adUnitCode: 'div-banner-id',
bidId: 'bid-123',
mediaTypes: {
banner: {
sizes: [
[300, 250],
[300, 600],
],
},
},
bidder: 'akcelo',
params: {
siteId: 123,
adUnitId: 456,
},
requestId: 'request-123',
}
];
const DEFAULT_BANNER_BIDDER_REQUEST = {
bidderCode: 'akcelo',
bids: DEFAULT_BANNER_BID_REQUESTS,
};
const SAMPLE_RESPONSE = {
body: {
id: '12h712u7-k22g-8124-ab7a-h268s22dy271',
seatbid: [
{
bid: [
{
id: '1bh7jku7-ko2g-8654-ab72-h268abcde271',
impid: 'bid-123',
price: 0.6565,
adm: '<h1>AD</h1>',
adomain: ['abc.com'],
cid: '1242512',
crid: '535231',
w: 300,
h: 600,
mtype: 1,
ext: {
prebid: {
type: 'banner',
}
}
},
],
seat: '4212',
},
],
cur: 'EUR',
},
};
describe('isBidRequestValid', () => {
it('should return true if params.siteId and params.adUnitId are set', () => {
const bidRequest = {
params: {
siteId: 123,
adUnitId: 456,
},
};
expect(spec.isBidRequestValid(bidRequest)).to.equal(true);
});
it('should return false if params.siteId is missing', () => {
const bidRequest = {
params: {
adUnitId: 456,
},
};
expect(spec.isBidRequestValid(bidRequest)).to.equal(false);
});
it('should return false if params.adUnitId is missing', () => {
const bidRequest = {
params: {
siteId: 123,
},
};
expect(spec.isBidRequestValid(bidRequest)).to.equal(false);
});
});
describe('buildRequests', () => {
it('should build correct requests using ORTB converter', () => {
const request = spec.buildRequests(
DEFAULT_BANNER_BID_REQUESTS,
DEFAULT_BANNER_BIDDER_REQUEST
);
const dataFromConverter = converter.toORTB({
bidderRequest: DEFAULT_BANNER_BIDDER_REQUEST,
bidRequests: DEFAULT_BANNER_BID_REQUESTS,
});
expect(request[0]).to.deep.equal({
data: { ...dataFromConverter, id: request[0].data.id },
method: 'POST',
url: 'https://s2s.sportslocalmedia.com/openrtb2/auction',
});
});
it('should add site.publisher.ext.prebid.parentAccount to request object when siteId is defined', () => {
const request = spec.buildRequests(DEFAULT_BANNER_BID_REQUESTS, DEFAULT_BANNER_BIDDER_REQUEST)[0];
expect(request.data.site.publisher.ext.prebid.parentAccount).to.equal(123);
});
it('should not add site.publisher.ext.prebid.parentAccount to request object when siteId is not defined', () => {
const bidRequests = [
{ ...DEFAULT_BANNER_BID_REQUESTS[0], params: { adUnitId: 456 } },
];
const bidderRequest = { ...DEFAULT_BANNER_BIDDER_REQUEST, bids: bidRequests };
const request = spec.buildRequests(bidRequests, bidderRequest)[0];
expect(request.data.site.publisher.ext.prebid.parentAccount).to.be.undefined;
});
it('should add ext.akcelo to imp object when siteId and adUnitId are defined', () => {
const request = spec.buildRequests(DEFAULT_BANNER_BID_REQUESTS, DEFAULT_BANNER_BIDDER_REQUEST)[0];
expect(request.data.imp[0].ext.akcelo).to.deep.equal({
siteId: 123,
adUnitId: 456,
});
});
it('should not add ext.akcelo.siteId to imp object when siteId is not defined', () => {
const bidRequests = [
{ ...DEFAULT_BANNER_BID_REQUESTS[0], params: { adUnitId: 456 } },
];
const bidderRequest = { ...DEFAULT_BANNER_BIDDER_REQUEST, bids: bidRequests };
const request = spec.buildRequests(bidRequests, bidderRequest)[0];
expect(request.data.imp[0].ext.akcelo.siteId).to.be.undefined;
expect(utils.logError.calledOnce).to.equal(true);
expect(utils.logError.args[0][0]).to.equal('Missing parameter : siteId')
});
it('should not add ext.akcelo.adUnitId to imp object when adUnitId is not defined', () => {
const bidRequests = [
{ ...DEFAULT_BANNER_BID_REQUESTS[0], params: { siteId: 123 } },
];
const bidderRequest = { ...DEFAULT_BANNER_BIDDER_REQUEST, bids: bidRequests };
const request = spec.buildRequests(bidRequests, bidderRequest)[0];
expect(request.data.imp[0].ext.akcelo.adUnitId).to.be.undefined;
expect(utils.logError.calledOnce).to.equal(true);
expect(utils.logError.args[0][0]).to.equal('Missing parameter : adUnitId')
});
it('should add ext.akcelo.test=1 to imp object when param akcelo_demo is true', () => {
sandBox.stub(utils, 'getParameterByName').callsFake(() => 'true');
const request = spec.buildRequests(DEFAULT_BANNER_BID_REQUESTS, DEFAULT_BANNER_BIDDER_REQUEST)[0];
expect(request.data.imp[0].ext.akcelo.test).to.equal(1);
});
it('should not add ext.akcelo.test to imp object when param akcelo_demo is not true', () => {
sandBox.stub(utils, 'getParameterByName').callsFake(() => 'something_else');
const request = spec.buildRequests(DEFAULT_BANNER_BID_REQUESTS, DEFAULT_BANNER_BIDDER_REQUEST)[0];
expect(request.data.imp[0].ext.akcelo.test).to.be.undefined;
});
it('should not add ext.akcelo.test to imp object when param akcelo_demo is not defined', () => {
const request = spec.buildRequests(DEFAULT_BANNER_BID_REQUESTS, DEFAULT_BANNER_BIDDER_REQUEST)[0];
expect(request.data.imp[0].ext.akcelo.test).to.be.undefined;
});
});
describe('interpretResponse', () => {
it('should return data returned by ORTB converter', () => {
const request = spec.buildRequests(DEFAULT_BANNER_BID_REQUESTS, DEFAULT_BANNER_BIDDER_REQUEST)[0];
const bids = spec.interpretResponse(SAMPLE_RESPONSE, request);
const responseFromConverter = converter.fromORTB({
request: request.data,
response: SAMPLE_RESPONSE.body,
});
expect(bids).to.deep.equal(responseFromConverter.bids);
});
it('should find the media type from bid.mtype if possible', () => {
const serverResponse = deepClone(SAMPLE_RESPONSE);
serverResponse.body.seatbid[0].bid[0].mtype = 2;
const request = spec.buildRequests(DEFAULT_BANNER_BID_REQUESTS, DEFAULT_BANNER_BIDDER_REQUEST)[0];
const bids = spec.interpretResponse(serverResponse, request);
expect(bids[0].mediaType).to.equal('video');
});
it('should find the media type from bid.ext.prebid.type if mtype is not defined', () => {
const serverResponse = deepClone(SAMPLE_RESPONSE);
delete serverResponse.body.seatbid[0].bid[0].mtype;
const request = spec.buildRequests(DEFAULT_BANNER_BID_REQUESTS, DEFAULT_BANNER_BIDDER_REQUEST)[0];
const bids = spec.interpretResponse(serverResponse, request);
expect(bids[0].mediaType).to.equal('banner');
});
it('should skip the bid if bid.mtype and bid.ext.prebid.type are not defined', () => {
const serverResponse = deepClone(SAMPLE_RESPONSE);
delete serverResponse.body.seatbid[0].bid[0].mtype;
delete serverResponse.body.seatbid[0].bid[0].ext.prebid.type;
const request = spec.buildRequests(DEFAULT_BANNER_BID_REQUESTS, DEFAULT_BANNER_BIDDER_REQUEST)[0];
const bids = spec.interpretResponse(serverResponse, request);
expect(bids).to.be.empty;
});
});
describe('getUserSyncs', () => {
it('should return an empty array if iframe sync is not enabled', () => {
const syncs = spec.getUserSyncs({}, [SAMPLE_RESPONSE], null, null);
expect(syncs).to.deep.equal([]);
});
it('should return an array with iframe url', () => {
const syncs = spec.getUserSyncs({ iframeEnabled: true }, [SAMPLE_RESPONSE], null, null);
expect(syncs).to.deep.equal([{
type: 'iframe',
url: 'https://ads.sportslocalmedia.com/load-cookie.html?endpoint=akcelo'
}]);
});
it('should return an array with iframe URL and GDPR parameters', () => {
const gdprConsent = { gdprApplies: true, consentString: 'the_gdpr_consent' };
const syncs = spec.getUserSyncs({ iframeEnabled: true }, [SAMPLE_RESPONSE], gdprConsent, null);
expect(syncs[0].url).to.contain('?endpoint=akcelo&gdpr=1&gdpr_consent=the_gdpr_consent');
});
it('should return an array with iframe URL containing empty GDPR parameters when GDPR does not apply', () => {
const gdprConsent = { gdprApplies: false };
const syncs = spec.getUserSyncs({ iframeEnabled: true }, [SAMPLE_RESPONSE], gdprConsent, null);
expect(syncs[0].url).to.contain('?endpoint=akcelo&gdpr=0&gdpr_consent=');
});
it('should URI encode the GDPR consent string', () => {
const gdprConsent = { gdprApplies: true, consentString: 'the_gdpr_consent==' };
const syncs = spec.getUserSyncs({ iframeEnabled: true }, [SAMPLE_RESPONSE], gdprConsent, null);
expect(syncs[0].url).to.contain('?endpoint=akcelo&gdpr=1&gdpr_consent=the_gdpr_consent%3D%3D');
});
it('should return an array with iframe URL containing USP parameters when USP is defined', () => {
const uspConsent = 'the_usp_consent';
const syncs = spec.getUserSyncs({ iframeEnabled: true }, [SAMPLE_RESPONSE], null, uspConsent);
expect(syncs[0].url).to.contain('?endpoint=akcelo&us_privacy=the_usp_consent');
});
it('should URI encode the USP consent string', () => {
const uspConsent = 'the_usp_consent==';
const syncs = spec.getUserSyncs({ iframeEnabled: true }, [SAMPLE_RESPONSE], null, uspConsent);
expect(syncs[0].url).to.contain('?endpoint=akcelo&us_privacy=the_usp_consent%3D%3D');
});
});
});