Skip to content

Commit

Permalink
move generation of transactionIds to requestBids over addAdUnits (#2706)
Browse files Browse the repository at this point in the history
* move generation of transactionIds to requestBids over addAdUnits

* remove transactionId generation for arrays as well

* move transactionId check in tests

* remove errant debugger statement
  • Loading branch information
snapwich authored and jsnellbaker committed Jun 19, 2018
1 parent 4cfb3bc commit 069c4e3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
11 changes: 5 additions & 6 deletions src/prebid.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,13 @@ $$PREBID_GLOBAL$$.requestBids = createHook('asyncSeries', function ({ bidsBackHa
const bidders = adUnit.bids.map(bid => bid.bidder);
const bidderRegistry = adaptermanager.bidderRegistry;

if (!adUnit.transactionId) {
adUnit.transactionId = utils.generateUUID();
}

bidders.forEach(bidder => {
const adapter = bidderRegistry[bidder];
const spec = adapter && adapter.getSpec && adapter.getSpec()
const spec = adapter && adapter.getSpec && adapter.getSpec();
// banner is default if not specified in spec
const bidderMediaTypes = (spec && spec.supportedMediaTypes) || ['banner'];

Expand Down Expand Up @@ -382,13 +386,8 @@ $$PREBID_GLOBAL$$.requestBids = createHook('asyncSeries', function ({ bidsBackHa
$$PREBID_GLOBAL$$.addAdUnits = function (adUnitArr) {
utils.logInfo('Invoking $$PREBID_GLOBAL$$.addAdUnits', arguments);
if (utils.isArray(adUnitArr)) {
// generate transactionid for each new adUnits
// Append array to existing
adUnitArr.forEach(adUnit => adUnit.transactionId = utils.generateUUID());
$$PREBID_GLOBAL$$.adUnits.push.apply($$PREBID_GLOBAL$$.adUnits, adUnitArr);
} else if (typeof adUnitArr === 'object') {
// Generate the transaction id for the adunit
adUnitArr.transactionId = utils.generateUUID();
$$PREBID_GLOBAL$$.adUnits.push(adUnitArr);
}
// emit event
Expand Down
7 changes: 0 additions & 7 deletions test/spec/adUnits_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,6 @@ describe('Publisher API _ AdUnits', function () {
assert.strictEqual(bids2[1].params.placementId, '827326', 'adUnit2 bids2 params.placementId');
});

it('both add unit should contains a transactionId', function() {
assert.isString(adUnit1.transactionId);
assert.isString(adUnit2.transactionId);

assert.strictEqual(false, adUnit1.transactionId === adUnit2.transactionId);
});

it('the second adUnits value should be same with the adUnits that is added by $$PREBID_GLOBAL$$.addAdUnits();', function () {
assert.strictEqual(adUnit2.code, '/1996833/slot-2', 'adUnit2 code');
assert.deepEqual(adUnit2.sizes, [[468, 60]], 'adUnit2 sizes');
Expand Down
23 changes: 23 additions & 0 deletions test/spec/unit/pbjs_api_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1209,9 +1209,12 @@ describe('Unit: Prebid Module', function () {
registerBidder(spec);

describe('part 1', () => {
let auctionArgs;

beforeEach(() => {
adUnitsBackup = auction.getAdUnits
auctionManagerStub = sinon.stub(auctionManager, 'createAuction').callsFake(function() {
auctionArgs = arguments[0];
return auction;
});
logMessageSpy = sinon.spy(utils, 'logMessage');
Expand All @@ -1234,6 +1237,26 @@ describe('Unit: Prebid Module', function () {
assert.ok(logMessageSpy.calledWith('No adUnits configured. No bids requested.'), 'expected message was logged');
});

it('should attach transactionIds to ads (or pass through transactionId if it already exists)', () => {
$$PREBID_GLOBAL$$.requestBids({
adUnits: [
{
code: 'test1',
transactionId: 'd0676a3c-ff32-45a5-af65-8175a8e7ddca',
bids: []
}, {
code: 'test2',
bids: []
}
]
});

expect(auctionArgs.adUnits[0]).to.have.property('transactionId')
.and.to.equal('d0676a3c-ff32-45a5-af65-8175a8e7ddca');
expect(auctionArgs.adUnits[1]).to.have.property('transactionId')
.and.to.match(/[a-f0-9\-]{36}/i);
});

it('should execute callback immediately if adUnits is empty', () => {
var bidsBackHandler = function bidsBackHandlerCallback() {};
var spyExecuteCallback = sinon.spy(bidsBackHandler);
Expand Down

0 comments on commit 069c4e3

Please sign in to comment.