From 1a89d024cb561f44cc59fe85d3f0adea11e24381 Mon Sep 17 00:00:00 2001 From: Sumit Sharma Date: Tue, 7 May 2019 22:23:02 +0530 Subject: [PATCH] refactor --- test/spec/unit/core/targeting_spec.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/test/spec/unit/core/targeting_spec.js b/test/spec/unit/core/targeting_spec.js index 78041dfeecf..f2cd22c8167 100644 --- a/test/spec/unit/core/targeting_spec.js +++ b/test/spec/unit/core/targeting_spec.js @@ -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); @@ -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);