forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 5
/
banner_spec.js
182 lines (165 loc) · 4.36 KB
/
banner_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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import * as utils from '../../src/utils.js';
import { syncOrtb2 } from '../../src/prebid.js';
describe('banner', () => {
describe('syncOrtb2', () => {
let logWarnSpy;
beforeEach(function () {
logWarnSpy = sinon.spy(utils, 'logWarn');
});
afterEach(function () {
utils.logWarn.restore();
});
it('should properly sync fields if both present', () => {
const adUnit = {
mediaTypes: {
banner: {
format: [{w: 100, h: 100}],
btype: [1, 2, 34], // should be overwritten with value from ortb2Imp
battr: [3, 4],
maxduration: 'omitted_value' // should be omitted during copying - not part of banner obj spec
}
},
ortb2Imp: {
banner: {
request: '{payload: true}',
pos: 5,
btype: [999, 999],
vcm: 0,
foobar: 'omitted_value' // should be omitted during copying - not part of banner obj spec
}
}
};
const expected = {
mediaTypes: {
banner: {
format: [{w: 100, h: 100}],
btype: [999, 999],
pos: 5,
battr: [3, 4],
vcm: 0,
maxduration: 'omitted_value'
}
},
ortb2Imp: {
banner: {
format: [{w: 100, h: 100}],
request: '{payload: true}',
pos: 5,
btype: [999, 999],
battr: [3, 4],
vcm: 0,
foobar: 'omitted_value'
}
}
};
syncOrtb2(adUnit, 'banner');
expect(adUnit).to.deep.eql(expected);
assert.ok(logWarnSpy.calledOnce, 'expected warning was logged due to conflicting btype');
});
it('should omit sync if mediaType not present on adUnit', () => {
const adUnit = {
mediaTypes: {
video: {
fieldToOmit: 'omitted_value'
}
},
ortb2Imp: {
video: {
fieldToOmit2: 'omitted_value'
}
}
};
syncOrtb2(adUnit, 'banner');
expect(adUnit.ortb2Imp.banner).to.be.undefined;
expect(adUnit.mediaTypes.banner).to.be.undefined;
});
it('should properly sync if mediaTypes is not present on any of side', () => {
const adUnit = {
mediaTypes: {
banner: {
format: [{w: 100, h: 100}],
btype: [999, 999],
pos: 5,
battr: [3, 4],
vcm: 0,
maxduration: 'omitted_value'
}
},
};
const expected1 = {
mediaTypes: {
banner: {
format: [{w: 100, h: 100}],
btype: [999, 999],
pos: 5,
battr: [3, 4],
vcm: 0,
maxduration: 'omitted_value'
}
},
ortb2Imp: {
banner: {
format: [{w: 100, h: 100}],
btype: [999, 999],
pos: 5,
battr: [3, 4],
vcm: 0,
}
}
};
syncOrtb2(adUnit, 'banner');
expect(adUnit).to.deep.eql(expected1);
const adUnit2 = {
mediaTypes: {},
ortb2Imp: {
banner: {
format: [{w: 100, h: 100}],
btype: [999, 999],
pos: 5,
battr: [3, 4],
vcm: 0,
maxduration: 'omitted_value'
}
}
};
const expected2 = {
mediaTypes: {
banner: {
format: [{w: 100, h: 100}],
btype: [999, 999],
pos: 5,
battr: [3, 4],
vcm: 0,
}
},
ortb2Imp: {
banner: {
format: [{w: 100, h: 100}],
btype: [999, 999],
pos: 5,
battr: [3, 4],
vcm: 0,
maxduration: 'omitted_value'
}
}
};
syncOrtb2(adUnit2, 'banner');
expect(adUnit2).to.deep.eql(expected2);
});
it('should not create empty banner object on ortb2Imp if there was nothing to copy', () => {
const adUnit2 = {
mediaTypes: {
banner: {
noOrtbBannerField1: 'value',
noOrtbBannerField2: 'value'
}
},
ortb2Imp: {
// lack of banner field
}
};
syncOrtb2(adUnit2, 'banner');
expect(adUnit2.ortb2Imp.banner).to.be.undefined
});
});
})