Skip to content

Commit

Permalink
[AD-1043] JW Player RTD - add targeting info to bid.rtd (#5950)
Browse files Browse the repository at this point in the history
* adds targeting to rtd

* updates tmg module

* updates unit tests

* shortens realTimeData

* updates grid adapter for rtd

Co-authored-by: karimJWP <karimJWP@github.com>
  • Loading branch information
karimMourra and karimJWP authored Nov 13, 2020
1 parent ef7fb86 commit 09468bf
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 29 deletions.
3 changes: 2 additions & 1 deletion modules/gridBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,12 @@ export const spec = {
if (!userId) {
userId = bid.userId;
}
const {params: {uid, keywords, bidFloor}, mediaTypes, bidId, adUnitCode, jwTargeting} = bid;
const {params: {uid, keywords, bidFloor}, mediaTypes, bidId, adUnitCode, rtd} = bid;
bidsMap[bidId] = bid;
if (!pageKeywords && !utils.isEmpty(keywords)) {
pageKeywords = utils.transformBidderParamKeywords(keywords);
}
const jwTargeting = rtd && rtd.jwplayer && rtd.jwplayer.targeting;
if (jwTargeting) {
if (!jwpseg && jwTargeting.segments) {
jwpseg = jwTargeting.segments;
Expand Down
11 changes: 8 additions & 3 deletions modules/jwplayerRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,14 @@ function addTargetingToBids(bids, targeting) {
return;
}

bids.forEach(bid => {
bid.jwTargeting = targeting;
});
bids.forEach(bid => addTargetingToBid(bid, targeting));
}

export function addTargetingToBid(bid, targeting) {
const rtd = bid.rtd || {};
const jwRtd = {};
jwRtd[SUBMODULE_NAME] = Object.assign({}, rtd[SUBMODULE_NAME], { targeting });
bid.rtd = Object.assign({}, rtd, jwRtd);
}

function getPlayer(playerID) {
Expand Down
14 changes: 9 additions & 5 deletions modules/jwplayerRtdProvider.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,15 @@ Each bid for which targeting information was found will conform to the following
adUnitCode: 'xyz',
bidId: 'abc',
...,
jwTargeting: {
segments: ['123', '456'],
content: {
id: 'jw_abc123'
}
rtd: {
jwplayer: {
targeting: {
segments: ['123', '456'],
content: {
id: 'jw_abc123'
}
}
}
}
}
```
Expand Down
10 changes: 7 additions & 3 deletions test/spec/modules/gridBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,9 +411,13 @@ describe('TheMediaGrid Adapter', function () {
const jsSegments = ['test_seg_1', 'test_seg_2'];
const bidRequestsWithUserIds = bidRequests.map((bid) => {
return Object.assign({
jwTargeting: {
segments: jsSegments,
content: jsContent
rtd: {
jwplayer: {
targeting: {
segments: jsSegments,
content: jsContent
}
}
}
}, bid);
});
Expand Down
115 changes: 98 additions & 17 deletions test/spec/modules/jwplayerRtdProvider_spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { fetchTargetingForMediaId, getVatFromCache, extractPublisherParams,
formatTargetingResponse, getVatFromPlayer, enrichAdUnits,
formatTargetingResponse, getVatFromPlayer, enrichAdUnits, addTargetingToBid,
fetchTargetingInformation, jwplayerSubmodule } from 'modules/jwplayerRtdProvider.js';
import { server } from 'test/mocks/xhr.js';

Expand Down Expand Up @@ -252,7 +252,7 @@ describe('jwplayerRtdProvider', function() {
};
jwplayerSubmodule.getBidRequestData({ adUnits: [adUnit] }, bidRequestSpy);
expect(bidRequestSpy.calledOnce).to.be.true;
expect(bid).to.have.deep.property('jwTargeting', expectedTargeting);
expect(bid.rtd.jwplayer).to.have.deep.property('targeting', expectedTargeting);
fakeServer.respond();
expect(bidRequestSpy.calledOnce).to.be.true;
});
Expand Down Expand Up @@ -313,8 +313,8 @@ describe('jwplayerRtdProvider', function() {
enrichAdUnits([adUnit]);
const bid1 = bids[0];
const bid2 = bids[1];
expect(bid1).to.not.have.property('jwTargeting');
expect(bid2).to.not.have.property('jwTargeting');
expect(bid1).to.not.have.property('rtd');
expect(bid2).to.not.have.property('rtd');

const request = fakeServer.requests[0];
request.respond(
Expand All @@ -330,8 +330,8 @@ describe('jwplayerRtdProvider', function() {
})
);

expect(bid1).to.have.deep.property('jwTargeting', expectedTargetingForSuccess);
expect(bid2).to.have.deep.property('jwTargeting', expectedTargetingForSuccess);
expect(bid1.rtd.jwplayer).to.have.deep.property('targeting', expectedTargetingForSuccess);
expect(bid2.rtd.jwplayer).to.have.deep.property('targeting', expectedTargetingForSuccess);
});

it('immediately adds cached targeting', function () {
Expand Down Expand Up @@ -373,8 +373,8 @@ describe('jwplayerRtdProvider', function() {
enrichAdUnits([adUnit]);
const bid1 = bids[0];
const bid2 = bids[1];
expect(bid1).to.have.deep.property('jwTargeting', expectedTargetingForSuccess);
expect(bid2).to.have.deep.property('jwTargeting', expectedTargetingForSuccess);
expect(bid1.rtd.jwplayer).to.have.deep.property('targeting', expectedTargetingForSuccess);
expect(bid2.rtd.jwplayer).to.have.deep.property('targeting', expectedTargetingForSuccess);
});

it('adds content block when segments are absent and no request is pending', function () {
Expand Down Expand Up @@ -407,8 +407,8 @@ describe('jwplayerRtdProvider', function() {
enrichAdUnits([adUnit]);
const bid1 = bids[0];
const bid2 = bids[1];
expect(bid1).to.have.deep.property('jwTargeting', expectedTargetingForFailure);
expect(bid2).to.have.deep.property('jwTargeting', expectedTargetingForFailure);
expect(bid1.rtd.jwplayer).to.have.deep.property('targeting', expectedTargetingForFailure);
expect(bid2.rtd.jwplayer).to.have.deep.property('targeting', expectedTargetingForFailure);
});
});

Expand Down Expand Up @@ -456,6 +456,87 @@ describe('jwplayerRtdProvider', function() {
})
});

describe('Add Targeting to Bid', function () {
const targeting = {foo: 'bar'};

it('creates realTimeData when absent from Bid', function () {
const targeting = {foo: 'bar'};
const bid = {};
addTargetingToBid(bid, targeting);
expect(bid).to.have.property('rtd');
expect(bid).to.have.nested.property('rtd.jwplayer.targeting', targeting);
});

it('adds to existing realTimeData', function () {
const otherRtd = {
targeting: {
seg: 'rtd seg'
}
};

const bid = {
rtd: {
otherRtd
}
};

addTargetingToBid(bid, targeting);
expect(bid).to.have.property('rtd');
const rtd = bid.rtd;
expect(rtd).to.have.property('jwplayer');
expect(rtd).to.have.nested.property('jwplayer.targeting', targeting);

expect(rtd).to.have.deep.property('otherRtd', otherRtd);
});

it('adds to existing realTimeData.jwplayer', function () {
const otherInfo = { seg: 'rtd seg' };
const bid = {
rtd: {
jwplayer: {
otherInfo
}
}
};
addTargetingToBid(bid, targeting);

expect(bid).to.have.property('rtd');
const rtd = bid.rtd;
expect(rtd).to.have.property('jwplayer');
expect(rtd).to.have.nested.property('jwplayer.otherInfo', otherInfo);
expect(rtd).to.have.nested.property('jwplayer.targeting', targeting);
});

it('overrides existing jwplayer.targeting', function () {
const otherInfo = { seg: 'rtd seg' };
const bid = {
rtd: {
jwplayer: {
targeting: {
otherInfo
}
}
}
};
addTargetingToBid(bid, targeting);

expect(bid).to.have.property('rtd');
const rtd = bid.rtd;
expect(rtd).to.have.property('jwplayer');
expect(rtd).to.have.nested.property('jwplayer.targeting', targeting);
});

it('creates jwplayer when absent from realTimeData', function () {
const bid = { rtd: {} };
addTargetingToBid(bid, targeting);

expect(bid).to.have.property('rtd');
const rtd = bid.rtd;
expect(rtd).to.have.property('jwplayer');
expect(rtd).to.have.nested.property('jwplayer.targeting', targeting);
});
});

describe('jwplayerSubmodule', function () {
it('successfully instantiates', function () {
expect(jwplayerSubmodule.init()).to.equal(true);
Expand Down Expand Up @@ -578,7 +659,7 @@ describe('jwplayerRtdProvider', function() {
};
jwplayerSubmodule.getBidRequestData({ adUnits: [adUnitWithMediaId, adUnitEmpty] }, bidRequestSpy);
expect(bidRequestSpy.calledOnce).to.be.true;
expect(bid).to.have.deep.property('jwTargeting', expectedTargeting);
expect(bid.rtd.jwplayer).to.have.deep.property('targeting', expectedTargeting);
});

it('excludes segments when absent', function () {
Expand All @@ -605,9 +686,9 @@ describe('jwplayerRtdProvider', function() {

jwplayerSubmodule.getBidRequestData({ adUnits: [ adUnit ] }, bidRequestSpy);
expect(bidRequestSpy.calledOnce).to.be.true;
expect(bid.jwTargeting).to.not.have.property('segments');
expect(bid.jwTargeting).to.not.have.property('segments');
expect(bid).to.have.deep.property('jwTargeting', expectedTargeting);
expect(bid.rtd.jwplayer.targeting).to.not.have.property('segments');
expect(bid.rtd.jwplayer.targeting).to.not.have.property('segments');
expect(bid.rtd.jwplayer).to.have.deep.property('targeting', expectedTargeting);
});

it('does not modify bid when jwTargeting block is absent', function () {
Expand Down Expand Up @@ -637,9 +718,9 @@ describe('jwplayerRtdProvider', function() {

jwplayerSubmodule.getBidRequestData({ adUnits: [adUnitWithMediaId, adUnitEmpty, adUnitEmptyfpd] }, bidRequestSpy);
expect(bidRequestSpy.calledOnce).to.be.true;
expect(bid1).to.not.have.property('jwTargeting');
expect(bid2).to.not.have.property('jwTargeting');
expect(bid3).to.not.have.property('jwTargeting');
expect(bid1).to.not.have.property('rtd');
expect(bid2).to.not.have.property('rtd');
expect(bid3).to.not.have.property('rtd');
});
});
});
Expand Down

0 comments on commit 09468bf

Please sign in to comment.