forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
debugging_spec.js
144 lines (121 loc) · 3.35 KB
/
debugging_spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import { expect } from 'chai';
import { sessionLoader, addBidResponseHook, getConfig, disableOverrides, boundHook } from 'src/debugging';
import { addBidResponse } from 'src/auction';
import { config } from 'src/config';
describe('bid overrides', function () {
let sandbox;
beforeEach(function () {
sandbox = sinon.sandbox.create();
});
afterEach(function () {
window.sessionStorage.clear();
config.resetConfig();
sandbox.restore();
});
describe('initialization', function () {
beforeEach(function () {
sandbox.stub(config, 'setConfig');
});
afterEach(function () {
disableOverrides();
});
it('should happen when enabled with setConfig', function () {
getConfig({
enabled: true
});
expect(addBidResponse.getHooks().some(hook => hook.hook === boundHook)).to.equal(true);
});
it('should happen when configuration found in sessionStorage', function () {
sessionLoader({
getItem: () => ('{"enabled": true}')
});
expect(addBidResponse.getHooks().some(hook => hook.hook === boundHook)).to.equal(true);
});
it('should not throw if sessionStorage is inaccessible', function () {
expect(() => {
sessionLoader({
getItem() {
throw new Error('test');
}
});
}).not.to.throw();
});
});
describe('hook', function () {
let mockBids;
let bids;
beforeEach(function () {
let baseBid = {
'bidderCode': 'rubicon',
'width': 970,
'height': 250,
'statusMessage': 'Bid available',
'mediaType': 'banner',
'source': 'client',
'currency': 'USD',
'cpm': 0.5,
'ttl': 300,
'netRevenue': false,
'adUnitCode': '/19968336/header-bid-tag-0'
};
mockBids = [];
mockBids.push(baseBid);
mockBids.push(Object.assign({}, baseBid, {
bidderCode: 'appnexus'
}));
bids = [];
});
function run(overrides) {
mockBids.forEach(bid => {
let next = (adUnitCode, bid) => {
bids.push(bid);
};
addBidResponseHook.bind(overrides)(next, bid.adUnitCode, bid)
});
}
it('should allow us to exclude bidders', function () {
run({
enabled: true,
bidders: ['appnexus']
});
expect(bids.length).to.equal(1);
expect(bids[0].bidderCode).to.equal('appnexus');
});
it('should allow us to override all bids', function () {
run({
enabled: true,
bids: [{
cpm: 2
}]
});
expect(bids.length).to.equal(2);
expect(bids[0].cpm).to.equal(2);
expect(bids[1].cpm).to.equal(2);
});
it('should allow us to override bids by bidder', function () {
run({
enabled: true,
bids: [{
bidder: 'rubicon',
cpm: 2
}]
});
expect(bids.length).to.equal(2);
expect(bids[0].cpm).to.equal(2);
expect(bids[1].cpm).to.equal(0.5);
});
it('should allow us to override bids by adUnitCode', function () {
mockBids[1].adUnitCode = 'test';
run({
enabled: true,
bids: [{
adUnitCode: 'test',
cpm: 2
}]
});
expect(bids.length).to.equal(2);
expect(bids[0].cpm).to.equal(0.5);
expect(bids[1].cpm).to.equal(2);
});
});
});