Skip to content

Commit

Permalink
Fix issue where the ${AUCTION_PRICE} macro was not being replaced in …
Browse files Browse the repository at this point in the history
…secure creatives (#3493)

* fixed issue where the creative AUCTION_PRICE macro was not being replaced in secure creatives.

* fixed issue where the creative AUCTION_PRICE macro was not being replaced in secure creatives.

* removed cpm from postMessage payload]

* removed unneeded cpm deconstruct

* pulling cpm from the adObject

* also macro repalce adUrl

* added unit test for secureCreative sendAdToCreative

* added more realistic mock values
  • Loading branch information
JonGoSonobi authored and mkendall07 committed Feb 5, 2019
1 parent 6c196a0 commit 90afc1a
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/secureCreatives.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import events from './events';
import { fireNativeTrackers } from './native';
import { EVENTS } from './constants';
import { isSlotMatchingAdUnitCode, logWarn } from './utils';
import { isSlotMatchingAdUnitCode, logWarn, replaceAuctionPrice } from './utils';
import { auctionManager } from './auctionManager';
import find from 'core-js/library/fn/array/find';
import { isRendererRequired, executeRenderer } from './Renderer';
Expand All @@ -32,7 +32,7 @@ function receiveMessage(ev) {
});

if (data.message === 'Prebid Request') {
sendAdToCreative(adObject, data.adServerDomain, ev.source);
_sendAdToCreative(adObject, data.adServerDomain, ev.source);

// save winning bids
auctionManager.addWinningBid(adObject);
Expand All @@ -53,17 +53,17 @@ function receiveMessage(ev) {
}
}

function sendAdToCreative(adObject, remoteDomain, source) {
const { adId, ad, adUrl, width, height, renderer } = adObject;
export function _sendAdToCreative(adObject, remoteDomain, source) {
const { adId, ad, adUrl, width, height, renderer, cpm } = adObject;
// rendering for outstream safeframe
if (isRendererRequired(renderer)) {
executeRenderer(renderer, adObject);
} else if (adId) {
resizeRemoteCreative(adObject);
source.postMessage(JSON.stringify({
message: 'Prebid Response',
ad,
adUrl,
ad: replaceAuctionPrice(ad, cpm),
adUrl: replaceAuctionPrice(adUrl, cpm),
adId,
width,
height
Expand Down
45 changes: 45 additions & 0 deletions test/spec/unit/secureCreatives_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import {
_sendAdToCreative
} from '../../../src/secureCreatives';
import { expect } from 'chai';
import * as utils from 'src/utils';

describe('secureCreatives', () => {
describe('_sendAdToCreative', () => {
beforeEach(function () {
sinon.stub(utils, 'logError');
sinon.stub(utils, 'logWarn');
});

afterEach(function () {
utils.logError.restore();
utils.logWarn.restore();
});
it('should macro replace ${AUCTION_PRICE} with the winning bid for ad and adUrl', () => {
const oldVal = window.googletag;
const oldapntag = window.apntag;
window.apntag = null
window.googletag = null;
const mockAdObject = {
adId: 'someAdId',
ad: '<script src="http://prebid.org/creative/${AUCTION_PRICE}"></script>',
adUrl: 'http://creative.prebid.org/${AUCTION_PRICE}',
width: 300,
height: 250,
renderer: null,
cpm: '1.00',
adUnitCode: 'some_dom_id'
};
const remoteDomain = '*';
const source = {
postMessage: sinon.stub()
};

_sendAdToCreative(mockAdObject, remoteDomain, source);
expect(JSON.parse(source.postMessage.args[0][0]).ad).to.equal('<script src="http://prebid.org/creative/1.00"></script>');
expect(JSON.parse(source.postMessage.args[0][0]).adUrl).to.equal('http://creative.prebid.org/1.00');
window.googletag = oldVal;
window.apntag = oldapntag;
});
});
});

0 comments on commit 90afc1a

Please sign in to comment.