forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadponeBidAdapter_spec.js
More file actions
218 lines (201 loc) · 6.8 KB
/
adponeBidAdapter_spec.js
File metadata and controls
218 lines (201 loc) · 6.8 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
import { expect } from 'chai';
import { spec } from 'modules/adponeBidAdapter.js';
import { newBidder } from 'src/adapters/bidderFactory.js';
import * as utils from 'src/utils.js';
const EMPTY_ARRAY = [];
describe('adponeBidAdapter', function () {
const bid = {
bidder: 'adpone',
adUnitCode: 'adunit-code',
sizes: [[300, 250]],
bidId: '30b31c1838de1e',
bidderRequestId: '22edbae2733bf6',
auctionId: '1d1a030790a475',
params: {
placementId: '1',
}
};
describe('build requests', () => {
it('sends bid request to ENDPOINT via POST', function () {
const request = spec.buildRequests([
{
bidder: 'adpone',
adUnitCode: 'adunit-code',
sizes: [[300, 250]],
bidId: '30b31c1838de1e',
bidderRequestId: '22edbae2733bf6',
auctionId: '1d1a030790a475',
params: {
placementId: '1',
}
}
]);
expect(request[0].method).to.equal('POST');
});
it('sends bid request to adpone endpoint', function () {
const request = spec.buildRequests([
{
bidder: 'adpone',
adUnitCode: 'adunit-code',
sizes: [[300, 250]],
bidId: '30b31c1838de1e',
bidderRequestId: '22edbae2733bf6',
auctionId: '1d1a030790a475',
params: {
placementId: '1',
}
}
]);
expect(request[0].url).to.equal('https://rtb.adpone.com/bid-request?pid=1');
});
});
describe('inherited functions', () => {
const adapter = newBidder(spec);
it('exists and is a function', () => {
expect(adapter.callBids).to.exist.and.to.be.a('function');
});
});
describe('isBidRequestValid', function () {
it('should return true when necessary information is found', function () {
expect(spec.isBidRequestValid(bid)).to.be.true;
});
it('should return false when necessary information is not found', function () {
// empty bid
expect(spec.isBidRequestValid({ bidId: '', params: {} })).to.be.false;
// empty bidId
bid.bidId = '';
expect(spec.isBidRequestValid(bid)).to.be.false;
// empty placementId
bid.bidId = '30b31c1838de1e';
bid.params.placementId = '';
expect(spec.isBidRequestValid(bid)).to.be.false;
bid.adUnitCode = 'adunit-code';
});
it('returns false when bidder not set to "adpone"', function() {
const invalidBid = {
bidder: 'enopda',
adUnitCode: 'adunit-code',
sizes: [[300, 250]],
bidId: '30b31c1838de1e',
bidderRequestId: '22edbae2733bf6',
auctionId: '1d1a030790a475',
params: {
placementId: '1',
}
};
expect(spec.isBidRequestValid(invalidBid)).to.be.false;
});
it('returns false when placementId is not set in params', function() {
const invalidBid = {
bidder: 'adpone',
adUnitCode: 'adunit-code',
sizes: [[300, 250]],
bidId: '30b31c1838de1e',
bidderRequestId: '22edbae2733bf6',
auctionId: '1d1a030790a475',
params: {
}
};
expect(spec.isBidRequestValid(invalidBid)).to.be.false;
});
});
describe('interpretResponse', function () {
let serverResponse;
const bidRequest = { data: { id: '1234' } };
beforeEach(function () {
serverResponse = {
body: {
id: '2579e20c0bb89',
seatbid: [
{
bid: [
{
id: '613673EF-A07C-4486-8EE9-3FC71A7DC73D',
impid: '2579e20c0bb89_0',
price: 1,
adm: '<html><a href="https://www.adpone.com" target="_blank"><img src ="https://placehold.it/300x250" /></a></html>',
meta: {
adomain: [
'adpone.com'
]
},
iurl: 'https://localhost11',
crid: 'creative111',
h: 250,
w: 300,
ext: {
dspid: 6
}
}
],
seat: 'adpone'
}
],
cur: 'USD'
},
};
});
it('validate_response_params', function() {
const newResponse = spec.interpretResponse(serverResponse, bidRequest);
expect(newResponse[0].id).to.be.equal('613673EF-A07C-4486-8EE9-3FC71A7DC73D');
expect(newResponse[0].requestId).to.be.equal('1234');
expect(newResponse[0].cpm).to.be.equal(1);
expect(newResponse[0].width).to.be.equal(300);
expect(newResponse[0].height).to.be.equal(250);
expect(newResponse[0].currency).to.be.equal('USD');
expect(newResponse[0].netRevenue).to.be.equal(true);
expect(newResponse[0].ttl).to.be.equal(300);
expect(newResponse[0].ad).to.be.equal('<html><a href="https://www.adpone.com" target="_blank"><img src ="https://placehold.it/300x250" /></a></html>');
});
it('should correctly reorder the server response', function () {
const newResponse = spec.interpretResponse(serverResponse, bidRequest);
expect(newResponse.length).to.be.equal(1);
expect(newResponse[0]).to.deep.equal({
id: '613673EF-A07C-4486-8EE9-3FC71A7DC73D',
meta: {
advertiserDomains: [
'adpone.com'
]
},
requestId: '1234',
cpm: 1,
width: 300,
height: 250,
creativeId: 'creative111',
currency: 'USD',
netRevenue: true,
ttl: 300,
ad: '<html><a href="https://www.adpone.com" target="_blank"><img src ="https://placehold.it/300x250" /></a></html>'
});
});
it('should not add responses if the cpm is 0 or null', function () {
serverResponse.body.seatbid[0].bid[0].price = 0;
let response = spec.interpretResponse(serverResponse, bidRequest);
expect(response).to.deep.equal([]);
serverResponse.body.seatbid[0].bid[0].price = null;
response = spec.interpretResponse(serverResponse, bidRequest);
expect(response).to.deep.equal([])
});
it('should add responses if the cpm is valid', function () {
serverResponse.body.seatbid[0].bid[0].price = 0.5;
const response = spec.interpretResponse(serverResponse, bidRequest);
expect(response).to.not.deep.equal([]);
});
});
describe('test onBidWon function', function () {
beforeEach(function() {
sinon.stub(utils, 'triggerPixel');
});
afterEach(function() {
utils.triggerPixel.restore();
});
it('exists and is a function', () => {
expect(spec.onBidWon).to.exist.and.to.be.a('function');
});
it('should return nothing', function () {
var response = spec.onBidWon({});
expect(response).to.be.an('undefined')
expect(utils.triggerPixel.called).to.equal(true);
});
});
});