Skip to content

Commit

Permalink
Rad 2751/specify ad units set targeting for ast (prebid#3805)
Browse files Browse the repository at this point in the history
* add adUnitCodes as param for setTargetingForAst()

* unit tests for setTargetingForAst

* refactor

* Revert "refactor"

This reverts commit 1a89d02.

* refactor to add more tests
  • Loading branch information
sumit116 authored and jacekburys-quantcast committed May 15, 2019
1 parent 3b96184 commit 29d11ce
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/targeting.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ export function newTargeting(auctionManager) {
let astTargeting = targeting.getAllTargeting(adUnitCodes);

try {
targeting.resetPresetTargetingAST();
targeting.resetPresetTargetingAST(adUnitCodes);
} catch (e) {
utils.logError('unable to reset targeting for AST' + e)
}
Expand Down
40 changes: 40 additions & 0 deletions test/spec/unit/core/targeting_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,4 +326,44 @@ describe('targeting tests', function () {
});
});
});

describe('setTargetingForAst', function () {
let sandbox,
apnTagStub;
beforeEach(function() {
sandbox = sinon.createSandbox();
sandbox.stub(targetingInstance, 'resetPresetTargetingAST');
apnTagStub = sandbox.stub(window.apntag, 'setKeywords');
});
afterEach(function () {
sandbox.restore();
});

it('should set single addUnit code', function() {
let adUnitCode = 'testdiv-abc-ad-123456-0';
sandbox.stub(targetingInstance, 'getAllTargeting').returns({
'testdiv1-abc-ad-123456-0': {hb_bidder: 'appnexus'}
});
targetingInstance.setTargetingForAst(adUnitCode);
expect(targetingInstance.getAllTargeting.called).to.equal(true);
expect(targetingInstance.resetPresetTargetingAST.called).to.equal(true);
expect(apnTagStub.callCount).to.equal(1);
expect(apnTagStub.getCall(0).args[0]).to.deep.equal('testdiv1-abc-ad-123456-0');
expect(apnTagStub.getCall(0).args[1]).to.deep.equal({HB_BIDDER: 'appnexus'});
});

it('should set array of addUnit codes', function() {
let adUnitCodes = ['testdiv1-abc-ad-123456-0', 'testdiv2-abc-ad-123456-0']
sandbox.stub(targetingInstance, 'getAllTargeting').returns({
'testdiv1-abc-ad-123456-0': {hb_bidder: 'appnexus'},
'testdiv2-abc-ad-123456-0': {hb_bidder: 'appnexus'}
});
targetingInstance.setTargetingForAst(adUnitCodes);
expect(targetingInstance.getAllTargeting.called).to.equal(true);
expect(targetingInstance.resetPresetTargetingAST.called).to.equal(true);
expect(apnTagStub.callCount).to.equal(2);
expect(apnTagStub.getCall(1).args[0]).to.deep.equal('testdiv2-abc-ad-123456-0');
expect(apnTagStub.getCall(1).args[1]).to.deep.equal({HB_BIDDER: 'appnexus'});
});
});
});

0 comments on commit 29d11ce

Please sign in to comment.