From ea042d062c7fedc34199bd497f1ac955a9b25136 Mon Sep 17 00:00:00 2001 From: Kanchika - Automatad Date: Mon, 23 Mar 2020 17:11:56 +0530 Subject: [PATCH 01/16] added automatad bid adapter --- modules/automatadBidAdapter.js | 113 +++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 modules/automatadBidAdapter.js diff --git a/modules/automatadBidAdapter.js b/modules/automatadBidAdapter.js new file mode 100644 index 00000000000..7f5c9e09df3 --- /dev/null +++ b/modules/automatadBidAdapter.js @@ -0,0 +1,113 @@ +import {registerBidder} from '../src/adapters/bidderFactory'; +import * as utils from '../src/utils'; +import {BANNER} from '../src/mediaTypes'; +import {ajax} from '../src/ajax'; + +const BIDDER = 'automatad' + +const ENDPOINT_URL = 'https://rtb2.automatad.com/ortb2'; + +const DEFAULT_BID_TTL = 30; +const DEFAULT_CURRENCY = 'USD'; +const DEFAULT_NET_REVENUE = true; + +export const spec = { + code: BIDDER, + aliases: ['atd'], + supportedMediaTypes: [BANNER], + + isBidRequestValid: function (bid) { + // will receive request bid. check if have necessary params for bidding + return (bid && bid.hasOwnProperty('params') && bid.params.hasOwnProperty('siteId') && bid.params.hasOwnProperty('placementId') && bid.hasOwnProperty('mediaTypes') && bid.mediaTypes.hasOwnProperty('banner')); + }, + + buildRequests: function (validBidRequests, bidderRequest) { + if (!validBidRequests || !bidderRequest) { + return; + } + + const siteId = validBidRequests[0].params.siteId; + const placementId = validBidRequests[0].params.placementId; + + const impressions = validBidRequests.map(bidRequest => ({ + id: bidRequest.bidId, + banner: { + format: bidRequest.sizes.map(sizeArr => ({ + w: sizeArr[0], + h: sizeArr[1], + })) + }, + })); + + // params from bid request + const openrtbRequest = { + id: validBidRequests[0].auctionId, + imp: impressions, + site: { + id: siteId, + placement: placementId, + domain: window.location.hostname, + page: window.location.href, + ref: bidderRequest.refererInfo ? bidderRequest.refererInfo.referer || null : null, + }, + }; + + const payloadString = JSON.stringify(openrtbRequest); + return { + method: 'POST', + url: ENDPOINT_URL + '/resp', + data: payloadString, + options: { + contentType: 'application/json', + withCredentials: false, + crossOrigin: true, + }, + }; + }, + + interpretResponse: function (serverResponse, request) { + const bidResponses = []; + const response = (serverResponse || {}).body; + + if (response && response.seatbid && response.seatbid.length === 1 && response.seatbid[0].bid && response.seatbid[0].bid.length) { + response.seatbid[0].bid.forEach(bid => { + bidResponses.push({ + requestId: bid.impid, + cpm: bid.price, + ad: bid.adm, + adDomain: bid.adomain[0], + currency: DEFAULT_CURRENCY, + ttl: DEFAULT_BID_TTL, + creativeId: bid.crid, + width: bid.w, + height: bid.h, + netRevenue: DEFAULT_NET_REVENUE, + nurl: bid.nurl, + }) + }) + } else { + utils.logInfo('automatad :: no valid responses to interpret'); + } + + return bidResponses; + }, + onBidWon: function(bid) { + if (!bid.nurl) { return; } + const winUrl = bid.nurl.replace( + /\$\{AUCTION_PRICE\}/, + bid.cpm + ).replace( + /\$\{AUCTION_IMP_ID\}/, + bid.requestId + ).replace( + /\$\{AUCTION_CURRENCY\}/, + bid.currency + ).replace( + /\$\{AUCTION_ID\}/, + bid.auctionId + ); + ajax(winUrl, null) + }, + +}; +registerBidder(spec); From c2a3ab6f50653d305f2e2be0a282f07d4d4a3677 Mon Sep 17 00:00:00 2001 From: Kanchika - Automatad Date: Mon, 23 Mar 2020 17:13:16 +0530 Subject: [PATCH 02/16] added automatad bid adapter readme --- modules/automatadBidAdapter.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 modules/automatadBidAdapter.md diff --git a/modules/automatadBidAdapter.md b/modules/automatadBidAdapter.md new file mode 100644 index 00000000000..c9792f19b06 --- /dev/null +++ b/modules/automatadBidAdapter.md @@ -0,0 +1,34 @@ +# Overview + +``` +Module Name: Automatad Bid Adapter +Module Type: Bidder Adapter +Maintainer: '' +``` + +# Description + +Connects to automatad exchange for bids. + +automatad bid adapter supports Banner ads. + +# Test Parameters +``` +var adUnits = [ + { + code: 'banner-ad-div', + mediaTypes: { + banner: { + sizes: [[300, 250], [300,600]] + } + }, + bids: [{ + bidder: 'automatad', + params: { + siteId: 'someValue', + placementId: 'someValue' + } + }] + } +]; +``` From 2d98d8f5a85bfdb62c290ba16759dfe044a36338 Mon Sep 17 00:00:00 2001 From: Kanchika - Automatad Date: Mon, 23 Mar 2020 17:21:52 +0530 Subject: [PATCH 03/16] added automatad bidder adapter unit test --- test/spec/modules/automatadBidAdapter_spec.js | 114 ++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 test/spec/modules/automatadBidAdapter_spec.js diff --git a/test/spec/modules/automatadBidAdapter_spec.js b/test/spec/modules/automatadBidAdapter_spec.js new file mode 100644 index 00000000000..2eb57a6ae97 --- /dev/null +++ b/test/spec/modules/automatadBidAdapter_spec.js @@ -0,0 +1,114 @@ +import { expect } from 'chai' +import { spec, _getPlatform } from 'modules/automatadBidAdapter' +import { newBidder } from 'src/adapters/bidderFactory' + +describe('automatadBidAdapter', function () { + const adapter = newBidder(spec) + + let bidRequest = { + bidder: 'automatad', + params: {siteId: '123ad', placementId: '123abc345'}, + mediaTypes: { + banner: { + sizes: [[300, 600]], + } + }, + adUnitCode: 'some-ad-unit-code', + transactionId: '1465569e-52cc-4c36-88a1-7174cfef4b44', + sizes: [[300, 600]], + bidId: '123abc', + bidderRequestId: '3213887463c059', + auctionId: 'abc-123', + src: 'client', + bidRequestsCount: 1, + } + + describe('codes', function () { + it('should return a bidder code of automatad', function () { + expect(spec.code).to.equal('automatad') + }) + it('should alias atd', function () { + expect(spec.aliases.length > 0 && spec.aliases[0] === 'atd').to.be.true + }) + }) + + describe('isBidRequestValid', function () { + let inValidBid = Object.assign({}, bidRequest) + delete inValidBid.params + it('should return true if all params present', function () { + expect(spec.isBidRequestValid(bidRequest)).to.equal(true) + }) + + it('should return false if any parameter missing', function () { + expect(spec.isBidRequestValid(inValidBid)).to.be.false + }) + }) + + describe('buildRequests', function () { + let req = spec.buildRequests([ bidRequest ], { refererInfo: { } }) + let rdata + + it('should return request object', function () { + expect(req).to.not.be.null + }) + + it('should build request data', function () { + expect(req.data).to.not.be.null + }) + + it('should include one request', function () { + rdata = JSON.parse(req.data) + expect(rdata.imp.length).to.equal(1) + }) + + it('should include media types', function () { + let r = rdata.imp[0] + expect(r.media_types !== null).to.be.true + }) + + it('should include all publisher params', function () { + let r = rdata.imp[0] + expect(r.siteID !== null && r.placementID !== null).to.be.true + }) + }) + + describe('interpretResponse', function () { + it('should get the correct bid response', function () { + let expectedResponse = [{ + 'body': { + 'id': 'abc-123', + 'seatbid': [ + { + 'bid': [ + { + 'adm': '', + 'adomain': [ + 'someAdDomain' + ], + 'crid': 123, + 'h': 250, + 'id': 'bid1', + 'impid': '1', + 'nurl': '', + 'price': 0.3, + 'w': 300 + } + ] + } + ] + } + }]; + + let result = spec.interpretResponse(expectedResponse[0]); + expect(result).to.be.an('array').that.is.not.empty; + }); + + it('handles empty bid response', function () { + let response = { + body: '' + }; + let result = spec.interpretResponse(response); + expect(result.length).to.equal(0); + }); + }); +}) From 9b84d5716a9b95257d573a83d18f1e0beb88cdfe Mon Sep 17 00:00:00 2001 From: Kanchika - Automatad Date: Mon, 23 Mar 2020 17:25:13 +0530 Subject: [PATCH 04/16] updated maintainer email id for automatad adapter --- modules/automatadBidAdapter.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/automatadBidAdapter.md b/modules/automatadBidAdapter.md index c9792f19b06..56a4b53c067 100644 --- a/modules/automatadBidAdapter.md +++ b/modules/automatadBidAdapter.md @@ -3,7 +3,7 @@ ``` Module Name: Automatad Bid Adapter Module Type: Bidder Adapter -Maintainer: '' +Maintainer: tech@automatad.com ``` # Description From 85611aaa93bf8406395a6c27dc164cb5ed32731f Mon Sep 17 00:00:00 2001 From: Kanchika - Automatad Date: Mon, 23 Mar 2020 18:25:10 +0530 Subject: [PATCH 05/16] refactored automatadBidAdapter js --- modules/automatadBidAdapter.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/automatadBidAdapter.js b/modules/automatadBidAdapter.js index 7f5c9e09df3..a3f571d237a 100644 --- a/modules/automatadBidAdapter.js +++ b/modules/automatadBidAdapter.js @@ -1,7 +1,7 @@ -import {registerBidder} from '../src/adapters/bidderFactory'; -import * as utils from '../src/utils'; -import {BANNER} from '../src/mediaTypes'; -import {ajax} from '../src/ajax'; +import {registerBidder} from '../src/adapters/bidderFactory.js'; +import * as utils from '../src/utils.js'; +import {BANNER} from '../src/mediaTypes.js'; +import {ajax} from '../src/ajax.js'; const BIDDER = 'automatad' From 8ef416cba622c64f12ae2a30719e830b3276c5ac Mon Sep 17 00:00:00 2001 From: Kanchika - Automatad Date: Mon, 23 Mar 2020 18:26:24 +0530 Subject: [PATCH 06/16] refactored automatadBidAdapter unit test --- test/spec/modules/automatadBidAdapter_spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/spec/modules/automatadBidAdapter_spec.js b/test/spec/modules/automatadBidAdapter_spec.js index 2eb57a6ae97..67912157aee 100644 --- a/test/spec/modules/automatadBidAdapter_spec.js +++ b/test/spec/modules/automatadBidAdapter_spec.js @@ -1,6 +1,6 @@ import { expect } from 'chai' -import { spec, _getPlatform } from 'modules/automatadBidAdapter' -import { newBidder } from 'src/adapters/bidderFactory' +import { spec, _getPlatform } from 'modules/automatadBidAdapter.js' +import { newBidder } from 'src/adapters/bidderFactory.js' describe('automatadBidAdapter', function () { const adapter = newBidder(spec) From 70e395629ea449cf2392afb22c430b55fc768cf4 Mon Sep 17 00:00:00 2001 From: Kanchika - Automatad Date: Mon, 23 Mar 2020 19:12:27 +0530 Subject: [PATCH 07/16] refactored automatadBidAdapter unit test --- test/spec/modules/automatadBidAdapter_spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/spec/modules/automatadBidAdapter_spec.js b/test/spec/modules/automatadBidAdapter_spec.js index 67912157aee..d3f56043ea2 100644 --- a/test/spec/modules/automatadBidAdapter_spec.js +++ b/test/spec/modules/automatadBidAdapter_spec.js @@ -1,5 +1,5 @@ import { expect } from 'chai' -import { spec, _getPlatform } from 'modules/automatadBidAdapter.js' +import { spec } from 'modules/automatadBidAdapter.js' import { newBidder } from 'src/adapters/bidderFactory.js' describe('automatadBidAdapter', function () { From 1d1d2cdbeab44e4b61f3f9aaddacf432beabe596 Mon Sep 17 00:00:00 2001 From: Kanchika - Automatad Date: Mon, 23 Mar 2020 22:13:27 +0530 Subject: [PATCH 08/16] added usersync code to automatad bid adapter --- modules/automatadBidAdapter.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/modules/automatadBidAdapter.js b/modules/automatadBidAdapter.js index a3f571d237a..62f62bd09a8 100644 --- a/modules/automatadBidAdapter.js +++ b/modules/automatadBidAdapter.js @@ -91,6 +91,14 @@ export const spec = { return bidResponses; }, + getUserSyncs: function(syncOptions) { + if (syncOptions.iframeEnabled) { + return [{ + type: 'iframe', + url: 'https://rtb2.automatad.com/static/usersync/v1/async_usersync' + }]; + } + }, onBidWon: function(bid) { if (!bid.nurl) { return; } const winUrl = bid.nurl.replace( From 8c4c2a8b80f5c84c037fc997d1ef1d5ec1a47532 Mon Sep 17 00:00:00 2001 From: Kanchika - Automatad Date: Mon, 30 Mar 2020 04:28:38 +0530 Subject: [PATCH 09/16] Added unit test for onBidWon in automatadBidAdapter_spec --- test/spec/modules/automatadBidAdapter_spec.js | 66 +++++++++++-------- 1 file changed, 37 insertions(+), 29 deletions(-) diff --git a/test/spec/modules/automatadBidAdapter_spec.js b/test/spec/modules/automatadBidAdapter_spec.js index d3f56043ea2..41150a33c7e 100644 --- a/test/spec/modules/automatadBidAdapter_spec.js +++ b/test/spec/modules/automatadBidAdapter_spec.js @@ -22,6 +22,31 @@ describe('automatadBidAdapter', function () { src: 'client', bidRequestsCount: 1, } + + let expectedResponse = [{ + 'body': { + 'id': 'abc-123', + 'seatbid': [ + { + 'bid': [ + { + 'adm': '', + 'adomain': [ + 'someAdDomain' + ], + 'crid': 123, + 'h': 600, + 'id': 'bid1', + 'impid': '1', + 'nurl': '', + 'price': 0.5, + 'w': 300 + } + ] + } + ] + } + }] describe('codes', function () { it('should return a bidder code of automatad', function () { @@ -74,41 +99,24 @@ describe('automatadBidAdapter', function () { describe('interpretResponse', function () { it('should get the correct bid response', function () { - let expectedResponse = [{ - 'body': { - 'id': 'abc-123', - 'seatbid': [ - { - 'bid': [ - { - 'adm': '', - 'adomain': [ - 'someAdDomain' - ], - 'crid': 123, - 'h': 250, - 'id': 'bid1', - 'impid': '1', - 'nurl': '', - 'price': 0.3, - 'w': 300 - } - ] - } - ] - } - }]; - let result = spec.interpretResponse(expectedResponse[0]); expect(result).to.be.an('array').that.is.not.empty; - }); + }) it('handles empty bid response', function () { let response = { body: '' - }; + } let result = spec.interpretResponse(response); expect(result.length).to.equal(0); - }); - }); + }) + }) + describe('onBidWon', function () { + let serverResponses = spec.interpretResponse(expectedResponse[0]); + let wonbid = serverResponses[0]; + + it('Returns true is nurl is good/not blank', function () { + expect(wonbid.nurl).to.not.equal(''); + }) + }) }) From ce62f830ffbda5f98829e9616efe300c4a34b322 Mon Sep 17 00:00:00 2001 From: Kanchika - Automatad Date: Mon, 30 Mar 2020 05:09:50 +0530 Subject: [PATCH 10/16] removed trailing spaces --- test/spec/modules/automatadBidAdapter_spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/spec/modules/automatadBidAdapter_spec.js b/test/spec/modules/automatadBidAdapter_spec.js index 41150a33c7e..693074bf95d 100644 --- a/test/spec/modules/automatadBidAdapter_spec.js +++ b/test/spec/modules/automatadBidAdapter_spec.js @@ -22,7 +22,7 @@ describe('automatadBidAdapter', function () { src: 'client', bidRequestsCount: 1, } - + let expectedResponse = [{ 'body': { 'id': 'abc-123', From f35971192f278b580fca2a55e9fd940958eb4ae7 Mon Sep 17 00:00:00 2001 From: kanchika-automatad Date: Mon, 30 Mar 2020 05:10:27 +0530 Subject: [PATCH 11/16] removed trailing space --- test/spec/modules/automatadBidAdapter_spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/spec/modules/automatadBidAdapter_spec.js b/test/spec/modules/automatadBidAdapter_spec.js index 41150a33c7e..a867ba2259c 100644 --- a/test/spec/modules/automatadBidAdapter_spec.js +++ b/test/spec/modules/automatadBidAdapter_spec.js @@ -20,9 +20,9 @@ describe('automatadBidAdapter', function () { bidderRequestId: '3213887463c059', auctionId: 'abc-123', src: 'client', - bidRequestsCount: 1, + bidRequestsCount: 1 } - + let expectedResponse = [{ 'body': { 'id': 'abc-123', From 3897bce6c5a6d1a48799dec38709c28262647d42 Mon Sep 17 00:00:00 2001 From: kanchika-automatad Date: Mon, 30 Mar 2020 06:40:09 +0530 Subject: [PATCH 12/16] changes for getUserSync function --- modules/automatadBidAdapter.js | 6 ++---- test/spec/modules/automatadBidAdapter_spec.js | 10 ++++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/modules/automatadBidAdapter.js b/modules/automatadBidAdapter.js index 62f62bd09a8..31499c8db19 100644 --- a/modules/automatadBidAdapter.js +++ b/modules/automatadBidAdapter.js @@ -91,13 +91,11 @@ export const spec = { return bidResponses; }, - getUserSyncs: function(syncOptions) { - if (syncOptions.iframeEnabled) { + getUserSyncs: function(syncOptions,serverResponse) { return [{ type: 'iframe', url: 'https://rtb2.automatad.com/static/usersync/v1/async_usersync' - }]; - } + }] }, onBidWon: function(bid) { if (!bid.nurl) { return; } diff --git a/test/spec/modules/automatadBidAdapter_spec.js b/test/spec/modules/automatadBidAdapter_spec.js index a867ba2259c..3cd36997526 100644 --- a/test/spec/modules/automatadBidAdapter_spec.js +++ b/test/spec/modules/automatadBidAdapter_spec.js @@ -111,6 +111,16 @@ describe('automatadBidAdapter', function () { expect(result.length).to.equal(0); }) }) + + describe('getUserSyncs', function () { + it('should return iframe sync', function () { + let sync = spec.getUserSyncs() + expect(sync.length).to.equal(1) + expect(sync[0].type === 'iframe') + expect(typeof sync[0].url === 'string') + }) + }) + describe('onBidWon', function () { let serverResponses = spec.interpretResponse(expectedResponse[0]); let wonbid = serverResponses[0]; From 88d84a1e8727cf9aa52dbd37d88b973cdc703aae Mon Sep 17 00:00:00 2001 From: kanchika-automatad Date: Mon, 30 Mar 2020 06:48:34 +0530 Subject: [PATCH 13/16] lint error fixes --- modules/automatadBidAdapter.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/automatadBidAdapter.js b/modules/automatadBidAdapter.js index 31499c8db19..86738978a5b 100644 --- a/modules/automatadBidAdapter.js +++ b/modules/automatadBidAdapter.js @@ -91,11 +91,11 @@ export const spec = { return bidResponses; }, - getUserSyncs: function(syncOptions,serverResponse) { - return [{ - type: 'iframe', - url: 'https://rtb2.automatad.com/static/usersync/v1/async_usersync' - }] + getUserSyncs: function(syncOptions, serverResponse) { + return [{ + type: 'iframe', + url: 'https://rtb2.automatad.com/static/usersync/v1/async_usersync' + }] }, onBidWon: function(bid) { if (!bid.nurl) { return; } From c1305a0d0f7aac1f5263e01d71eac4a0caaa6fd5 Mon Sep 17 00:00:00 2001 From: kanchika-automatad Date: Mon, 30 Mar 2020 08:33:19 +0530 Subject: [PATCH 14/16] updated usersync url --- modules/automatadBidAdapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/automatadBidAdapter.js b/modules/automatadBidAdapter.js index 86738978a5b..6c1853ca881 100644 --- a/modules/automatadBidAdapter.js +++ b/modules/automatadBidAdapter.js @@ -94,7 +94,7 @@ export const spec = { getUserSyncs: function(syncOptions, serverResponse) { return [{ type: 'iframe', - url: 'https://rtb2.automatad.com/static/usersync/v1/async_usersync' + url: 'https://rtb2.automatad.com/ortb2/async_usersync' }] }, onBidWon: function(bid) { From 581472a2414826cf14155b7f62e20b7d028599e8 Mon Sep 17 00:00:00 2001 From: kanchika-automatad Date: Tue, 31 Mar 2020 02:34:38 +0530 Subject: [PATCH 15/16] additional test for onBidWon function added --- modules/automatadBidAdapter.js | 49 ++++++++++--------- test/spec/modules/automatadBidAdapter_spec.js | 15 +++--- 2 files changed, 33 insertions(+), 31 deletions(-) diff --git a/modules/automatadBidAdapter.js b/modules/automatadBidAdapter.js index 6c1853ca881..1f46c89536d 100644 --- a/modules/automatadBidAdapter.js +++ b/modules/automatadBidAdapter.js @@ -1,15 +1,15 @@ -import {registerBidder} from '../src/adapters/bidderFactory.js'; -import * as utils from '../src/utils.js'; -import {BANNER} from '../src/mediaTypes.js'; -import {ajax} from '../src/ajax.js'; +import {registerBidder} from '../src/adapters/bidderFactory.js' +import * as utils from '../src/utils.js' +import {BANNER} from '../src/mediaTypes.js' +import {ajax} from '../src/ajax.js' const BIDDER = 'automatad' -const ENDPOINT_URL = 'https://rtb2.automatad.com/ortb2'; +const ENDPOINT_URL = 'https://rtb2.automatad.com/ortb2' -const DEFAULT_BID_TTL = 30; -const DEFAULT_CURRENCY = 'USD'; -const DEFAULT_NET_REVENUE = true; +const DEFAULT_BID_TTL = 30 +const DEFAULT_CURRENCY = 'USD' +const DEFAULT_NET_REVENUE = true export const spec = { code: BIDDER, @@ -18,16 +18,16 @@ export const spec = { isBidRequestValid: function (bid) { // will receive request bid. check if have necessary params for bidding - return (bid && bid.hasOwnProperty('params') && bid.params.hasOwnProperty('siteId') && bid.params.hasOwnProperty('placementId') && bid.hasOwnProperty('mediaTypes') && bid.mediaTypes.hasOwnProperty('banner')); + return (bid && bid.hasOwnProperty('params') && bid.params.hasOwnProperty('siteId') && bid.params.hasOwnProperty('placementId') && bid.hasOwnProperty('mediaTypes') && bid.mediaTypes.hasOwnProperty('banner')) }, buildRequests: function (validBidRequests, bidderRequest) { if (!validBidRequests || !bidderRequest) { - return; + return } - const siteId = validBidRequests[0].params.siteId; - const placementId = validBidRequests[0].params.placementId; + const siteId = validBidRequests[0].params.siteId + const placementId = validBidRequests[0].params.placementId const impressions = validBidRequests.map(bidRequest => ({ id: bidRequest.bidId, @@ -37,7 +37,7 @@ export const spec = { h: sizeArr[1], })) }, - })); + })) // params from bid request const openrtbRequest = { @@ -50,9 +50,9 @@ export const spec = { page: window.location.href, ref: bidderRequest.refererInfo ? bidderRequest.refererInfo.referer || null : null, }, - }; + } - const payloadString = JSON.stringify(openrtbRequest); + const payloadString = JSON.stringify(openrtbRequest) return { method: 'POST', url: ENDPOINT_URL + '/resp', @@ -62,12 +62,12 @@ export const spec = { withCredentials: false, crossOrigin: true, }, - }; + } }, interpretResponse: function (serverResponse, request) { - const bidResponses = []; - const response = (serverResponse || {}).body; + const bidResponses = [] + const response = (serverResponse || {}).body if (response && response.seatbid && response.seatbid.length === 1 && response.seatbid[0].bid && response.seatbid[0].bid.length) { response.seatbid[0].bid.forEach(bid => { @@ -86,10 +86,10 @@ export const spec = { }) }) } else { - utils.logInfo('automatad :: no valid responses to interpret'); + utils.logInfo('automatad :: no valid responses to interpret') } - return bidResponses; + return bidResponses }, getUserSyncs: function(syncOptions, serverResponse) { return [{ @@ -98,7 +98,7 @@ export const spec = { }] }, onBidWon: function(bid) { - if (!bid.nurl) { return; } + if (!bid.nurl) { return } const winUrl = bid.nurl.replace( /\$\{AUCTION_PRICE\}/, bid.cpm @@ -111,9 +111,10 @@ export const spec = { ).replace( /\$\{AUCTION_ID\}/, bid.auctionId - ); + ) ajax(winUrl, null) + return true }, -}; -registerBidder(spec); +} +registerBidder(spec) diff --git a/test/spec/modules/automatadBidAdapter_spec.js b/test/spec/modules/automatadBidAdapter_spec.js index 3cd36997526..a7f5e2707a8 100644 --- a/test/spec/modules/automatadBidAdapter_spec.js +++ b/test/spec/modules/automatadBidAdapter_spec.js @@ -99,16 +99,16 @@ describe('automatadBidAdapter', function () { describe('interpretResponse', function () { it('should get the correct bid response', function () { - let result = spec.interpretResponse(expectedResponse[0]); - expect(result).to.be.an('array').that.is.not.empty; + let result = spec.interpretResponse(expectedResponse[0]) + expect(result).to.be.an('array').that.is.not.empty }) it('handles empty bid response', function () { let response = { body: '' } - let result = spec.interpretResponse(response); - expect(result.length).to.equal(0); + let result = spec.interpretResponse(response) + expect(result.length).to.equal(0) }) }) @@ -122,11 +122,12 @@ describe('automatadBidAdapter', function () { }) describe('onBidWon', function () { - let serverResponses = spec.interpretResponse(expectedResponse[0]); - let wonbid = serverResponses[0]; + let serverResponses = spec.interpretResponse(expectedResponse[0]) + let wonbid = serverResponses[0] it('Returns true is nurl is good/not blank', function () { - expect(wonbid.nurl).to.not.equal(''); + expect(wonbid.nurl).to.not.equal('') + expect(spec.onBidWon(wonbid)).to.be.true }) }) }) From 6a2bf79d3e1107344dc1e87b5e542b00c969bda1 Mon Sep 17 00:00:00 2001 From: kanchika-automatad Date: Mon, 6 Apr 2020 08:03:20 +0530 Subject: [PATCH 16/16] added ajax stub in test --- modules/automatadBidAdapter.js | 5 ++++- test/spec/modules/automatadBidAdapter_spec.js | 13 ++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/modules/automatadBidAdapter.js b/modules/automatadBidAdapter.js index 1f46c89536d..4a9e6b6a1e4 100644 --- a/modules/automatadBidAdapter.js +++ b/modules/automatadBidAdapter.js @@ -112,9 +112,12 @@ export const spec = { /\$\{AUCTION_ID\}/, bid.auctionId ) - ajax(winUrl, null) + spec.ajaxCall(winUrl, null) return true }, + ajaxCall: function(endpoint, data) { + ajax(endpoint, data) + }, } registerBidder(spec) diff --git a/test/spec/modules/automatadBidAdapter_spec.js b/test/spec/modules/automatadBidAdapter_spec.js index a7f5e2707a8..788fd3aefc4 100644 --- a/test/spec/modules/automatadBidAdapter_spec.js +++ b/test/spec/modules/automatadBidAdapter_spec.js @@ -38,7 +38,7 @@ describe('automatadBidAdapter', function () { 'h': 600, 'id': 'bid1', 'impid': '1', - 'nurl': '', + 'nurl': 'https://example/win', 'price': 0.5, 'w': 300 } @@ -124,10 +124,21 @@ describe('automatadBidAdapter', function () { describe('onBidWon', function () { let serverResponses = spec.interpretResponse(expectedResponse[0]) let wonbid = serverResponses[0] + let ajaxStub + + beforeEach(() => { + ajaxStub = sinon.stub(spec, 'ajaxCall') + }) + + afterEach(() => { + ajaxStub.restore() + }) it('Returns true is nurl is good/not blank', function () { expect(wonbid.nurl).to.not.equal('') expect(spec.onBidWon(wonbid)).to.be.true + expect(ajaxStub.calledOnce).to.equal(true) + expect(ajaxStub.firstCall.args[0].indexOf('https://')).to.equal(0) }) }) })