From dce630283cdac31f5a133770e40248655be586b2 Mon Sep 17 00:00:00 2001 From: logicad Date: Wed, 24 Jul 2019 00:33:16 +0900 Subject: [PATCH] Add Logicad for Publishers bid adapter (#4010) * Add Logicad for Publishers bid adapter * Add test code --- modules/logicadBidAdapter.js | 68 +++++++++++ modules/logicadBidAdapter.md | 25 ++++ test/spec/modules/logicadBidAdapter_spec.js | 119 ++++++++++++++++++++ 3 files changed, 212 insertions(+) create mode 100644 modules/logicadBidAdapter.js create mode 100644 modules/logicadBidAdapter.md create mode 100644 test/spec/modules/logicadBidAdapter_spec.js diff --git a/modules/logicadBidAdapter.js b/modules/logicadBidAdapter.js new file mode 100644 index 00000000000..65d765c30a3 --- /dev/null +++ b/modules/logicadBidAdapter.js @@ -0,0 +1,68 @@ +import {registerBidder} from '../src/adapters/bidderFactory'; +import {BANNER} from '../src/mediaTypes'; + +const BIDDER_CODE = 'logicad'; +const ENDPOINT_URL = 'https://pb.ladsp.com/adrequest/prebid'; + +export const spec = { + code: BIDDER_CODE, + supportedMediaTypes: [BANNER], + isBidRequestValid: function (bid) { + return !!(bid.params && bid.params.tid); + }, + buildRequests: function (bidRequests, bidderRequest) { + const requests = []; + for (let i = 0, len = bidRequests.length; i < len; i++) { + const request = { + method: 'POST', + url: ENDPOINT_URL, + data: JSON.stringify(newBidRequest(bidRequests[i], bidderRequest)), + options: {}, + bidderRequest + }; + requests.push(request); + } + return requests; + }, + interpretResponse: function (serverResponse, bidderRequest) { + serverResponse = serverResponse.body; + const bids = []; + if (!serverResponse || serverResponse.error) { + return bids; + } + serverResponse.seatbid.forEach(function (seatbid) { + bids.push(seatbid.bid); + }) + return bids; + }, + getUserSyncs: function (syncOptions, serverResponses) { + if (serverResponses.length > 0 && serverResponses[0].body.userSync && + syncOptions.pixelEnabled && serverResponses[0].body.userSync.type == 'image') { + return [{ + type: 'image', + url: serverResponses[0].body.userSync.url + }]; + } + return []; + }, +}; + +function newBidRequest(bid, bidderRequest) { + return { + auctionId: bid.auctionId, + bidderRequestId: bid.bidderRequestId, + bids: [{ + adUnitCode: bid.adUnitCode, + bidId: bid.bidId, + transactionId: bid.transactionId, + sizes: bid.sizes, + params: bid.params, + mediaTypes: bid.mediaTypes + }], + prebidJsVersion: '$prebid.version$', + referrer: bidderRequest.refererInfo.referer, + auctionStartTime: bidderRequest.auctionStart, + }; +} + +registerBidder(spec); diff --git a/modules/logicadBidAdapter.md b/modules/logicadBidAdapter.md new file mode 100644 index 00000000000..32d40a7d3cd --- /dev/null +++ b/modules/logicadBidAdapter.md @@ -0,0 +1,25 @@ +# Overview +``` +Module Name: Logicad for Publishers +Module Type: Bidder Adapter +Maintainer: prebid@so-netmedia.jp +``` + +# Description +Module that connects to Logicad's demand sources. +Currently module supports only banner mediaType. + +# Test Parameters +``` + var adUnits = [{ + code: 'test-code', + sizes: [[300, 250],[300, 600]], + bids: [{ + bidder: 'logicad', + params: { + tid: 'test', + page: 'url', + } + }] + }]; +``` diff --git a/test/spec/modules/logicadBidAdapter_spec.js b/test/spec/modules/logicadBidAdapter_spec.js new file mode 100644 index 00000000000..7d2916e3e0f --- /dev/null +++ b/test/spec/modules/logicadBidAdapter_spec.js @@ -0,0 +1,119 @@ +import {expect} from 'chai'; +import {spec} from '../../../modules/logicadBidAdapter'; +import * as utils from 'src/utils'; + +describe('LogicadAdapter', function () { + const bidRequests = [{ + bidder: 'logicad', + bidId: '51ef8751f9aead', + params: { + tid: 'PJ2P', + page: 'http://www.logicad.com/' + }, + adUnitCode: 'div-gpt-ad-1460505748561-0', + transactionId: 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec', + sizes: [[300, 250], [300, 600]], + bidderRequestId: '418b37f85e772c', + auctionId: '18fd8b8b0bd757', + mediaTypes: { + banner: { + sizes: [[300, 250], [300, 600]] + } + } + }]; + const bidderRequest = { + refererInfo: { + referer: 'fakeReferer', + reachedTop: true, + numIframes: 1, + stack: [] + }, + auctionStart: 1563337198010 + }; + const serverResponse = { + body: { + seatbid: + [{ + bid: { + requestId: '51ef8751f9aead', + cpm: 101.0234, + width: 300, + height: 250, + creativeId: '2019', + currency: 'JPY', + netRevenue: true, + ttl: 60, + ad: '
TEST
' + } + }], + userSync: { + type: 'image', + url: 'https://cr-p31.ladsp.jp/cookiesender/31' + } + } + }; + + describe('isBidRequestValid', function () { + it('should return true if the tid parameter is present', function () { + expect(spec.isBidRequestValid(bidRequests[0])).to.be.true; + }); + + it('should return false if the tid parameter is not present', function () { + let bidRequest = utils.deepClone(bidRequests[0]); + delete bidRequest.params.tid; + expect(spec.isBidRequestValid(bidRequest)).to.be.false; + }); + + it('should return false if the params object is not present', function () { + let bidRequest = utils.deepClone(bidRequests); + delete bidRequest[0].params; + expect(spec.isBidRequestValid(bidRequest)).to.be.false; + }); + }); + + describe('buildRequests', function () { + it('should generate a valid single POST request for multiple bid requests', function () { + const request = spec.buildRequests(bidRequests, bidderRequest)[0]; + expect(request.method).to.equal('POST'); + expect(request.url).to.equal('https://pb.ladsp.com/adrequest/prebid'); + expect(request.data).to.exist; + }); + }); + + describe('interpretResponse', function () { + it('should return an empty array if an invalid response is passed', function () { + const interpretedResponse = spec.interpretResponse({}, {}); + expect(interpretedResponse).to.be.an('array').that.is.empty; + }); + + it('should return valid response when passed valid server response', function () { + const request = spec.buildRequests(bidRequests, bidderRequest)[0]; + const interpretedResponse = spec.interpretResponse(serverResponse, request); + + expect(interpretedResponse).to.have.lengthOf(1); + + expect(interpretedResponse[0].requestId).to.equal(serverResponse.body.seatbid[0].bid.requestId); + expect(interpretedResponse[0].cpm).to.equal(serverResponse.body.seatbid[0].bid.cpm); + expect(interpretedResponse[0].width).to.equal(serverResponse.body.seatbid[0].bid.width); + expect(interpretedResponse[0].height).to.equal(serverResponse.body.seatbid[0].bid.height); + expect(interpretedResponse[0].creativeId).to.equal(serverResponse.body.seatbid[0].bid.creativeId); + expect(interpretedResponse[0].currency).to.equal(serverResponse.body.seatbid[0].bid.currency); + expect(interpretedResponse[0].netRevenue).to.equal(serverResponse.body.seatbid[0].bid.netRevenue); + expect(interpretedResponse[0].ad).to.equal(serverResponse.body.seatbid[0].bid.ad); + expect(interpretedResponse[0].ttl).to.equal(serverResponse.body.seatbid[0].bid.ttl); + }); + }); + + describe('getUserSyncs', function () { + it('should perform usersync', function () { + let syncs = spec.getUserSyncs({pixelEnabled: false}, [serverResponse]); + expect(syncs).to.have.length(0); + console.log(serverResponse); + syncs = spec.getUserSyncs({pixelEnabled: true}, [serverResponse]); + expect(syncs).to.have.length(1); + + expect(syncs[0]).to.have.property('type', 'image'); + expect(syncs[0]).to.have.property('url', 'https://cr-p31.ladsp.jp/cookiesender/31'); + }); + }); +});