-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rad 2751/specify ad units set targeting for ast #3805
Changes from 5 commits
27d3210
02bb3d5
7fa8293
fe05bd3
1a89d02
6f8e2a8
34094f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -326,4 +326,46 @@ describe('targeting tests', function () { | |
}); | ||
}); | ||
}); | ||
|
||
describe('setTargetingForAst', function () { | ||
let sandbox; | ||
beforeEach(function() { | ||
sandbox = sinon.createSandbox(); | ||
sandbox.stub(targetingInstance, 'resetPresetTargetingAST').callsFake(function() {}); | ||
sandbox.stub(window.apntag, 'setKeywords').callsFake(function() {}); | ||
}); | ||
afterEach(function () { | ||
sandbox.restore(); | ||
}); | ||
|
||
function mockGetAllTargeting(adUnitCodes) { | ||
adUnitCodes = Array.isArray(adUnitCodes) ? adUnitCodes : Array(adUnitCodes); | ||
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; | ||
}); | ||
} | ||
|
||
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); | ||
expect(window.apntag.setKeywords.called).to.equal(true); | ||
}); | ||
|
||
it('should set array of addUnit codes', function() { | ||
let adUnitCodes = ['testdiv1-abc-ad-123456-0', 'testdiv2-abc-ad-123456-0'] | ||
mockGetAllTargeting(adUnitCodes); | ||
targetingInstance.setTargetingForAst(adUnitCodes); | ||
expect(targetingInstance.getAllTargeting.called).to.equal(true); | ||
expect(targetingInstance.resetPresetTargetingAST.called).to.equal(true); | ||
expect(window.apntag.setKeywords.called).to.equal(true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To differentiate between this test and the one with single adUnitCode, you should test here that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated the tests. |
||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest here to use
stub.returns
. Changing the implementation of getAllTargeting with this fake function is not a good idea. So you can do something like below in each test caseThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.