From ec455f2de9ff1c9fa46c41969f9ea634bc1f7f3b Mon Sep 17 00:00:00 2001 From: SmartHubSolutions <87376145+SmartHubSolutions@users.noreply.github.com> Date: Tue, 21 May 2024 18:14:04 +0300 Subject: [PATCH] Smarthub Bid Adapter : update convertOrtbToNative (#11411) * Update adapter SmartHub * revert previous fixes * Add back convertOrtbRequestToNative function --------- Co-authored-by: Victor Co-authored-by: Chris Huie --- modules/smarthubBidAdapter.js | 27 +++++++++++++++----- test/spec/modules/smarthubBidAdapter_spec.js | 25 ++++++++++++++++-- 2 files changed, 44 insertions(+), 8 deletions(-) diff --git a/modules/smarthubBidAdapter.js b/modules/smarthubBidAdapter.js index 2889bd5358b..0be3e6831e7 100644 --- a/modules/smarthubBidAdapter.js +++ b/modules/smarthubBidAdapter.js @@ -2,9 +2,23 @@ import {deepAccess, isFn, logError, logMessage} from '../src/utils.js'; import {registerBidder} from '../src/adapters/bidderFactory.js'; import {BANNER, NATIVE, VIDEO} from '../src/mediaTypes.js'; import {config} from '../src/config.js'; -import { convertOrtbRequestToProprietaryNative } from '../src/native.js'; +import {convertOrtbRequestToProprietaryNative} from '../src/native.js'; const BIDDER_CODE = 'smarthub'; +const ALIASES = [{code: 'markapp', skipPbsAliasing: true}]; +const BASE_URLS = { + smarthub: 'https://prebid.smart-hub.io/pbjs', + markapp: 'https://markapp-prebid.smart-hub.io/pbjs' +}; + +function getUrl(partnerName) { + const aliases = ALIASES.map(el => el.code); + if (aliases.includes(partnerName)) { + return BASE_URLS[partnerName]; + } + + return `${BASE_URLS[BIDDER_CODE]}?partnerName=${partnerName}`; +} function isBidResponseValid(bid) { if (!bid.requestId || !bid.cpm || !bid.creativeId || !bid.ttl || !bid.currency || !bid.hasOwnProperty('netRevenue')) { @@ -23,13 +37,13 @@ function isBidResponseValid(bid) { } function getPlacementReqData(bid) { - const { params, bidId, mediaTypes } = bid; + const { params, bidId, mediaTypes, bidder } = bid; const schain = bid.schain || {}; const { partnerName, seat, token, iabCat, minBidfloor, pos } = params; const bidfloor = getBidFloor(bid); const placement = { - partnerName: partnerName.toLowerCase(), + partnerName: String(partnerName || bidder).toLowerCase(), seat, token, iabCat, @@ -37,7 +51,7 @@ function getPlacementReqData(bid) { pos, bidId, schain, - bidfloor + bidfloor, }; if (mediaTypes && mediaTypes[BANNER]) { @@ -131,11 +145,12 @@ function buildRequestParams(bidderRequest = {}, placements = []) { export const spec = { code: BIDDER_CODE, + aliases: ALIASES, supportedMediaTypes: [BANNER, VIDEO, NATIVE], isBidRequestValid: (bid = {}) => { const { params, bidId, mediaTypes } = bid; - let valid = Boolean(bidId && params && params.partnerName && params.seat && params.token); + let valid = Boolean(bidId && params && params.seat && params.token); if (mediaTypes && mediaTypes[BANNER]) { valid = valid && Boolean(mediaTypes[BANNER] && mediaTypes[BANNER].sizes); @@ -166,7 +181,7 @@ export const spec = { const request = buildRequestParams(bidderRequest, tempObj[key]); return { method: 'POST', - url: `https://${key}-prebid.smart-hub.io/pbjs`, + url: getUrl(key), data: request, } }); diff --git a/test/spec/modules/smarthubBidAdapter_spec.js b/test/spec/modules/smarthubBidAdapter_spec.js index e01d0c72f6b..dcbfd297013 100644 --- a/test/spec/modules/smarthubBidAdapter_spec.js +++ b/test/spec/modules/smarthubBidAdapter_spec.js @@ -4,6 +4,7 @@ import { BANNER, VIDEO, NATIVE } from '../../../src/mediaTypes.js'; import { getUniqueIdentifierStr } from '../../../src/utils.js'; const bidder = 'smarthub' +const bidderAlias = 'markapp' describe('SmartHubBidAdapter', function () { const bids = [ @@ -24,6 +25,22 @@ describe('SmartHubBidAdapter', function () { pos: 1, } }, + { + bidId: getUniqueIdentifierStr(), + bidder: bidderAlias, + mediaTypes: { + [BANNER]: { + sizes: [[400, 350]] + } + }, + params: { + seat: 'testSeat', + token: 'testBanner', + iabCat: ['IAB1-1', 'IAB3-1', 'IAB4-3'], + minBidfloor: 9, + pos: 1, + } + }, { bidId: getUniqueIdentifierStr(), bidder: bidder, @@ -105,7 +122,7 @@ describe('SmartHubBidAdapter', function () { }); describe('buildRequests', function () { - let [serverRequest] = spec.buildRequests(bids, bidderRequest); + let [serverRequest, requestAlias] = spec.buildRequests(bids, bidderRequest); it('Creates a ServerRequest object with method, URL and data', function () { expect(serverRequest).to.exist; @@ -119,7 +136,11 @@ describe('SmartHubBidAdapter', function () { }); it('Returns valid URL', function () { - expect(serverRequest.url).to.equal('https://testname-prebid.smart-hub.io/pbjs'); + expect(serverRequest.url).to.equal(`https://prebid.smart-hub.io/pbjs?partnerName=testname`); + }); + + it('Returns valid URL if alias', function () { + expect(requestAlias.url).to.equal(`https://${bidderAlias}-prebid.smart-hub.io/pbjs`); }); it('Returns general data valid', function () {