-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Core: Sync between ortb2Imp and mediaTypes (#12423)
* ortb2 <-> mediaTypes * native & banner params * syncOrtb2 * improvements * improvement * lint fix * type check * instance of Map check * get rid of entries * removing native from syncOrtb2 * Update test/spec/banner_spec.js Co-authored-by: Demetrio Girardi <[email protected]> * Update src/prebid.js Co-authored-by: Demetrio Girardi <[email protected]> * Update prebid.js * video test fix --------- Co-authored-by: Marcin Komorski <[email protected]> Co-authored-by: Patrick McCann <[email protected]> Co-authored-by: Demetrio Girardi <[email protected]>
- Loading branch information
1 parent
80364ce
commit 05d9c74
Showing
6 changed files
with
442 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { isArrayOfNums, isInteger, isStr } from './utils.js'; | ||
|
||
/** | ||
* List of OpenRTB 2.x banner object properties with simple validators. | ||
* Not included: `ext` | ||
* reference: https://github.com/InteractiveAdvertisingBureau/openrtb2.x/blob/main/2.6.md | ||
*/ | ||
export const ORTB_BANNER_PARAMS = new Map([ | ||
[ 'format', value => Array.isArray(value) && value.length > 0 && value.every(v => typeof v === 'object') ], | ||
[ 'w', isInteger ], | ||
[ 'h', isInteger ], | ||
[ 'btype', isArrayOfNums ], | ||
[ 'battr', isArrayOfNums ], | ||
[ 'pos', isInteger ], | ||
[ 'mimes', value => Array.isArray(value) && value.length > 0 && value.every(v => typeof v === 'string') ], | ||
[ 'topframe', value => [1, 0].includes(value) ], | ||
[ 'expdir', isArrayOfNums ], | ||
[ 'api', isArrayOfNums ], | ||
[ 'id', isStr ], | ||
[ 'vcm', value => [1, 0].includes(value) ] | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 | ||
}); | ||
}); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.