forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
includes a type property to all events (prebid#9771)
- Loading branch information
1 parent
8fe7115
commit 5db8560
Showing
4 changed files
with
42 additions
and
6 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 |
---|---|---|
@@ -1,5 +1,19 @@ | ||
import { videoKey } from '../constants/constants.js' | ||
|
||
export function getExternalVideoEventName(eventName) { | ||
if (!eventName) { | ||
return ''; | ||
} | ||
return videoKey + eventName.replace(/^./, eventName[0].toUpperCase()); | ||
} | ||
|
||
export function getExternalVideoEventPayload(eventName, payload) { | ||
if (!payload) { | ||
payload = {}; | ||
} | ||
|
||
if (!payload.type) { | ||
payload.type = eventName; | ||
} | ||
return payload; | ||
} |
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
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,22 @@ | ||
import { getExternalVideoEventName, getExternalVideoEventPayload } from 'libraries/video/shared/helpers.js'; | ||
import { expect } from 'chai'; | ||
|
||
describe('Helpers', function () { | ||
describe('getExternalVideoEventName', function () { | ||
it('should append video prefix and stay camelcase', function () { | ||
expect(getExternalVideoEventName('eventName')).to.equal('videoEventName'); | ||
expect(getExternalVideoEventName(null)).to.equal(''); | ||
}); | ||
}); | ||
|
||
describe('getExternalVideoEventPayload', function () { | ||
it('should include type in payload when absent', function () { | ||
const testType = 'testType'; | ||
const payloadWithType = { datum: 'datum', type: 'existingType' }; | ||
expect(getExternalVideoEventPayload(testType, payloadWithType).type).to.equal('existingType'); | ||
|
||
const payloadWithoutType = { datum: 'datum' }; | ||
expect(getExternalVideoEventPayload(testType, payloadWithoutType).type).to.equal(testType); | ||
}); | ||
}); | ||
}); |