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

Smarthub Bid Adapter : update convertOrtbToNative #11411

Merged
merged 3 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions modules/smarthubBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand All @@ -23,21 +37,21 @@ 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,
minBidfloor,
pos,
bidId,
schain,
bidfloor
bidfloor,
};

if (mediaTypes && mediaTypes[BANNER]) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
}
});
Expand Down
25 changes: 23 additions & 2 deletions test/spec/modules/smarthubBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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,
Expand Down Expand Up @@ -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;
Expand All @@ -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 () {
Expand Down