Skip to content

Commit

Permalink
Cointraffic Bid Adapter: domain change (#9580)
Browse files Browse the repository at this point in the history
* domain change

* added types in tests
  • Loading branch information
stsepelin authored Feb 23, 2023
1 parent 7be7080 commit 7d1d1a9
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 17 deletions.
8 changes: 4 additions & 4 deletions modules/cointrafficBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@ import { BANNER } from '../src/mediaTypes.js'
import { config } from '../src/config.js'

const BIDDER_CODE = 'cointraffic';
const ENDPOINT_URL = 'https://apps-pbd.ctengine.io/pb/tmp';
const ENDPOINT_URL = 'https://apps-pbd.ctraffic.io/pb/tmp';
const DEFAULT_CURRENCY = 'EUR';
const ALLOWED_CURRENCIES = [
'EUR', 'USD', 'JPY', 'BGN', 'CZK', 'DKK', 'GBP', 'HUF', 'PLN', 'RON', 'SEK', 'CHF', 'ISK', 'NOK', 'HRK', 'RUB', 'TRY',
'AUD', 'BRL', 'CAD', 'CNY', 'HKD', 'IDR', 'ILS', 'INR', 'KRW', 'MXN', 'MYR', 'NZD', 'PHP', 'SGD', 'THB', 'ZAR',
];

/** @type {BidderSpec} */
export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [BANNER],

/**
* Determines whether or not the given bid request is valid.
* Determines whether the given bid request is valid.
*
* @param {BidRequest} bid The bid params to validate.
* @return boolean True if this is a valid bid, and false otherwise.
Expand Down Expand Up @@ -50,8 +51,7 @@ export const spec = {
currency: currency,
sizes: sizes,
bidId: bidRequest.bidId,
// TODO: is 'page' the right value here?
referer: bidderRequest.refererInfo.page,
referer: bidderRequest.refererInfo.ref,
};

return {
Expand Down
84 changes: 71 additions & 13 deletions test/spec/modules/cointrafficBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import sinon from 'sinon'
import { expect } from 'chai';
import { spec } from 'modules/cointrafficBidAdapter.js';
import { config } from 'src/config.js'
import * as utils from 'src/utils.js'

const ENDPOINT_URL = 'https://apps-pbd.ctengine.io/pb/tmp';
const ENDPOINT_URL = 'https://apps-pbd.ctraffic.io/pb/tmp';

describe('cointrafficBidAdapter', function () {
describe('isBidRequestValid', function () {
let bid = {
/** @type {BidRequest} */
let bidRequest = {
bidder: 'cointraffic',
params: {
placementId: 'testPlacementId'
Expand All @@ -22,11 +24,12 @@ describe('cointrafficBidAdapter', function () {
};

it('should return true where required params found', function () {
expect(spec.isBidRequestValid(bid)).to.equal(true);
expect(spec.isBidRequestValid(bidRequest)).to.equal(true);
});
});

describe('buildRequests', function () {
/** @type {BidRequest[]} */
let bidRequests = [
{
bidder: 'cointraffic',
Expand Down Expand Up @@ -56,7 +59,8 @@ describe('cointrafficBidAdapter', function () {
}
];

let bidderRequests = {
/** @type {BidderRequest} */
let bidderRequest = {
refererInfo: {
numIframes: 0,
reachedTop: true,
Expand All @@ -68,7 +72,7 @@ describe('cointrafficBidAdapter', function () {
};

it('replaces currency with EUR if there is no currency provided', function () {
const request = spec.buildRequests(bidRequests, bidderRequests);
const request = spec.buildRequests(bidRequests, bidderRequest);

expect(request[0].data.currency).to.equal('EUR');
expect(request[1].data.currency).to.equal('EUR');
Expand All @@ -79,7 +83,7 @@ describe('cointrafficBidAdapter', function () {
arg => arg === 'currency.bidderCurrencyDefault.cointraffic' ? 'USD' : 'EUR'
);

const request = spec.buildRequests(bidRequests, bidderRequests);
const request = spec.buildRequests(bidRequests, bidderRequest);

expect(request[0].data.currency).to.equal('USD');
expect(request[1].data.currency).to.equal('USD');
Expand All @@ -93,7 +97,7 @@ describe('cointrafficBidAdapter', function () {
arg => arg === 'currency.bidderCurrencyDefault.cointraffic' ? 'BTC' : 'EUR'
);

const request = spec.buildRequests(bidRequests, bidderRequests);
const request = spec.buildRequests(bidRequests, bidderRequest);

expect(request[0]).to.undefined;
expect(request[1]).to.undefined;
Expand All @@ -103,14 +107,14 @@ describe('cointrafficBidAdapter', function () {
});

it('sends bid request to our endpoint via POST', function () {
const request = spec.buildRequests(bidRequests, bidderRequests);
const request = spec.buildRequests(bidRequests, bidderRequest);

expect(request[0].method).to.equal('POST');
expect(request[1].method).to.equal('POST');
});

it('attaches source and version to endpoint URL as query params', function () {
const request = spec.buildRequests(bidRequests, bidderRequests);
const request = spec.buildRequests(bidRequests, bidderRequest);

expect(request[0].url).to.equal(ENDPOINT_URL);
expect(request[1].url).to.equal(ENDPOINT_URL);
Expand All @@ -119,6 +123,7 @@ describe('cointrafficBidAdapter', function () {

describe('interpretResponse', function () {
it('should get the correct bid response', function () {
/** @type {BidRequest[]} */
let bidRequest = [{
method: 'POST',
url: ENDPOINT_URL,
Expand All @@ -142,7 +147,7 @@ describe('cointrafficBidAdapter', function () {
height: 250,
creativeId: 'creativeId12345',
ttl: 90,
ad: '<html><h3>I am an ad</h3></html> ',
ad: '<html lang="en"><h3>I am an ad</h3></html> ',
mediaType: 'banner',
adomain: ['test.com']
}
Expand All @@ -157,7 +162,7 @@ describe('cointrafficBidAdapter', function () {
height: 250,
creativeId: 'creativeId12345',
ttl: 90,
ad: '<html><h3>I am an ad</h3></html>',
ad: '<html lang="en"><h3>I am an ad</h3></html>',
meta: {
mediaType: 'banner',
advertiserDomains: [
Expand All @@ -170,7 +175,58 @@ describe('cointrafficBidAdapter', function () {
expect(Object.keys(result)).to.deep.equal(Object.keys(expectedResponse));
});

it('should get the correct bid response without advertiser domains specified', function () {
/** @type {BidRequest[]} */
let bidRequest = [{
method: 'POST',
url: ENDPOINT_URL,
data: {
placementId: 'testPlacementId',
device: 'desktop',
currency: 'EUR',
sizes: ['300x250'],
bidId: 'bidId12345',
referer: 'www.example.com'
}
}];

let serverResponse = {
body: {
requestId: 'bidId12345',
cpm: 3.9,
currency: 'EUR',
netRevenue: true,
width: 300,
height: 250,
creativeId: 'creativeId12345',
ttl: 90,
ad: '<html lang="en"><h3>I am an ad</h3></html> ',
mediaType: 'banner',
}
};

let expectedResponse = [{
requestId: 'bidId12345',
cpm: 3.9,
currency: 'EUR',
netRevenue: true,
width: 300,
height: 250,
creativeId: 'creativeId12345',
ttl: 90,
ad: '<html lang="en"><h3>I am an ad</h3></html>',
meta: {
mediaType: 'banner',
advertiserDomains: []
}
}];

let result = spec.interpretResponse(serverResponse, bidRequest[0]);
expect(Object.keys(result)).to.deep.equal(Object.keys(expectedResponse));
});

it('should get the correct bid response with different currency', function () {
/** @type {BidRequest[]} */
let bidRequest = [{
method: 'POST',
url: ENDPOINT_URL,
Expand All @@ -194,7 +250,7 @@ describe('cointrafficBidAdapter', function () {
height: 250,
creativeId: 'creativeId12345',
ttl: 90,
ad: '<html><h3>I am an ad</h3></html> ',
ad: '<html lang="en"><h3>I am an ad</h3></html> ',
mediaType: 'banner',
adomain: ['test.com']
}
Expand All @@ -209,7 +265,7 @@ describe('cointrafficBidAdapter', function () {
height: 250,
creativeId: 'creativeId12345',
ttl: 90,
ad: '<html><h3>I am an ad</h3></html>',
ad: '<html lang="en"><h3>I am an ad</h3></html>',
meta: {
mediaType: 'banner',
advertiserDomains: [
Expand All @@ -227,6 +283,7 @@ describe('cointrafficBidAdapter', function () {
});

it('should get empty bid response requested currency is not available', function () {
/** @type {BidRequest[]} */
let bidRequest = [{
method: 'POST',
url: ENDPOINT_URL,
Expand All @@ -253,6 +310,7 @@ describe('cointrafficBidAdapter', function () {
});

it('should get empty bid response if no server response', function () {
/** @type {BidRequest[]} */
let bidRequest = [{
method: 'POST',
url: ENDPOINT_URL,
Expand Down

0 comments on commit 7d1d1a9

Please sign in to comment.