Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New bid adapter: Wipes #5051

Merged
merged 12 commits into from
Apr 8, 2020
Merged
69 changes: 69 additions & 0 deletions modules/wipesBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import * as utils from '../src/utils.js';
import {config} from '../src/config.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {VIDEO} from '../src/mediaTypes.js';

const BIDDER_CODE = 'wipes';
const ALIAS_BIDDER_CODE = ['wi'];
const SUPPORTED_MEDIA_TYPES = [VIDEO]
const ENDPOINT_URL = 'https://adn-srv.reckoner-api.com/v1/prebid';

function isBidRequestValid(bid) {
switch (true) {
case !!(bid.params.asid):
break;
default:
utils.logWarn(`isBidRequestValid Error. ${bid.params}, please check your implementation.`);
return false;
}
return true;
}

function buildRequests(validBidRequests, bidderRequest) {
return validBidRequests.map(bidRequest => {
const params = bidRequest.params;
const asid = params.asid;
return {
method: 'GET',
url: ENDPOINT_URL,
data: {
asid: asid
}
}
});
}

function interpretResponse(serverResponse, bidRequest) {
const bidResponses = [];
const response = serverResponse.body;
const cpm = response.cpm * 1000 || 0;
if (cpm !== 0) {
const netRevenue = (response.netRevenue === undefined) ? true : response.netRevenue;
const bidResponse = {
requestId: response.uuid,
cpm: cpm,
width: response.width,
height: response.height,
creativeId: response.videoCreativeId || 0,
dealId: response.dealId,
currency: 'JPY',
netRevenue: netRevenue,
ttl: config.getConfig('_bidderTimeout'),
referrer: bidRequest.data.r || '',
mediaType: VIDEO,
ad: response.adTag,
musikele marked this conversation as resolved.
Show resolved Hide resolved
};
bidResponses.push(bidResponse);
}
return bidResponses;
}

export const spec = {
code: BIDDER_CODE,
aliases: ALIAS_BIDDER_CODE,
isBidRequestValid,
buildRequests,
interpretResponse,
supportedMediaTypes: SUPPORTED_MEDIA_TYPES
}
registerBidder(spec);
28 changes: 28 additions & 0 deletions modules/wipesBidAdapter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Overview

```
Module Name: WIPES Bidder Adapter
Module Type: Bidder Adapter
Maintainer: contact@3-shake.com
```

# Description

Connect to WIPES for bids.
Publishers needs to be set up and approved by WIPES team to enable this adapter.
Please contact support@wipestream.com for further information.

# Test Parameters
```javascript
var adUnits = [
musikele marked this conversation as resolved.
Show resolved Hide resolved
// Video adUnit
{
code: 'video-div',
bids: [{
bidder: 'wipes',
params: {
asid: 'XXXXXXXXXX'
}
}]
}]
```
148 changes: 148 additions & 0 deletions test/spec/modules/wipesBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
import {expect} from 'chai';
import {spec} from 'modules/wipesBidAdapter.js';
import {newBidder} from 'src/adapters/bidderFactory.js';

const ENDPOINT_URL = 'https://adn-srv.reckoner-api.com/v1/prebid';

describe('wipesBidAdapter', function () {
const adapter = newBidder(spec);

describe('isBidRequestValid', function () {
let bid = {
'bidder': 'wipes',
'params': {
asid: 'dWyPondh2EGB_bNlrVjzIXRZO9F0k1dpo0I8ZvQ'
},
'adUnitCode': 'adunit-code',
'bidId': '51ef8751f9aead',
'bidderRequestId': '15246a574e859f',
'auctionId': 'b06c5141-fe8f-4cdf-9d7d-54415490a917',
};

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

it('should return false when asid not passed correctly', function () {
bid.params.asid = '';
expect(spec.isBidRequestValid(bid)).to.equal(false);
});

it('should return false when require params are not passed', function () {
let bid = Object.assign({}, bid);
bid.params = {};
expect(spec.isBidRequestValid(bid)).to.equal(false);
});
});

describe('buildRequests', function () {
let bidRequests = [
{
'bidder': 'wipes',
'params': {
asid: 'dWyPondh2EGB_bNlrVjzIXRZO9F0k1dpo0I8ZvQ'
},
'adUnitCode': 'adunit-code',
'bidId': '51ef8751f9aead',
'bidderRequestId': '15246a574e859f',
'auctionId': 'b06c5141-fe8f-4cdf-9d7d-54415490a917',
},
{
'bidder': 'wipes',
'params': {
asid: 'dWyPondh2EGB_bNlrVjzIXRZO9F0k1dpo0I8ZvQ'
},
'adUnitCode': 'adunit-code2',
'bidId': '51ef8751f9aead',
'bidderRequestId': '15246a574e859f',
'auctionId': 'b06c5141-fe8f-4cdf-9d7d-54415490a917',
}
];

let bidderRequest = {
refererInfo: {
numIframes: 0,
reachedTop: true,
referer: 'http://example.com',
stack: ['http://example.com']
}
};

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

it('sends bid request to our endpoint via GET', function () {
expect(request[0].method).to.equal('GET');
expect(request[1].method).to.equal('GET');
});

it('attaches source and version to endpoint URL as query params', function () {
expect(request[0].url).to.equal(ENDPOINT_URL);
expect(request[1].url).to.equal(ENDPOINT_URL);
});

it('adUnitCode should be sent as uc parameters on any requests', function () {
expect(request[0].data.asid).to.equal('dWyPondh2EGB_bNlrVjzIXRZO9F0k1dpo0I8ZvQ');
expect(request[1].data.asid).to.equal('dWyPondh2EGB_bNlrVjzIXRZO9F0k1dpo0I8ZvQ');
});
});

describe('interpretResponse', function () {
let bidRequestVideo = [
{
'method': 'GET',
'url': ENDPOINT_URL,
'data': {
'asid': 'dWyPondh2EGB_bNlrVjzIXRZO9F0k1dpo0I8ZvQ',
}
}
];

let serverResponseVideo = {
body: {
'uuid': 'a42947f8-f8fd-4cf7-bb72-31a87ab1f6ff',
'adTag': '<!-- adtag -->',
'height': 160,
'width': 300,
'cpm': 850,
'statusMessage': '',
'currency': 'JPY',
'videoCreativeId': 600004
}
};

it('should get the correct bid response for video', function () {
let expectedResponse = [{
'requestId': '23beaa6af6cdde',
'cpm': 850,
'width': 300,
'height': 160,
'creativeId': '600004',
'dealId': undefined,
'currency': 'JPY',
'netRevenue': true,
'ttl': 3000,
'referrer': '',
'mediaType': 'video',
'ad': '<!-- adtag -->'
}];
let result = spec.interpretResponse(serverResponseVideo, bidRequestVideo[0]);
expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse[0]));
expect(result[0].mediaType).to.equal(expectedResponse[0].mediaType);
});

it('handles empty bid response', function () {
let response = {
body: {
'uid': 'a42947f8-f8fd-4cf7-bb72-31a87ab1f6ff',
'height': 0,
'crid': '',
'statusMessage': '',
'width': 0,
'cpm': 0
}
};
let result = spec.interpretResponse(response, bidRequestVideo[0]);
expect(result.length).to.equal(0);
});
});
});