forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalvadsBidAdapter_spec.js
More file actions
171 lines (149 loc) · 5.49 KB
/
alvadsBidAdapter_spec.js
File metadata and controls
171 lines (149 loc) · 5.49 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
import { expect } from 'chai';
import { spec } from 'modules/alvadsBidAdapter.js';
describe('ALVADS Bid Adapter', function() {
const bannerBid = {
bidId: 'banner-1',
mediaTypes: { banner: { sizes: [[320, 100]] } },
params: {
publisherId: 'D7DACCE3-C23D-4AB9-8FE6-9FF41BF32F8F',
tagid: 'zone-001',
bidfloor: 0.1,
userId: 'user-001'
}
};
const videoBid = {
bidId: 'video-1',
mediaTypes: { video: { playerSize: [[1280, 720]] } },
params: {
publisherId: 'D7DACCE3-C23D-4AB9-8FE6-9FF41BF32F8F',
bidfloor: 0.5,
userId: 'user-002',
language: 'en',
count: 1
}
};
const bidderRequestBanner = {
refererInfo: { page: "http://localhost:1200" },
gdprConsent: true,
uspConsent: '1YNN'
};
const bidderRequestVideo = {
refererInfo: { page: "https://instagram.com" },
gdprConsent: true,
uspConsent: '1YNN'
};
// -----------------------------
describe('isBidRequestValid', function() {
it('validates banner bid requests', function() {
expect(spec.isBidRequestValid(bannerBid)).to.be.true;
});
it('validates video bid requests', function() {
expect(spec.isBidRequestValid(videoBid)).to.be.true;
});
it('rejects invalid bid requests', function() {
expect(spec.isBidRequestValid({})).to.be.false;
});
});
// -----------------------------
describe('buildRequests', function() {
it('uses default endpoint if none provided', function() {
const requests = spec.buildRequests([bannerBid], bidderRequestBanner);
expect(requests[0].url).to.equal('https://helios-ads-qa-core.ssidevops.com/decision/openrtb');
});
it('uses custom endpoint from bid params', function() {
const customBid = {
...bannerBid,
params: { ...bannerBid.params, endpoint: 'https://helios-ads-qa-core.ssidevops.com/decision/openrtb' }
};
const requests = spec.buildRequests([customBid], bidderRequestBanner);
expect(requests[0].url).to.equal('https://helios-ads-qa-core.ssidevops.com/decision/openrtb');
});
it('builds correct banner request payload', function() {
const requests = spec.buildRequests([bannerBid], bidderRequestBanner);
const request = requests[0];
const data = JSON.parse(request.data);
expect(data.imp).to.have.lengthOf(1);
expect(data.imp[0].banner).to.deep.equal({ w: 320, h: 100 });
expect(data.imp[0].tagid).to.equal(bannerBid.params.tagid);
expect(data.site.publisher.id).to.equal(bannerBid.params.publisherId);
});
it('builds correct video request payload', function() {
const requests = spec.buildRequests([videoBid], bidderRequestVideo);
const request = requests[0];
const data = JSON.parse(request.data);
expect(data.imp).to.have.lengthOf(1);
expect(data.imp[0].video).to.deep.equal({ w: 1280, h: 720 });
});
});
// -----------------------------
describe('interpretResponse', function() {
it('returns empty array if no bids', function() {
const serverResponse = { body: { seatbid: [] } };
const result = spec.interpretResponse(serverResponse, { bid: bannerBid });
expect(result).to.have.lengthOf(0);
});
it('interprets banner bid response', function() {
const serverResponse = {
body: {
seatbid: [
{ bid: [{ impid: 'banner-1', price: 1.2, w: 320, h: 100, crid: 'c1', adm: '<div>ad</div>' }] }
],
cur: 'USD'
}
};
const result = spec.interpretResponse(serverResponse, { bid: bannerBid });
expect(result).to.have.lengthOf(1);
const r = result[0];
expect(r.mediaType).to.equal('banner');
expect(r.cpm).to.equal(1.2);
expect(r.ad).to.equal('<div>ad</div>');
expect(r.width).to.equal(320);
expect(r.height).to.equal(100);
expect(r.creativeId).to.equal('c1');
});
it('interprets video bid response', function() {
const serverResponse = {
body: {
seatbid: [
{ bid: [{ impid: 'video-1', price: 2.5, w: 1280, h: 720, crid: 'v1', adm: '<VAST></VAST>', ext: { vast_url: 'http://vast.url' }, adomain: ['example.com'] }] }
],
cur: 'USD'
}
};
const result = spec.interpretResponse(serverResponse, { bid: videoBid });
expect(result).to.have.lengthOf(1);
const r = result[0];
expect(r.mediaType).to.equal('video');
expect(r.cpm).to.equal(2.5);
expect(r.vastXml).to.equal('<VAST></VAST>');
expect(r.vastUrl).to.equal('http://vast.url');
expect(r.width).to.equal(1280);
expect(r.height).to.equal(720);
expect(r.creativeId).to.equal('v1');
expect(r.meta.advertiserDomains).to.deep.equal(['example.com']);
});
});
// -----------------------------
describe('onTimeout', function() {
it('calls logWarn with timeout data', function() {
const logs = [];
const original = spec.onTimeout;
spec.onTimeout = (data) => logs.push(data);
spec.onTimeout({ bidId: 'timeout-1' });
expect(logs).to.have.lengthOf(1);
expect(logs[0].bidId).to.equal('timeout-1');
spec.onTimeout = original;
});
});
describe('onBidWon', function() {
it('calls logInfo with bid won', function() {
const logs = [];
const original = spec.onBidWon;
spec.onBidWon = (bid) => logs.push(bid);
spec.onBidWon({ bidId: 'won-1' });
expect(logs).to.have.lengthOf(1);
expect(logs[0].bidId).to.equal('won-1');
spec.onBidWon = original;
});
});
});