Skip to content

Commit 1df6a22

Browse files
authored
cointrafficBidAdapter: added support responding in different currencies (#5800)
* New adapter "Cointraffic" added * removed mobile detection * The sizes property has been updated, added supportedMediaTypes. * feat: added support responding in different currencies * change: module description
1 parent 9573a42 commit 1df6a22

File tree

3 files changed

+149
-14
lines changed

3 files changed

+149
-14
lines changed

modules/cointrafficBidAdapter.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
import * as utils from '../src/utils.js';
2-
import {registerBidder} from '../src/adapters/bidderFactory.js';
3-
import {BANNER} from '../src/mediaTypes.js'
2+
import { registerBidder } from '../src/adapters/bidderFactory.js';
3+
import { BANNER } from '../src/mediaTypes.js'
4+
import { config } from '../src/config.js'
45

56
const BIDDER_CODE = 'cointraffic';
67
const ENDPOINT_URL = 'https://appspb.cointraffic.io/pb/tmp';
8+
const DEFAULT_CURRENCY = 'EUR';
9+
const ALLOWED_CURRENCIES = [
10+
'EUR', 'USD', 'JPY', 'BGN', 'CZK', 'DKK', 'GBP', 'HUF', 'PLN', 'RON', 'SEK', 'CHF', 'ISK', 'NOK', 'HRK', 'RUB', 'TRY',
11+
'AUD', 'BRL', 'CAD', 'CNY', 'HKD', 'IDR', 'ILS', 'INR', 'KRW', 'MXN', 'MYR', 'NZD', 'PHP', 'SGD', 'THB', 'ZAR',
12+
];
713

814
export const spec = {
915
code: BIDDER_CODE,
@@ -29,9 +35,19 @@ export const spec = {
2935
buildRequests: function (validBidRequests, bidderRequest) {
3036
return validBidRequests.map(bidRequest => {
3137
const sizes = utils.parseSizesInput(bidRequest.params.size || bidRequest.sizes);
38+
const currency =
39+
config.getConfig(`currency.bidderCurrencyDefault.${BIDDER_CODE}`) ||
40+
config.getConfig('currency.adServerCurrency') ||
41+
DEFAULT_CURRENCY;
42+
43+
if (ALLOWED_CURRENCIES.indexOf(currency) === -1) {
44+
utils.logError('Currency is not supported - ' + currency);
45+
return;
46+
}
3247

3348
const payload = {
3449
placementId: bidRequest.params.placementId,
50+
currency: currency,
3551
sizes: sizes,
3652
bidId: bidRequest.bidId,
3753
referer: bidderRequest.refererInfo.referer,

modules/cointrafficBidAdapter.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ Maintainer: [email protected]
77
```
88

99
# Description
10-
The Cointraffic client module makes it easy to implement Cointraffic directly into your website. To get started, simply replace the ``placementId`` with your assigned tracker key. This is dependent on the size required by your account dashboard. For additional information on this module, please contact us at ``[email protected]``.
10+
The Cointraffic client module makes it easy to implement Cointraffic directly into your website. To get started, simply replace the ``placementId`` with your assigned tracker key. This is dependent on the size required by your account dashboard.
11+
We support response in different currencies. Supported currencies listed [here](https://www.ecb.europa.eu/stats/policy_and_exchange_rates/euro_reference_exchange_rates/html/index.en.html).
12+
13+
For additional information on this module, please contact us at ``[email protected]``.
1114

1215
# Test Parameters
1316
```

test/spec/modules/cointrafficBidAdapter_spec.js

Lines changed: 127 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { expect } from 'chai';
22
import { spec } from 'modules/cointrafficBidAdapter.js';
3+
import { config } from 'src/config.js'
4+
import * as utils from 'src/utils.js'
35

46
const ENDPOINT_URL = 'https://appspb.cointraffic.io/pb/tmp';
57

@@ -37,7 +39,7 @@ describe('cointrafficBidAdapter', function () {
3739
],
3840
bidId: 'bidId12345',
3941
bidderRequestId: 'bidderRequestId12345',
40-
auctionId: 'auctionId12345',
42+
auctionId: 'auctionId12345'
4143
},
4244
{
4345
bidder: 'cointraffic',
@@ -50,7 +52,7 @@ describe('cointrafficBidAdapter', function () {
5052
],
5153
bidId: 'bidId67890"',
5254
bidderRequestId: 'bidderRequestId67890',
53-
auctionId: 'auctionId12345',
55+
auctionId: 'auctionId12345'
5456
}
5557
];
5658

@@ -65,34 +67,71 @@ describe('cointrafficBidAdapter', function () {
6567
}
6668
};
6769

68-
const request = spec.buildRequests(bidRequests, bidderRequests);
70+
it('replaces currency with EUR if there is no currency provided', function () {
71+
const request = spec.buildRequests(bidRequests, bidderRequests);
72+
73+
expect(request[0].data.currency).to.equal('EUR');
74+
expect(request[1].data.currency).to.equal('EUR');
75+
});
76+
77+
it('replaces currency with EUR if there is no currency provided', function () {
78+
const getConfigStub = sinon.stub(config, 'getConfig').callsFake(
79+
arg => arg === 'currency.bidderCurrencyDefault.cointraffic' ? 'USD' : 'EUR'
80+
);
81+
82+
const request = spec.buildRequests(bidRequests, bidderRequests);
83+
84+
expect(request[0].data.currency).to.equal('USD');
85+
expect(request[1].data.currency).to.equal('USD');
86+
87+
getConfigStub.restore();
88+
});
89+
90+
it('throws an error if currency provided in params is not allowed', function () {
91+
const utilsMock = sinon.mock(utils).expects('logError').twice()
92+
const getConfigStub = sinon.stub(config, 'getConfig').callsFake(
93+
arg => arg === 'currency.bidderCurrencyDefault.cointraffic' ? 'BTC' : 'EUR'
94+
);
95+
96+
const request = spec.buildRequests(bidRequests, bidderRequests);
97+
98+
expect(request[0]).to.undefined;
99+
expect(request[1]).to.undefined;
100+
101+
utilsMock.restore()
102+
getConfigStub.restore();
103+
});
69104

70105
it('sends bid request to our endpoint via POST', function () {
106+
const request = spec.buildRequests(bidRequests, bidderRequests);
107+
71108
expect(request[0].method).to.equal('POST');
72109
expect(request[1].method).to.equal('POST');
73110
});
111+
74112
it('attaches source and version to endpoint URL as query params', function () {
113+
const request = spec.buildRequests(bidRequests, bidderRequests);
114+
75115
expect(request[0].url).to.equal(ENDPOINT_URL);
76116
expect(request[1].url).to.equal(ENDPOINT_URL);
77117
});
78118
});
79119

80120
describe('interpretResponse', function () {
81-
let bidRequest = [
82-
{
121+
it('should get the correct bid response', function () {
122+
let bidRequest = [{
83123
method: 'POST',
84124
url: ENDPOINT_URL,
85125
data: {
86126
placementId: 'testPlacementId',
87127
device: 'desktop',
128+
currency: 'EUR',
88129
sizes: ['300x250'],
89130
bidId: 'bidId12345',
90131
referer: 'www.example.com'
91132
}
92-
}
93-
];
133+
}];
94134

95-
it('should get the correct bid response', function () {
96135
let serverResponse = {
97136
body: {
98137
requestId: 'bidId12345',
@@ -103,7 +142,7 @@ describe('cointrafficBidAdapter', function () {
103142
height: 250,
104143
creativeId: 'creativeId12345',
105144
ttl: 90,
106-
ad: '<html><h3>I am an ad</h3></html> ',
145+
ad: '<html><h3>I am an ad</h3></html> '
107146
}
108147
};
109148

@@ -118,22 +157,99 @@ describe('cointrafficBidAdapter', function () {
118157
ttl: 90,
119158
ad: '<html><h3>I am an ad</h3></html>'
120159
}];
160+
121161
let result = spec.interpretResponse(serverResponse, bidRequest[0]);
122162
expect(Object.keys(result)).to.deep.equal(Object.keys(expectedResponse));
123163
});
124164

125-
it('should get empty bid response if server response body is empty', function () {
165+
it('should get the correct bid response with different currency', function () {
166+
let bidRequest = [{
167+
method: 'POST',
168+
url: ENDPOINT_URL,
169+
data: {
170+
placementId: 'testPlacementId',
171+
device: 'desktop',
172+
currency: 'USD',
173+
sizes: ['300x250'],
174+
bidId: 'bidId12345',
175+
referer: 'www.example.com'
176+
}
177+
}];
178+
126179
let serverResponse = {
127-
body: {}
180+
body: {
181+
requestId: 'bidId12345',
182+
cpm: 3.9,
183+
currency: 'USD',
184+
netRevenue: true,
185+
width: 300,
186+
height: 250,
187+
creativeId: 'creativeId12345',
188+
ttl: 90,
189+
ad: '<html><h3>I am an ad</h3></html> '
190+
}
128191
};
129192

193+
let expectedResponse = [{
194+
requestId: 'bidId12345',
195+
cpm: 3.9,
196+
currency: 'USD',
197+
netRevenue: true,
198+
width: 300,
199+
height: 250,
200+
creativeId: 'creativeId12345',
201+
ttl: 90,
202+
ad: '<html><h3>I am an ad</h3></html>'
203+
}];
204+
205+
const getConfigStub = sinon.stub(config, 'getConfig').returns('USD');
206+
207+
let result = spec.interpretResponse(serverResponse, bidRequest[0]);
208+
expect(Object.keys(result)).to.deep.equal(Object.keys(expectedResponse));
209+
210+
getConfigStub.restore();
211+
});
212+
213+
it('should get empty bid response requested currency is not available', function () {
214+
let bidRequest = [{
215+
method: 'POST',
216+
url: ENDPOINT_URL,
217+
data: {
218+
placementId: 'testPlacementId',
219+
device: 'desktop',
220+
currency: 'BTC',
221+
sizes: ['300x250'],
222+
bidId: 'bidId12345',
223+
referer: 'www.example.com'
224+
}
225+
}];
226+
227+
let serverResponse = {};
228+
130229
let expectedResponse = [];
131230

231+
const getConfigStub = sinon.stub(config, 'getConfig').returns('BTC');
232+
132233
let result = spec.interpretResponse(serverResponse, bidRequest[0]);
133234
expect(Object.keys(result)).to.deep.equal(Object.keys(expectedResponse));
235+
236+
getConfigStub.restore();
134237
});
135238

136239
it('should get empty bid response if no server response', function () {
240+
let bidRequest = [{
241+
method: 'POST',
242+
url: ENDPOINT_URL,
243+
data: {
244+
placementId: 'testPlacementId',
245+
device: 'desktop',
246+
currency: 'EUR',
247+
sizes: ['300x250'],
248+
bidId: 'bidId12345',
249+
referer: 'www.example.com'
250+
}
251+
}];
252+
137253
let serverResponse = {};
138254

139255
let expectedResponse = [];

0 commit comments

Comments
 (0)