Skip to content

Commit 07c74f0

Browse files
committed
Adds unit test
1 parent 57638b1 commit 07c74f0

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

test/spec/unit/core/targeting_spec.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {auctionManager} from 'src/auctionManager.js';
1313
import * as utils from 'src/utils.js';
1414
import {deepClone} from 'src/utils.js';
1515
import {createBid} from '../../../../src/bidfactory.js';
16-
import {hook} from '../../../../src/hook.js';
16+
import { hook, setupBeforeHookFnOnce } from '../../../../src/hook.js';
1717
import {getHighestCpm} from '../../../../src/utils/reducers.js';
1818

1919
function mkBid(bid, status = STATUS.GOOD) {
@@ -956,6 +956,40 @@ describe('targeting tests', function () {
956956
});
957957
}); // end getAllTargeting tests
958958

959+
describe('getAllTargeting will work correctly when a hook raises has modified flag in getHighestCpmBidsFromBidPool', function () {
960+
let bidsReceived;
961+
let amGetAdUnitsStub;
962+
let amBidsReceivedStub;
963+
let bidExpiryStub;
964+
965+
beforeEach(function () {
966+
bidsReceived = [bid2, bid1].map(deepClone);
967+
968+
amBidsReceivedStub = sandbox.stub(auctionManager, 'getBidsReceived').callsFake(function() {
969+
return bidsReceived;
970+
});
971+
amGetAdUnitsStub = sandbox.stub(auctionManager, 'getAdUnitCodes').callsFake(function() {
972+
return ['/123456/header-bid-tag-0'];
973+
});
974+
bidExpiryStub = sandbox.stub(filters, 'isBidNotExpired').returns(true);
975+
976+
setupBeforeHookFnOnce(getHighestCpmBidsFromBidPool, function (fn, bidsReceived, highestCpmCallback, adUnitBidLimit = 0, hasModified = false) {
977+
fn.call(this, bidsReceived, highestCpmCallback, adUnitBidLimit, true);
978+
});
979+
});
980+
981+
afterEach(function () {
982+
getHighestCpmBidsFromBidPool.getHooks().remove();
983+
})
984+
985+
it('will apply correct targeting', function () {
986+
let targeting = targetingInstance.getAllTargeting(['/123456/header-bid-tag-0']);
987+
988+
expect(targeting['/123456/header-bid-tag-0']['hb_pb']).to.equal('0.53');
989+
expect(targeting['/123456/header-bid-tag-0']['hb_adid']).to.equal('148018fe5e');
990+
})
991+
});
992+
959993
describe('getAllTargeting without bids return empty object', function () {
960994
let amBidsReceivedStub;
961995
let amGetAdUnitsStub;

0 commit comments

Comments
 (0)