-
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
Core: Sync between ortb2Imp and mediaTypes #12423
Open
mkomorski
wants to merge
11
commits into
master
Choose a base branch
from
user/mkomorski/12166-mediatypes-ortb2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
4a59ebf
ortb2 <-> mediaTypes
971a687
native & banner params
mkomorski 43ee07f
syncOrtb2
fdb2780
improvements
175e94b
improvement
mkomorski b1b013e
lint fix
mkomorski a10a0d8
type check
mkomorski 2ae9306
instance of Map check
mkomorski 39d5e18
get rid of entries
mkomorski 1303c5a
Merge branch 'master' into user/mkomorski/12166-mediatypes-ortb2
mkomorski d092151
removing native from syncOrtb2
mkomorski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,183 @@ | ||||
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' | ||||
} | ||||
}, | ||||
ortb2Imp: {} | ||||
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.
Suggested change
|
||||
}; | ||||
|
||||
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.