Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Sumit Sharma authored and Sumit Sharma committed May 7, 2019
1 parent fe05bd3 commit 1a89d02
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions test/spec/unit/core/targeting_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,13 +338,21 @@ describe('targeting tests', function () {
sandbox.restore();
});

it('should set single addUnit code', function() {
let adUnitCode = 'testdiv-abc-ad-123456-0';
function mockGetAllTargeting(adUnitCodes) {
adUnitCodes = Array.isArray(adUnitCodes) ? adUnitCodes : Array(adUnitCodes);
sandbox.stub(targetingInstance, 'getAllTargeting').callsFake(function() {
let mockTargeting = {};
mockTargeting.adUnitCode = {hb_bidder: 'appnexus'};
for (let i = 0; i < Object.keys(adUnitCodes).length; i++) {
let key = Object.keys(adUnitCodes)[i];
mockTargeting[key] = {hb_bidder: 'appnexus'};
}
return mockTargeting;
});
}

it('should set single addUnit code', function() {
let adUnitCode = 'testdiv-abc-ad-123456-0';
mockGetAllTargeting(adUnitCode);
targetingInstance.setTargetingForAst(adUnitCode);
expect(targetingInstance.getAllTargeting.called).to.equal(true);
expect(targetingInstance.resetPresetTargetingAST.called).to.equal(true);
Expand All @@ -353,14 +361,7 @@ describe('targeting tests', function () {

it('should set array of addUnit codes', function() {
let adUnitCodes = ['testdiv1-abc-ad-123456-0', 'testdiv2-abc-ad-123456-0']
sandbox.stub(targetingInstance, 'getAllTargeting').callsFake(function() {
let mockTargeting = {};
for (let i = 0; i < Object.keys(adUnitCodes).length; i++) {
let key = Object.keys(adUnitCodes)[i];
mockTargeting[key] = {hb_bidder: 'appnexus'};
}
return mockTargeting;
});
mockGetAllTargeting(adUnitCodes);
targetingInstance.setTargetingForAst(adUnitCodes);
expect(targetingInstance.getAllTargeting.called).to.equal(true);
expect(targetingInstance.resetPresetTargetingAST.called).to.equal(true);
Expand Down

0 comments on commit 1a89d02

Please sign in to comment.