Skip to content

Commit 06b4742

Browse files
iprom-adserverGašper Žagar
authored andcommitted
iPROM adapter upload - adapter (prebid#6334)
Co-authored-by: Gašper Žagar <[email protected]>
1 parent bb3acb9 commit 06b4742

File tree

3 files changed

+299
-0
lines changed

3 files changed

+299
-0
lines changed

modules/ipromBidAdapter.js

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import * as utils from '../src/utils.js';
2+
import { registerBidder } from '../src/adapters/bidderFactory.js';
3+
4+
const BIDDER_CODE = 'iprom';
5+
const ENDPOINT_URL = 'https://core.iprom.net/programmatic';
6+
const VERSION = 'v1.0.0';
7+
const DEFAULT_CURRENCY = 'EUR';
8+
const DEFAULT_NETREVENUE = true;
9+
const DEFAULT_TTL = 360;
10+
11+
export const spec = {
12+
code: BIDDER_CODE,
13+
isBidRequestValid: function ({ bidder, params = {} } = {}) {
14+
// id parameter checks
15+
if (!params.id) {
16+
utils.logError(`${bidder}: Parameter 'id' missing`);
17+
return false;
18+
} else if (typeof params.id !== 'string') {
19+
utils.logError(`${bidder}: Parameter 'id' needs to be a string`);
20+
return false;
21+
}
22+
// dimension parameter checks
23+
if (!params.dimension) {
24+
utils.logError(`${bidder}: Required parameter 'dimension' missing`);
25+
return false;
26+
} else if (typeof params.dimension !== 'string') {
27+
utils.logError(`${bidder}: Parameter 'dimension' needs to be a string`);
28+
return false;
29+
}
30+
31+
return true;
32+
},
33+
34+
buildRequests: function (validBidRequests, bidderRequest) {
35+
const payload = {
36+
bids: validBidRequests,
37+
referer: bidderRequest.refererInfo,
38+
version: VERSION
39+
};
40+
const payloadString = JSON.stringify(payload);
41+
42+
return {
43+
method: 'POST',
44+
url: ENDPOINT_URL,
45+
data: payloadString
46+
};
47+
},
48+
49+
interpretResponse: function (serverResponse, request) {
50+
let bids = serverResponse.body;
51+
52+
const bidResponses = [];
53+
54+
bids.forEach(bid => {
55+
bidResponses.push({
56+
ad: bid.ad,
57+
requestId: bid.requestId,
58+
cpm: bid.cpm,
59+
width: bid.width,
60+
height: bid.height,
61+
creativeId: bid.creativeId,
62+
currency: bid.currency || DEFAULT_CURRENCY,
63+
netRevenue: bid.netRevenue || DEFAULT_NETREVENUE,
64+
ttl: bid.ttl || DEFAULT_TTL,
65+
});
66+
});
67+
68+
return bidResponses;
69+
},
70+
}
71+
72+
registerBidder(spec);

modules/ipromBidAdapter.md

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Overview
2+
3+
```
4+
Module Name: Iprom PreBid Adapter
5+
Module Type: Bidder Adapter
6+
Maintainer: [email protected]
7+
```
8+
9+
# Description
10+
11+
Module that connects to Iprom's demand sources
12+
13+
# Test Parameters
14+
```
15+
var adUnits = [
16+
{
17+
code: 'test-div',
18+
mediaTypes: {
19+
banner: {
20+
sizes: [[300, 250]], // a display size
21+
}
22+
},
23+
bids: [
24+
{
25+
bidder: "iprom",
26+
params: {
27+
id: '1234',
28+
dimension: '300x250'
29+
}
30+
}
31+
]
32+
}
33+
];
34+
```
+193
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
import {expect} from 'chai';
2+
import {spec} from 'modules/ipromBidAdapter.js';
3+
4+
describe('iPROM Adapter', function () {
5+
let bidRequests;
6+
let bidderRequest;
7+
8+
beforeEach(function () {
9+
bidRequests = [
10+
{
11+
bidder: 'iprom',
12+
params: {
13+
id: '1234',
14+
dimension: '300x250',
15+
},
16+
adUnitCode: '/19966331/header-bid-tag-1',
17+
mediaTypes: {
18+
banner: {
19+
sizes: [[300, 250], [300, 600]],
20+
}
21+
},
22+
bidId: '29a72b151f7bd3',
23+
auctionId: 'e36abb27-g3b1-1ad6-8a4c-701c8919d3hh',
24+
bidderRequestId: '2z76da40m1b3cb8',
25+
transactionId: 'j51lhf58-1ad6-g3b1-3j6s-912c9493g0gu'
26+
}
27+
];
28+
29+
bidderRequest = {
30+
timeout: 3000,
31+
refererInfo: {
32+
referer: 'https://adserver.si/index.html',
33+
reachedTop: true,
34+
numIframes: 1,
35+
stack: [
36+
'https://adserver.si/index.html',
37+
'https://adserver.si/iframe1.html',
38+
]
39+
}
40+
}
41+
});
42+
43+
describe('validating bids', function () {
44+
it('should accept valid bid', function () {
45+
let validBid = {
46+
bidder: 'iprom',
47+
params: {
48+
id: '1234',
49+
dimension: '300x250',
50+
},
51+
};
52+
53+
const isValid = spec.isBidRequestValid(validBid);
54+
55+
expect(isValid).to.equal(true);
56+
});
57+
58+
it('should reject bid if missing dimension and id', function () {
59+
let invalidBid = {
60+
bidder: 'iprom',
61+
params: {}
62+
};
63+
64+
const isValid = spec.isBidRequestValid(invalidBid);
65+
66+
expect(isValid).to.equal(false);
67+
});
68+
69+
it('should reject bid if missing dimension', function () {
70+
let invalidBid = {
71+
bidder: 'iprom',
72+
params: {
73+
id: '1234',
74+
}
75+
};
76+
77+
const isValid = spec.isBidRequestValid(invalidBid);
78+
79+
expect(isValid).to.equal(false);
80+
});
81+
82+
it('should reject bid if dimension is not a string', function () {
83+
let invalidBid = {
84+
bidder: 'iprom',
85+
params: {
86+
id: '1234',
87+
dimension: 404,
88+
}
89+
};
90+
91+
const isValid = spec.isBidRequestValid(invalidBid);
92+
93+
expect(isValid).to.equal(false);
94+
});
95+
96+
it('should reject bid if missing id', function () {
97+
let invalidBid = {
98+
bidder: 'iprom',
99+
params: {
100+
dimension: '300x250',
101+
}
102+
};
103+
104+
const isValid = spec.isBidRequestValid(invalidBid);
105+
106+
expect(isValid).to.equal(false);
107+
});
108+
109+
it('should reject bid if id is not a string', function () {
110+
let invalidBid = {
111+
bidder: 'iprom',
112+
params: {
113+
id: 1234,
114+
dimension: '300x250',
115+
}
116+
};
117+
118+
const isValid = spec.isBidRequestValid(invalidBid);
119+
120+
expect(isValid).to.equal(false);
121+
});
122+
});
123+
124+
describe('building requests', function () {
125+
it('should go to correct endpoint', function () {
126+
const request = spec.buildRequests(bidRequests, bidderRequest);
127+
128+
expect(request.method).to.exist;
129+
expect(request.method).to.equal('POST');
130+
expect(request.url).to.exist;
131+
expect(request.url).to.equal('https://core.iprom.net/programmatic');
132+
});
133+
134+
it('should add referer info', function () {
135+
const request = spec.buildRequests(bidRequests, bidderRequest);
136+
const requestparse = JSON.parse(request.data);
137+
138+
expect(requestparse.referer).to.exist;
139+
expect(requestparse.referer.referer).to.equal('https://adserver.si/index.html');
140+
});
141+
142+
it('should add adapter version', function () {
143+
const request = spec.buildRequests(bidRequests, bidderRequest);
144+
const requestparse = JSON.parse(request.data);
145+
146+
expect(requestparse.version).to.exist;
147+
});
148+
149+
it('should contain id and dimension', function () {
150+
const request = spec.buildRequests(bidRequests, bidderRequest);
151+
const requestparse = JSON.parse(request.data);
152+
153+
expect(requestparse.bids[0].params.id).to.equal('1234');
154+
expect(requestparse.bids[0].params.dimension).to.equal('300x250');
155+
});
156+
});
157+
158+
describe('handling responses', function () {
159+
it('should return complete bid response', function () {
160+
const serverResponse = {
161+
body: [{
162+
requestId: '29a72b151f7bd3',
163+
cpm: 0.5,
164+
width: '300',
165+
height: '250',
166+
creativeId: 1234,
167+
ad: '<html><head><title>Iprom Header bidding example</title></head><body><img src="https://iprom.si/files/2015/08/iprom-logo.svg"></body></html>'
168+
}
169+
]};
170+
171+
const request = spec.buildRequests(bidRequests, bidderRequest);
172+
const bids = spec.interpretResponse(serverResponse, request);
173+
174+
expect(bids).to.be.lengthOf(1);
175+
expect(bids[0].requestId).to.equal('29a72b151f7bd3');
176+
expect(bids[0].cpm).to.equal(0.5);
177+
expect(bids[0].width).to.equal('300');
178+
expect(bids[0].height).to.equal('250');
179+
expect(bids[0].ad).to.have.length.above(1);
180+
});
181+
182+
it('should return empty bid response', function () {
183+
const emptyServerResponse = {
184+
body: []
185+
};
186+
187+
const request = spec.buildRequests(bidRequests, bidderRequest);
188+
const bids = spec.interpretResponse(emptyServerResponse, request);
189+
190+
expect(bids).to.be.lengthOf(0);
191+
});
192+
});
193+
});

0 commit comments

Comments
 (0)