From e75bf5fc83c9170fd5ada89d3663a042d8606aea Mon Sep 17 00:00:00 2001 From: symplorpro Date: Sat, 30 Nov 2024 16:12:07 +0530 Subject: [PATCH 01/10] feature: Rediads bid adapter --- modules/rediadsBidAdapter.js | 75 +++++++++++ modules/rediadsBidAdapter.md | 36 +++++ test/spec/modules/rediadsBidAdapter_spec.js | 140 ++++++++++++++++++++ 3 files changed, 251 insertions(+) create mode 100644 modules/rediadsBidAdapter.js create mode 100644 modules/rediadsBidAdapter.md create mode 100644 test/spec/modules/rediadsBidAdapter_spec.js diff --git a/modules/rediadsBidAdapter.js b/modules/rediadsBidAdapter.js new file mode 100644 index 00000000000..7f016e99cc9 --- /dev/null +++ b/modules/rediadsBidAdapter.js @@ -0,0 +1,75 @@ +import { ortbConverter } from '../libraries/ortbConverter/converter.js'; +import { registerBidder } from '../src/adapters/bidderFactory.js'; +import { deepSetValue } from '../src/utils.js'; +import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js'; +import { config } from '../src/config.js'; + +const BIDDER_CODE = 'rediads'; +const ENDPOINT_URL = 'https://stagingbidding.rediads.com/openrtb2/auction'; +const DEFAULT_CURRENCY = 'USD'; + +const MEDIA_TYPES = { + [BANNER]: 1, + [VIDEO]: 2, + [NATIVE]: 4, +}; + +const converter = ortbConverter({ + context: { + netRevenue: true, + ttl: 300, + currency: DEFAULT_CURRENCY, + }, + bidResponse(buildBidResponse, bid, context) { + let mediaType; + if (bid.video) { + mediaType = 'video'; // Video-specific response handling + } else if (bid.native) { + mediaType = 'native'; // Native-specific response handling + } else { + mediaType = 'banner'; // Default to banner + } + bid.mediaType = mediaType; + bid.mtype = MEDIA_TYPES[mediaType]; + + if (bid.mediaType === BANNER) { + bid.ad = bid.adm; + } + return buildBidResponse(bid, context); + }, +}); + +export const spec = { + code: BIDDER_CODE, + supportedMediaTypes: [NATIVE, BANNER, VIDEO], + isBidRequestValid: function (bid) { + return !!(bid.params && bid.params.accountID); + }, + buildRequests(bidRequests, bidderRequest) { + const accountID = bidRequests[0]?.params?.accountID; + const data = converter.toORTB({ bidRequests, bidderRequest }); + // deepSetValue(data.imp[0], 'ext.prebid.bidder', { + // amx: { tagId: 'dnV1a2xlLmNvbQ' }, + // }); + + deepSetValue(data, 'test', 1); + deepSetValue(data, 'ext.rediads.account_id', accountID?.toString()); + deepSetValue(data, 'site.content', config.getConfig('content')); + return [ + { + method: 'POST', + url: ENDPOINT_URL, + data, + }, + ]; + }, + interpretResponse(response, request) { + const bids = converter.fromORTB({ + response: response.body, + request: request.data, + }).bids; + return bids; + }, +}; + +registerBidder(spec); diff --git a/modules/rediadsBidAdapter.md b/modules/rediadsBidAdapter.md new file mode 100644 index 00000000000..5db6a156719 --- /dev/null +++ b/modules/rediadsBidAdapter.md @@ -0,0 +1,36 @@ +# Overview + +``` +Module Name: RediAds Bid Adapter +Module Type: Bidder Adapter +Maintainer: support@rediads.com +``` + +# Description + +Connect to RediAds exchange for bids. + +The RediAds adapter requires setup and approval. +Please reach out to support@rediads.com for more information. + +# Test Parameters +``` + var adUnits = [ + { + code: 'test-div', + mediaTypes: { + banner: { + sizes: [[300, 250]] + } + }, + bids: [ + { + bidder: "rediads", + params: { + accountID: 123 + } + } + ] + } + ]; +``` diff --git a/test/spec/modules/rediadsBidAdapter_spec.js b/test/spec/modules/rediadsBidAdapter_spec.js new file mode 100644 index 00000000000..24e310d5ca8 --- /dev/null +++ b/test/spec/modules/rediadsBidAdapter_spec.js @@ -0,0 +1,140 @@ +import { spec } from 'modules/rediadsBidAdapter'; +import { deepSetValue } from 'src/utils.js'; +import { config } from 'src/config.js'; +import { expect } from 'chai'; +import sinon from 'sinon'; + +// Test for isBidRequestValid +describe('isBidRequestValid', function() { + it('should return true if accountID is present', function() { + const bidRequest = { + params: { + accountID: '12345', + }, + }; + const result = spec.isBidRequestValid(bidRequest); + expect(result).to.be.true; + }); + + it('should return false if accountID is missing', function() { + const bidRequest = { + params: {}, + }; + const result = spec.isBidRequestValid(bidRequest); + expect(result).to.be.false; + }); +}); + +// Test for buildRequests +describe('buildRequests', function() { + it('should build a valid request with account_id and test flag', function() { + const bidRequests = [{ + params: { + accountID: '12345', + }, + }]; + const bidderRequest = {}; // Mock bidderRequest if needed + + // Mock config.getConfig('content') to return a valid value + sinon.stub(config, 'getConfig').returns('content_value'); + + const requests = spec.buildRequests(bidRequests, bidderRequest); + + const data = requests[0].data; + expect(data).to.have.property('test', 1); + expect(data).to.have.property('ext'); + expect(data.ext).to.have.property('rediads.account_id', '12345'); + expect(data.site).to.have.property('content', 'content_value'); + expect(requests[0].url).to.equal('https://stagingbidding.rediads.com/openrtb2/auction'); + + // Restore the stub after the test + sinon.restore(); + }); +}); + +// Test for interpretResponse +describe('interpretResponse', function() { + it('should correctly interpret the OpenRTB response and return bids', function() { + const mockResponse = { + body: { + bids: [ + { + requestId: '123', + cpm: 1.5, + ad: '', + mediaType: 'banner', + currency: 'USD', + ttl: 300, + }, + ], + }, + }; + + const request = { + data: { + test: 1, + ext: { + rediads: { + account_id: '12345', + }, + }, + }, + }; + + const bids = spec.interpretResponse(mockResponse, request); + + expect(bids).to.have.lengthOf(1); + expect(bids[0]).to.have.property('requestId', '123'); + expect(bids[0]).to.have.property('cpm', 1.5); + expect(bids[0]).to.have.property('ad', ''); + expect(bids[0]).to.have.property('mediaType', 'banner'); + }); +}); + +// Test for Default Values (Currency, Net Revenue) +describe('Default Values', function() { + it('should set the default currency as USD', function() { + const bidRequest = { + params: { + accountID: '12345', + }, + }; + const request = spec.buildRequests([bidRequest], {}); + expect(request[0].data.ext.rediads.account_id).to.equal('12345'); + expect(request[0].data.ext.rediads.currency).to.equal('USD'); + }); + + it('should set netRevenue to true', function() { + const bidRequest = { + params: { + accountID: '12345', + }, + }; + const request = spec.buildRequests([bidRequest], {}); + expect(request[0].data.ext.rediads.netRevenue).to.be.true; + }); +}); + +// Test for Media Type Handling +describe('Media Type Handling', function() { + it('should assign "banner" as mediaType by default', function() { + const bid = { adm: '', mediaType: 'banner' }; + const result = spec.converter.bidResponse(() => {}, bid, {}); + expect(result.mediaType).to.equal('banner'); + expect(result.mtype).to.equal(1); // BANNER = 1 + }); + + it('should assign "video" when video object exists', function() { + const bid = { video: {}, mediaType: 'video' }; + const result = spec.converter.bidResponse(() => {}, bid, {}); + expect(result.mediaType).to.equal('video'); + expect(result.mtype).to.equal(2); // VIDEO = 2 + }); + + it('should assign "native" when native object exists', function() { + const bid = { native: {}, mediaType: 'native' }; + const result = spec.converter.bidResponse(() => {}, bid, {}); + expect(result.mediaType).to.equal('native'); + expect(result.mtype).to.equal(4); // NATIVE = 4 + }); +}); From 965e5c0ac84337722db6913068fc8b3f17ffee72 Mon Sep 17 00:00:00 2001 From: Symplor Date: Sat, 30 Nov 2024 19:08:27 +0530 Subject: [PATCH 02/10] Test Cases updated | Bid Adapter improved --- modules/rediadsBidAdapter.js | 74 +++-- test/spec/modules/rediadsBidAdapter_spec.js | 305 ++++++++++++-------- 2 files changed, 233 insertions(+), 146 deletions(-) diff --git a/modules/rediadsBidAdapter.js b/modules/rediadsBidAdapter.js index 7f016e99cc9..17063283ac5 100644 --- a/modules/rediadsBidAdapter.js +++ b/modules/rediadsBidAdapter.js @@ -1,12 +1,14 @@ import { ortbConverter } from '../libraries/ortbConverter/converter.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; -import { deepSetValue } from '../src/utils.js'; +import { deepSetValue, logWarn, logError } from '../src/utils.js'; import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js'; import { config } from '../src/config.js'; const BIDDER_CODE = 'rediads'; -const ENDPOINT_URL = 'https://stagingbidding.rediads.com/openrtb2/auction'; +const ENDPOINT_URL = 'https://bidding.rediads.com/openrtb2/auction'; +const STAGING_ENDPOINT_URL = 'https://stagingbidding.rediads.com/openrtb2/auction'; const DEFAULT_CURRENCY = 'USD'; +const LOG_PREFIX = 'Rediads: '; const MEDIA_TYPES = { [BANNER]: 1, @@ -21,14 +23,14 @@ const converter = ortbConverter({ currency: DEFAULT_CURRENCY, }, bidResponse(buildBidResponse, bid, context) { - let mediaType; - if (bid.video) { - mediaType = 'video'; // Video-specific response handling - } else if (bid.native) { - mediaType = 'native'; // Native-specific response handling - } else { - mediaType = 'banner'; // Default to banner + let mediaType = 'banner'; // Default media type + + if (bid.vastXml || bid.vastUrl) { + mediaType = 'video'; + } else if (bid.adm && bid.adm.includes('"native"') && bid.adm.includes('"assets"')) { + mediaType = 'native'; } + bid.mediaType = mediaType; bid.mtype = MEDIA_TYPES[mediaType]; @@ -43,31 +45,57 @@ export const spec = { code: BIDDER_CODE, supportedMediaTypes: [NATIVE, BANNER, VIDEO], isBidRequestValid: function (bid) { - return !!(bid.params && bid.params.accountID); + let isValid = false; + const accountID = bid?.params?.account_id + if (accountID && typeof accountID === 'string') { + isValid = true; + } else { + logError(`${LOG_PREFIX} account_id is missing from params or is not of type "string"`) + } + return isValid; }, buildRequests(bidRequests, bidderRequest) { - const accountID = bidRequests[0]?.params?.accountID; - const data = converter.toORTB({ bidRequests, bidderRequest }); - // deepSetValue(data.imp[0], 'ext.prebid.bidder', { - // amx: { tagId: 'dnV1a2xlLmNvbQ' }, - // }); + const params = bidRequests[0]?.params || {}; + let data = {}; + let FINAL_ENDPOINT_URL = params.endpoint || ENDPOINT_URL + try { + const data = converter.toORTB({ bidRequests, bidderRequest }); + const testBidsRequested = location.hash.includes('rediads-test-bids'); + const stagingEnvRequested = location.hash.includes('rediads-staging'); + + if (stagingEnvRequested) { + FINAL_ENDPOINT_URL = STAGING_ENDPOINT_URL; + } + + deepSetValue(data, 'ext.rediads.params', params); + deepSetValue(data, 'site.content', config.getConfig('content')); + + if (testBidsRequested) { + deepSetValue(data, 'test', 1); + logWarn(`${LOG_PREFIX} test bids are enabled as rediads-test-bids is present in page URL hash.`) + } + } catch (err) { + logError(`${LOG_PREFIX} encountered an error while building bid requests :: ${err}`) + } - deepSetValue(data, 'test', 1); - deepSetValue(data, 'ext.rediads.account_id', accountID?.toString()); - deepSetValue(data, 'site.content', config.getConfig('content')); return [ { method: 'POST', - url: ENDPOINT_URL, + url: FINAL_ENDPOINT_URL, data, }, ]; }, interpretResponse(response, request) { - const bids = converter.fromORTB({ - response: response.body, - request: request.data, - }).bids; + let bids = []; + try { + bids = converter.fromORTB({ + response: response.body, + request: request.data, + }).bids + } catch (err) { + logError(`${LOG_PREFIX} encountered an error while processing bid responses :: ${err}`) + } return bids; }, }; diff --git a/test/spec/modules/rediadsBidAdapter_spec.js b/test/spec/modules/rediadsBidAdapter_spec.js index 24e310d5ca8..fc16c718060 100644 --- a/test/spec/modules/rediadsBidAdapter_spec.js +++ b/test/spec/modules/rediadsBidAdapter_spec.js @@ -1,140 +1,199 @@ -import { spec } from 'modules/rediadsBidAdapter'; -import { deepSetValue } from 'src/utils.js'; -import { config } from 'src/config.js'; import { expect } from 'chai'; -import sinon from 'sinon'; - -// Test for isBidRequestValid -describe('isBidRequestValid', function() { - it('should return true if accountID is present', function() { - const bidRequest = { - params: { - accountID: '12345', +import { spec } from '../../../modules/rediadsBidAdapter'; + +describe('rediads Bid Adapter', function () { + const BIDDER_CODE = 'rediads'; + const ENDPOINT_URL = 'https://stagingbidding.rediads.com/openrtb2/auction'; + + const bidRequest = { + bidder: BIDDER_CODE, + params: { + account_id: '12345', + }, + mediaTypes: { + banner: { + sizes: [[300, 250], [728, 90]], }, - }; - const result = spec.isBidRequestValid(bidRequest); - expect(result).to.be.true; + }, + adUnitCode: 'adunit-code', + bidId: '2ab03f1234', + auctionId: '123456789', + }; + + const bidderRequest = { + bidderCode: BIDDER_CODE, + refererInfo: { + referer: 'http://example.com', + }, + }; + + describe('isBidRequestValid', function () { + it('should return true for valid bid requests', function () { + expect(spec.isBidRequestValid(bidRequest)).to.equal(true); + }); + + it('should return false if account_id is missing', function () { + const invalidBid = { ...bidRequest, params: {} }; + expect(spec.isBidRequestValid(invalidBid)).to.equal(false); + }); }); - it('should return false if accountID is missing', function() { - const bidRequest = { - params: {}, - }; - const result = spec.isBidRequestValid(bidRequest); - expect(result).to.be.false; - }); -}); - -// Test for buildRequests -describe('buildRequests', function() { - it('should build a valid request with account_id and test flag', function() { - const bidRequests = [{ - params: { - accountID: '12345', - }, - }]; - const bidderRequest = {}; // Mock bidderRequest if needed + describe('buildRequests', function () { + it('should build a valid request with correct data', function () { + const requests = spec.buildRequests([bidRequest], bidderRequest); + expect(requests).to.be.an('array').that.is.not.empty; - // Mock config.getConfig('content') to return a valid value - sinon.stub(config, 'getConfig').returns('content_value'); + const request = requests[0]; + expect(request.method).to.equal('POST'); + expect(request.url).to.equal(ENDPOINT_URL); + expect(request.data).to.have.property('ext'); + expect(request.data.ext.rediads.params).to.deep.equal(bidRequest.params); + }); - const requests = spec.buildRequests(bidRequests, bidderRequest); + it('should include test flag if testBidsRequested is true', function () { + const originalHash = location.hash; + location.hash = '#rediads-test-bids'; - const data = requests[0].data; - expect(data).to.have.property('test', 1); - expect(data).to.have.property('ext'); - expect(data.ext).to.have.property('rediads.account_id', '12345'); - expect(data.site).to.have.property('content', 'content_value'); - expect(requests[0].url).to.equal('https://stagingbidding.rediads.com/openrtb2/auction'); + const requests = spec.buildRequests([bidRequest], bidderRequest); + expect(requests[0].data.test).to.equal(1); - // Restore the stub after the test - sinon.restore(); + location.hash = originalHash; // Reset the hash + }); }); -}); -// Test for interpretResponse -describe('interpretResponse', function() { - it('should correctly interpret the OpenRTB response and return bids', function() { - const mockResponse = { - body: { - bids: [ - { - requestId: '123', - cpm: 1.5, - ad: '', - mediaType: 'banner', - currency: 'USD', - ttl: 300, + describe('interpretResponse', function () { + it('should interpret and return valid bid responses for banner bid', function () { + const serverResponse = { + body: { + seatbid: [ + { + bid: [ + { + price: 1.23, + impid: '2ab03f1234', + adm: '
Ad
', + crid: 'creative123', + w: 300, + h: 250, + }, + ], + }, + ], + }, + }; + const requestObj = spec.buildRequests([bidRequest], bidderRequest); + const bids = spec.interpretResponse(serverResponse, requestObj[0]); + expect(bids).to.be.an('array').that.is.not.empty; + + const bid = bids[0]; + expect(bid).to.include({ + requestId: '2ab03f1234', + cpm: 1.23, + creativeId: 'creative123', + width: 300, + height: 250, + ad: '
Ad
', + }); + expect(bid.mediaType).to.equal('banner'); + }); + it('should interpret and return valid bid responses for video bid with VAST inline', function () { + const serverResponse = { + body: { + seatbid: [ + { + bid: [ + { + price: 1.23, + impid: '2ab03f1234', + adm: 'Video VAST Ad', + crid: 'creative123', + w: 300, + h: 250, + }, + ], + }, + ], + }, + }; + const updatedBidRequest = { ...bidRequest, + mediaTypes: { + video: { + sizes: [[300, 250]], }, - ], - }, - }; - - const request = { - data: { - test: 1, - ext: { - rediads: { - account_id: '12345', + }, + }; + const requestObj = spec.buildRequests([updatedBidRequest], bidderRequest); + const bids = spec.interpretResponse(serverResponse, requestObj[0]); + expect(bids).to.be.an('array').that.is.not.empty; + + const bid = bids[0]; + expect(bid).to.include({ + requestId: '2ab03f1234', + cpm: 1.23, + creativeId: 'creative123', + width: 300, + height: 250, + vastXml: 'Video VAST Ad', + }); + expect(bid.mediaType).to.equal('video'); + }); + + it('should interpret and return valid bid responses for video bid with nurl, w and h', function () { + const serverResponse = { + body: { + seatbid: [ + { + bid: [ + { + price: 1.23, + impid: '2ab03f1234', + adm: '
Video NURL Ad
', + crid: 'creative123', + w: 300, + h: 250, + nurl: 'https://example.com/nurl-video-ad-vast.xml' + }, + ], + }, + ], + }, + }; + const updatedBidRequest = { ...bidRequest, + mediaTypes: { + video: { + sizes: [[300, 250]], }, }, - }, - }; - - const bids = spec.interpretResponse(mockResponse, request); - - expect(bids).to.have.lengthOf(1); - expect(bids[0]).to.have.property('requestId', '123'); - expect(bids[0]).to.have.property('cpm', 1.5); - expect(bids[0]).to.have.property('ad', ''); - expect(bids[0]).to.have.property('mediaType', 'banner'); - }); -}); - -// Test for Default Values (Currency, Net Revenue) -describe('Default Values', function() { - it('should set the default currency as USD', function() { - const bidRequest = { - params: { - accountID: '12345', - }, - }; - const request = spec.buildRequests([bidRequest], {}); - expect(request[0].data.ext.rediads.account_id).to.equal('12345'); - expect(request[0].data.ext.rediads.currency).to.equal('USD'); - }); - - it('should set netRevenue to true', function() { - const bidRequest = { - params: { - accountID: '12345', - }, - }; - const request = spec.buildRequests([bidRequest], {}); - expect(request[0].data.ext.rediads.netRevenue).to.be.true; - }); -}); - -// Test for Media Type Handling -describe('Media Type Handling', function() { - it('should assign "banner" as mediaType by default', function() { - const bid = { adm: '', mediaType: 'banner' }; - const result = spec.converter.bidResponse(() => {}, bid, {}); - expect(result.mediaType).to.equal('banner'); - expect(result.mtype).to.equal(1); // BANNER = 1 - }); - - it('should assign "video" when video object exists', function() { - const bid = { video: {}, mediaType: 'video' }; - const result = spec.converter.bidResponse(() => {}, bid, {}); - expect(result.mediaType).to.equal('video'); - expect(result.mtype).to.equal(2); // VIDEO = 2 + }; + const requestObj = spec.buildRequests([updatedBidRequest], bidderRequest); + const bids = spec.interpretResponse(serverResponse, requestObj[0]); + expect(bids).to.be.an('array').that.is.not.empty; + + const bid = bids[0]; + expect(bid).to.include({ + requestId: '2ab03f1234', + cpm: 1.23, + creativeId: 'creative123', + width: 300, + height: 250, + vastXml: '
Video NURL Ad
', + vastUrl: 'https://example.com/nurl-video-ad-vast.xml' + }); + expect(bid.mediaType).to.equal('video'); + }); + + it('should return an empty array for invalid responses', function () { + const invalidResponse = { body: {} }; + const updatedBidRequest = {...bidRequest, params: undefined} + const requestObj = spec.buildRequests([updatedBidRequest], bidderRequest); + const bids = spec.interpretResponse(invalidResponse, requestObj[0]); + expect(bids).to.be.an('array').that.is.empty; + }); }); - it('should assign "native" when native object exists', function() { - const bid = { native: {}, mediaType: 'native' }; - const result = spec.converter.bidResponse(() => {}, bid, {}); - expect(result.mediaType).to.equal('native'); - expect(result.mtype).to.equal(4); // NATIVE = 4 + describe('Miscellaneous', function () { + it('should support multiple media types', function () { + expect(spec.supportedMediaTypes).to.include.members(['banner', 'native', 'video']); + }); }); }); From 8a127b36d69cd0e0388e50ba7b7bc2a24cdbcc4d Mon Sep 17 00:00:00 2001 From: symplorpro Date: Sat, 30 Nov 2024 19:51:16 +0530 Subject: [PATCH 03/10] Bug fix --- modules/rediadsBidAdapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/rediadsBidAdapter.js b/modules/rediadsBidAdapter.js index 17063283ac5..776a9c5e94a 100644 --- a/modules/rediadsBidAdapter.js +++ b/modules/rediadsBidAdapter.js @@ -59,7 +59,7 @@ export const spec = { let data = {}; let FINAL_ENDPOINT_URL = params.endpoint || ENDPOINT_URL try { - const data = converter.toORTB({ bidRequests, bidderRequest }); + data = converter.toORTB({ bidRequests, bidderRequest }); const testBidsRequested = location.hash.includes('rediads-test-bids'); const stagingEnvRequested = location.hash.includes('rediads-staging'); From 9b8f06975cfec0fb6908c92bddae623f889cc67e Mon Sep 17 00:00:00 2001 From: symplorpro Date: Sat, 30 Nov 2024 20:09:58 +0530 Subject: [PATCH 04/10] Readme updated --- modules/rediadsBidAdapter.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/rediadsBidAdapter.md b/modules/rediadsBidAdapter.md index 5db6a156719..28081177f41 100644 --- a/modules/rediadsBidAdapter.md +++ b/modules/rediadsBidAdapter.md @@ -27,7 +27,9 @@ Please reach out to support@rediads.com for more information. { bidder: "rediads", params: { - accountID: 123 + account_id: '123', + site: 'rediads.com', + slot: '321' } } ] From 25eacffafb6dac372d63faf20328804314821f8b Mon Sep 17 00:00:00 2001 From: Symplor Date: Sat, 30 Nov 2024 20:36:39 +0530 Subject: [PATCH 05/10] Test cases fixed --- modules/rediadsBidAdapter.js | 2 +- test/spec/modules/rediadsBidAdapter_spec.js | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/modules/rediadsBidAdapter.js b/modules/rediadsBidAdapter.js index 776a9c5e94a..e9006f71334 100644 --- a/modules/rediadsBidAdapter.js +++ b/modules/rediadsBidAdapter.js @@ -25,7 +25,7 @@ const converter = ortbConverter({ bidResponse(buildBidResponse, bid, context) { let mediaType = 'banner'; // Default media type - if (bid.vastXml || bid.vastUrl) { + if (bid.vastXml || bid.vastUrl || (bid.nurl && bid.w && bid.h) || (bid.adm && bid.adm.startsWith(' Date: Sat, 30 Nov 2024 20:49:17 +0530 Subject: [PATCH 06/10] test cases updated --- modules/rediadsBidAdapter.js | 2 +- test/spec/modules/rediadsBidAdapter_spec.js | 96 +++------------------ 2 files changed, 12 insertions(+), 86 deletions(-) diff --git a/modules/rediadsBidAdapter.js b/modules/rediadsBidAdapter.js index e9006f71334..7432f1461d6 100644 --- a/modules/rediadsBidAdapter.js +++ b/modules/rediadsBidAdapter.js @@ -25,7 +25,7 @@ const converter = ortbConverter({ bidResponse(buildBidResponse, bid, context) { let mediaType = 'banner'; // Default media type - if (bid.vastXml || bid.vastUrl || (bid.nurl && bid.w && bid.h) || (bid.adm && bid.adm.startsWith('Video VAST Ad', - crid: 'creative123', - w: 300, - h: 250, - }, - ], - }, - ], - }, - }; - const updatedBidRequest = { ...bidRequest, - mediaTypes: { - video: { - sizes: [[300, 250]], - }, - }, - }; - const requestObj = spec.buildRequests([updatedBidRequest], bidderRequest); - const bids = spec.interpretResponse(serverResponse, requestObj[0]); - expect(bids).to.be.an('array').that.is.not.empty; - - const bid = bids[0]; - expect(bid).to.include({ - requestId: '2ab03f1234', - cpm: 1.23, - creativeId: 'creative123', - width: 300, - height: 250, - vastXml: 'Video VAST Ad', - }); - expect(bid.mediaType).to.equal('video'); - }); - - it('should interpret and return valid bid responses for video bid with nurl, w and h', function () { - const serverResponse = { - body: { - seatbid: [ - { - bid: [ - { - price: 1.23, - impid: '2ab03f1234', - adm: '
Video NURL Ad
', - crid: 'creative123', - w: 300, - h: 250, - nurl: 'https://example.com/nurl-video-ad-vast.xml' - }, - ], - }, - ], - }, - }; - const updatedBidRequest = { ...bidRequest, - mediaTypes: { - video: { - sizes: [[300, 250]], - }, - }, - }; - const requestObj = spec.buildRequests([updatedBidRequest], bidderRequest); - const bids = spec.interpretResponse(serverResponse, requestObj[0]); - expect(bids).to.be.an('array').that.is.not.empty; - - const bid = bids[0]; - expect(bid).to.include({ - requestId: '2ab03f1234', - cpm: 1.23, - creativeId: 'creative123', - width: 300, - height: 250, - vastXml: '
Video NURL Ad
', - vastUrl: 'https://example.com/nurl-video-ad-vast.xml' - }); - expect(bid.mediaType).to.equal('video'); - }); it('should return an empty array for invalid responses', function () { const invalidResponse = { body: {} }; From 60adefda43d2151913da35a3b7d40bf6d2c83b11 Mon Sep 17 00:00:00 2001 From: Symplor Date: Sun, 1 Dec 2024 21:10:14 +0530 Subject: [PATCH 07/10] test cases reset hash fixed --- test/spec/modules/rediadsBidAdapter_spec.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/test/spec/modules/rediadsBidAdapter_spec.js b/test/spec/modules/rediadsBidAdapter_spec.js index a5453b20cd4..97b810974be 100644 --- a/test/spec/modules/rediadsBidAdapter_spec.js +++ b/test/spec/modules/rediadsBidAdapter_spec.js @@ -27,6 +27,15 @@ describe('rediads Bid Adapter', function () { }, }; + const resetHash = (originalHash) => { + // Reset the hash, ensuring no trailing # + if (originalHash) { + location.hash = originalHash; + } else { + history.replaceState(null, '', location.pathname + location.search); + } + } + describe('isBidRequestValid', function () { it('should return true for valid bid requests', function () { expect(spec.isBidRequestValid(bidRequest)).to.equal(true); @@ -57,7 +66,7 @@ describe('rediads Bid Adapter', function () { const requests = spec.buildRequests([bidRequest], bidderRequest); expect(requests[0].data.test).to.equal(1); - location.hash = originalHash; // Reset the hash + resetHash(originalHash); }); it('should set staging environtment if stagingEnvRequested is true', function () { @@ -67,7 +76,7 @@ describe('rediads Bid Adapter', function () { const requests = spec.buildRequests([bidRequest], bidderRequest); expect(requests[0].url).to.equal(STAGING_ENDPOINT_URL); - location.hash = originalHash; // Reset the hash + resetHash(originalHash); }); }); From 0eb2e46e90b80875a2afae3277aa1703abab8c03 Mon Sep 17 00:00:00 2001 From: symplorpro Date: Sun, 1 Dec 2024 22:13:18 +0530 Subject: [PATCH 08/10] Add semicolon --- modules/rediadsBidAdapter.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/rediadsBidAdapter.js b/modules/rediadsBidAdapter.js index 7432f1461d6..a40458c7531 100644 --- a/modules/rediadsBidAdapter.js +++ b/modules/rediadsBidAdapter.js @@ -57,7 +57,8 @@ export const spec = { buildRequests(bidRequests, bidderRequest) { const params = bidRequests[0]?.params || {}; let data = {}; - let FINAL_ENDPOINT_URL = params.endpoint || ENDPOINT_URL + let FINAL_ENDPOINT_URL = params.endpoint || ENDPOINT_URL; + try { data = converter.toORTB({ bidRequests, bidderRequest }); const testBidsRequested = location.hash.includes('rediads-test-bids'); From 65acb7ae0f4d827747b7dac3d6a1697303c4230b Mon Sep 17 00:00:00 2001 From: symplorpro Date: Sun, 1 Dec 2024 22:16:28 +0530 Subject: [PATCH 09/10] remove semicolon --- modules/rediadsBidAdapter.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/rediadsBidAdapter.js b/modules/rediadsBidAdapter.js index a40458c7531..7432f1461d6 100644 --- a/modules/rediadsBidAdapter.js +++ b/modules/rediadsBidAdapter.js @@ -57,8 +57,7 @@ export const spec = { buildRequests(bidRequests, bidderRequest) { const params = bidRequests[0]?.params || {}; let data = {}; - let FINAL_ENDPOINT_URL = params.endpoint || ENDPOINT_URL; - + let FINAL_ENDPOINT_URL = params.endpoint || ENDPOINT_URL try { data = converter.toORTB({ bidRequests, bidderRequest }); const testBidsRequested = location.hash.includes('rediads-test-bids'); From 75ef4a3796382004a23662934b707900a417a0d0 Mon Sep 17 00:00:00 2001 From: symplorpro <161946060+symplorpro@users.noreply.github.com> Date: Tue, 17 Dec 2024 21:08:06 +0530 Subject: [PATCH 10/10] Get site content from bidrequest instead of config --- modules/rediadsBidAdapter.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/modules/rediadsBidAdapter.js b/modules/rediadsBidAdapter.js index 7432f1461d6..ec4b12f6e39 100644 --- a/modules/rediadsBidAdapter.js +++ b/modules/rediadsBidAdapter.js @@ -2,7 +2,6 @@ import { ortbConverter } from '../libraries/ortbConverter/converter.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { deepSetValue, logWarn, logError } from '../src/utils.js'; import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js'; -import { config } from '../src/config.js'; const BIDDER_CODE = 'rediads'; const ENDPOINT_URL = 'https://bidding.rediads.com/openrtb2/auction'; @@ -56,6 +55,7 @@ export const spec = { }, buildRequests(bidRequests, bidderRequest) { const params = bidRequests[0]?.params || {}; + const siteContent = bidRequests[0]?.site?.content || null; let data = {}; let FINAL_ENDPOINT_URL = params.endpoint || ENDPOINT_URL try { @@ -66,9 +66,8 @@ export const spec = { if (stagingEnvRequested) { FINAL_ENDPOINT_URL = STAGING_ENDPOINT_URL; } - deepSetValue(data, 'ext.rediads.params', params); - deepSetValue(data, 'site.content', config.getConfig('content')); + deepSetValue(data, 'site.content', siteContent); if (testBidsRequested) { deepSetValue(data, 'test', 1);