-
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
Teads Bid Adapter: support floc and uid2 user IDs #7116
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,23 @@ | ||
import {expect} from 'chai'; | ||
// import prebid.js to make processQueue available and flush hooks (in particular, those used for cookies) | ||
import 'src/prebid.js'; | ||
import {spec} from 'modules/teadsBidAdapter.js'; | ||
import {newBidder} from 'src/adapters/bidderFactory.js'; | ||
import {getStorageManager} from 'src/storageManager'; | ||
|
||
const ENDPOINT = 'https://a.teads.tv/hb/bid-request'; | ||
const AD_SCRIPT = '<script type="text/javascript" class="teads" async="true" src="https://a.teads.tv/hb/getAdSettings"></script>"'; | ||
|
||
describe('teadsBidAdapter', () => { | ||
const adapter = newBidder(spec); | ||
|
||
before(function () { | ||
// Following the introduction of tests involving reading/writing cookies, | ||
// this allows for running this spec as a single file with: | ||
// `gulp test --file "test/spec/modules/teadsBidAdapter_spec.js"`. | ||
window.$$PREBID_GLOBAL$$.processQueue(); | ||
}); | ||
|
||
describe('inherited functions', () => { | ||
it('exists and is a function', () => { | ||
expect(adapter.callBids).to.exist.and.to.be.a('function'); | ||
|
@@ -102,7 +112,7 @@ describe('teadsBidAdapter', () => { | |
'timeout': 3000 | ||
}; | ||
|
||
it('sends bid request to ENDPOINT via POST', function() { | ||
it('should send bid request to ENDPOINT via POST', function() { | ||
const request = spec.buildRequests(bidRequests, bidderResquestDefault); | ||
|
||
expect(request.url).to.equal(ENDPOINT); | ||
|
@@ -274,7 +284,6 @@ describe('teadsBidAdapter', () => { | |
}); | ||
|
||
it('should send GDPR to endpoint with 22 status', function() { | ||
let consentString = 'JRJ8RKfDeBNsERRDCSAAZ+A=='; | ||
let bidderRequest = { | ||
'auctionId': '1d1a030790a475', | ||
'bidderRequestId': '22edbae2733bf6', | ||
|
@@ -322,7 +331,6 @@ describe('teadsBidAdapter', () => { | |
}); | ||
|
||
it('should send GDPR to endpoint with 0 status when gdprApplies = false (vendorData = undefined)', function() { | ||
let consentString = 'JRJ8RKfDeBNsERRDCSAAZ+A=='; | ||
let bidderRequest = { | ||
'auctionId': '1d1a030790a475', | ||
'bidderRequestId': '22edbae2733bf6', | ||
|
@@ -377,7 +385,7 @@ describe('teadsBidAdapter', () => { | |
} | ||
} | ||
}; | ||
checkMediaTypesSizes(mediaTypesPlayerSize, '32x34') | ||
checkMediaTypesSizes(mediaTypesPlayerSize, '32x34'); | ||
}); | ||
|
||
it('should add schain info to payload if available', function () { | ||
|
@@ -416,7 +424,7 @@ describe('teadsBidAdapter', () => { | |
} | ||
} | ||
}; | ||
checkMediaTypesSizes(mediaTypesVideoSizes, '12x14') | ||
checkMediaTypesSizes(mediaTypesVideoSizes, '12x14'); | ||
}); | ||
|
||
it('should use good mediaTypes banner sizes', function() { | ||
|
@@ -427,7 +435,7 @@ describe('teadsBidAdapter', () => { | |
} | ||
} | ||
}; | ||
checkMediaTypesSizes(mediaTypesBannerSize, '46x48') | ||
checkMediaTypesSizes(mediaTypesBannerSize, '46x48'); | ||
}); | ||
|
||
it('should use good mediaTypes for both video and banner sizes', function() { | ||
|
@@ -441,7 +449,129 @@ describe('teadsBidAdapter', () => { | |
} | ||
} | ||
}; | ||
checkMediaTypesSizes(hybridMediaTypes, ['46x48', '50x34', '45x45']) | ||
checkMediaTypesSizes(hybridMediaTypes, ['46x48', '50x34', '45x45']); | ||
}); | ||
|
||
describe('User IDs', function () { | ||
const baseBidRequest = { | ||
'bidder': 'teads', | ||
'params': { | ||
'placementId': 10433394, | ||
'pageId': 1234 | ||
}, | ||
'adUnitCode': 'adunit-code', | ||
'sizes': [[300, 250], [300, 600]], | ||
'bidId': '30b31c1838de1e', | ||
'bidderRequestId': '22edbae2733bf6', | ||
'auctionId': '1d1a030790a475', | ||
'creativeId': 'er2ee', | ||
'deviceWidth': 1680 | ||
}; | ||
|
||
describe('FLoC ID', function () { | ||
it('should not add cohortId and cohortVersion params to payload if FLoC ID system is not enabled', function () { | ||
const bidRequest = { | ||
...baseBidRequest, | ||
userId: {} // no "flocId" property -> assumption that the FLoC ID system is disabled | ||
}; | ||
|
||
const request = spec.buildRequests([bidRequest], bidderResquestDefault); | ||
const payload = JSON.parse(request.data); | ||
|
||
expect(payload).not.to.have.property('cohortId'); | ||
expect(payload).not.to.have.property('cohortVersion'); | ||
}); | ||
|
||
it('should add cohortId param to payload if FLoC ID system is enabled and ID available, but not version', function () { | ||
const bidRequest = { | ||
...baseBidRequest, | ||
userId: { | ||
flocId: { | ||
id: 'my-floc-id' | ||
} | ||
} | ||
}; | ||
|
||
const request = spec.buildRequests([bidRequest], bidderResquestDefault); | ||
const payload = JSON.parse(request.data); | ||
|
||
expect(payload.cohortId).to.equal('my-floc-id'); | ||
expect(payload).not.to.have.property('cohortVersion'); | ||
}); | ||
|
||
it('should add cohortId and cohortVersion params to payload if FLoC ID system is enabled', function () { | ||
const bidRequest = { | ||
...baseBidRequest, | ||
userId: { | ||
flocId: { | ||
id: 'my-floc-id', | ||
version: 'chrome.1.1' | ||
} | ||
} | ||
}; | ||
|
||
const request = spec.buildRequests([bidRequest], bidderResquestDefault); | ||
const payload = JSON.parse(request.data); | ||
|
||
expect(payload.cohortId).to.equal('my-floc-id'); | ||
expect(payload.cohortVersion).to.equal('chrome.1.1'); | ||
}); | ||
}); | ||
|
||
describe('Unified ID v2', function () { | ||
it('should not add unifiedId2 param to payload if uid2 system is not enabled', function () { | ||
const bidRequest = { | ||
...baseBidRequest, | ||
userId: {} // no "uid2" property -> assumption that the Unified ID v2 system is disabled | ||
}; | ||
|
||
const request = spec.buildRequests([bidRequest], bidderResquestDefault); | ||
const payload = JSON.parse(request.data); | ||
|
||
expect(payload).not.to.have.property('unifiedId2'); | ||
}); | ||
|
||
it('should add unifiedId2 param to payload if uid2 system is enabled', function () { | ||
const bidRequest = { | ||
...baseBidRequest, | ||
userId: { | ||
uid2: { | ||
id: 'my-unified-id-2' | ||
} | ||
} | ||
}; | ||
|
||
const request = spec.buildRequests([bidRequest], bidderResquestDefault); | ||
const payload = JSON.parse(request.data); | ||
|
||
expect(payload.unifiedId2).to.equal('my-unified-id-2'); | ||
}) | ||
}); | ||
|
||
describe('First-party cookie Teads ID', function () { | ||
const storage = getStorageManager(132, 'teads'); | ||
|
||
afterEach(function () { | ||
// drop cookie | ||
storage.setCookie('_tfpvi', '', new Date(0)); | ||
}); | ||
|
||
it('should not add firstPartyCookieTeadsId param to payload if first-party cookie is not available', function () { | ||
const request = spec.buildRequests([baseBidRequest], bidderResquestDefault); | ||
const payload = JSON.parse(request.data); | ||
|
||
expect(payload).not.to.have.property('firstPartyCookieTeadsId'); | ||
}); | ||
|
||
it('should add firstPartyCookieTeadsId param to payload if first-party cookie is available', function () { | ||
storage.setCookie('_tfpvi', 'my-teads-id'); | ||
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. We do not want to actually be setting and reading from storage / cookies inside of tests. We should be mocking the stubbing / mocking the storage manager, which has its own tests to verify it works. Here is an example: You'll need to export your storage var so that your tests can mock it: Then in your beforeEach you should setup the stub Don't forget to restore it back in the afterEach Then in your tests you can set them up to return what you want and make sure your module works as expected: |
||
|
||
const request = spec.buildRequests([baseBidRequest], bidderResquestDefault); | ||
const payload = JSON.parse(request.data); | ||
|
||
expect(payload.firstPartyCookieTeadsId).to.equal('my-teads-id'); | ||
}); | ||
}); | ||
}); | ||
|
||
function checkMediaTypesSizes(mediaTypes, expectedSizes) { | ||
|
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.
With the stubbing of storage, you can get rid of this I believe.
This type of code in test files can cause downstream tests to be very flakey.
We do not want to modify the window object and its contents if we do not have to in tests.