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

PREP-192 Update Prebid.js PET adapter to operate as a real time data … #10

Closed
wants to merge 1 commit into from
Closed
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
51 changes: 51 additions & 0 deletions modules/iasRtdProvider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { submodule } from '../src/hook.js';
import { getGlobal } from '../src/prebidGlobal.js'

/** @type {string} */
const MODULE_NAME = 'realTimeData';
const SUBMODULE_NAME = 'ias';

/**
* Module init
* @param {Object} provider
* @param {Object} userConsent
* @return {boolean}
*/
export function init(config, userConsent) {
return true;
}

/**
* isBidValid
* @param {Object} bid
* @return {boolean}
*/
export function isBidValid(bid) {
const { bidder } = bid;
const { pubId, adUnitPath } = bid.params;
return !!(pubId && adUnitPath && bidder && bidder == 'ias');
}

function getBidRequestData(reqBidsConfigObj, callback, config, userConsent) {
const adUnits = reqBidsConfigObj.adUnits || getGlobal().adUnits;
adUnits.forEach(function (unit) {
unit.bids.forEach(function (bid, index, object) {
if (!isBidValid(bid)) {
object.splice(index, 1);
}
});
});
}

/** @type {RtdSubmodule} */
export const iasSubModule = {
name: SUBMODULE_NAME,
init: init,
getBidRequestData: getBidRequestData
};

function beforeInit() {
submodule(MODULE_NAME, iasSubModule);
}

beforeInit();
9 changes: 9 additions & 0 deletions modules/iasRtdProvider.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Overview

Module Name: Integral Ad Science(IAS) Rtd Provider
Module Type: Rtd Provider
Maintainer: raguilar@integralads.com

# Description

RTD provider for Integral Ad Science(IAS) Contact raguilar@integralads.com for information.
106 changes: 106 additions & 0 deletions test/spec/modules/iasRtdProvider_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import { iasSubModule, isBidValid } from 'modules/iasRtdProvider.js';
import { expect } from 'chai';

describe('iasRtdProvider is a RTD provider that', function () {
it('has the correct module name', function () {
expect(iasSubModule.name).to.equal('ias');
});
describe('has a method `init` that', function () {
it('exists', function () {
expect(iasSubModule.init).to.be.a('function');
});
it('returns true', function () {
expect(iasSubModule.init()).to.equal(true);
});
});
describe('has a method `isBidValid` that', function () {
it('exists', function () {
expect(isBidValid).to.be.a('function');
});
it('returns true', function () {
const bid = {
bidder: 'ias',
params: {
pubId: '1234',
adUnitPath: '/a/b/c/d',
}
};
expect(isBidValid(bid)).to.equal(true);
});
it('returns false when pubId is missing', function () {
const bid = {
bidder: 'ias',
params: {
adUnitPath: '/a/b/c/d',
}
};
expect(isBidValid(bid)).to.equal(false);
});
it('returns false when adUnitPath is missing', function () {
const bid = {
bidder: 'ias',
params: {
pubId: '1234',
}
};
expect(isBidValid(bid)).to.equal(false);
});
it('returns false when bidder is missing', function () {
const bid = {
params: {
pubId: '1234',
adUnitPath: '/a/b/c/d'
}
};
expect(isBidValid(bid)).to.equal(false);
});
});
describe('has a method `getBidRequestData` that', function () {
const config = {
name: 'ias',
waitForIt: true
};
const userConsent = { gdpr: null, usp: null, coppa: false };
it('exists', function () {
expect(iasSubModule.getBidRequestData).to.be.a('function');
});
it('process requestData validate bids', function () {
iasSubModule.getBidRequestData({ adUnits: adUnits }, null, config, userConsent);
expect(adUnits).to.length(2);
});
});
});

const adUnits = [
{
code: 'one-div-id',
mediaTypes: {
banner: {
sizes: [[970, 250], [728, 90], [1000, 90]]
}
},
sizes: [[970, 250], [728, 90], [1000, 90]],
bids: [
{
bidder: 'ias',
params: {
pubId: '1234',
adUnitPath: '/a/b/c'
}
}]
},
{
code: 'two-div-id',
mediaTypes: {
banner: { sizes: [[300, 250], [300, 600]] }
},
sizes: [[300, 250], [300, 600]],
bids: [
{
bidder: 'ias',
params: {
pubId: '1234',
adUnitPath: '/d/e/f'
}
}]
}];