-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Welect Bid Adapter: update prebid compliance and add adapter back to master #7776
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 hidden or 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,106 @@ | ||
import * as utils from '../src/utils.js'; | ||
import { registerBidder } from '../src/adapters/bidderFactory.js'; | ||
|
||
const BIDDER_CODE = 'welect'; | ||
const DEFAULT_DOMAIN = 'www.welect.de'; | ||
|
||
export const spec = { | ||
code: BIDDER_CODE, | ||
aliases: ['wlt'], | ||
gvlid: 282, | ||
supportedMediaTypes: ['video'], | ||
|
||
// short code | ||
/** | ||
* Determines whether or not the given bid request is valid. | ||
* | ||
* @param {BidRequest} bid The bid params to validate. | ||
* @return boolean True if this is a valid bid, and false otherwise. | ||
*/ | ||
isBidRequestValid: function (bid) { | ||
return ( | ||
utils.deepAccess(bid, 'mediaTypes.video.context') === 'instream' && | ||
!!bid.params.placementId | ||
); | ||
}, | ||
/** | ||
* Make a server request from the list of BidRequests. | ||
* | ||
* @param {validBidRequests[]} - an array of bids | ||
* @return ServerRequest Info describing the request to the server. | ||
*/ | ||
buildRequests: function (validBidRequests) { | ||
return validBidRequests.map((bidRequest) => { | ||
let rawSizes = | ||
utils.deepAccess(bidRequest, 'mediaTypes.video.playerSize') || | ||
bidRequest.sizes; | ||
let size = rawSizes[0]; | ||
|
||
let domain = bidRequest.params.domain || DEFAULT_DOMAIN; | ||
|
||
let url = `https://${domain}/api/v2/preflight/${bidRequest.params.placementId}`; | ||
|
||
let gdprConsent = null; | ||
|
||
if (bidRequest && bidRequest.gdprConsent) { | ||
gdprConsent = { | ||
gdpr_consent: { | ||
gdprApplies: bidRequest.gdprConsent.gdprApplies, | ||
tcString: bidRequest.gdprConsent.gdprConsent, | ||
}, | ||
}; | ||
} | ||
|
||
const data = { | ||
width: size[0], | ||
height: size[1], | ||
bid_id: bidRequest.bidId, | ||
...gdprConsent, | ||
}; | ||
|
||
return { | ||
method: 'POST', | ||
url: url, | ||
data: data, | ||
options: { | ||
contentType: 'application/json', | ||
withCredentials: false, | ||
crossOrigin: true, | ||
}, | ||
}; | ||
}); | ||
}, | ||
/** | ||
* Unpack the response from the server into a list of bids. | ||
* | ||
* @param {ServerResponse} serverResponse A successful response from the server. | ||
* @return {Bid[]} An array of bids which were nested inside the server. | ||
*/ | ||
interpretResponse: function (serverResponse, bidRequest) { | ||
const responseBody = serverResponse.body; | ||
|
||
if (typeof responseBody !== 'object' || responseBody.available !== true) { | ||
return []; | ||
} | ||
|
||
const bidResponses = []; | ||
const bidResponse = { | ||
requestId: responseBody.bidResponse.requestId, | ||
cpm: responseBody.bidResponse.cpm, | ||
width: responseBody.bidResponse.width, | ||
height: responseBody.bidResponse.height, | ||
creativeId: responseBody.bidResponse.creativeId, | ||
currency: responseBody.bidResponse.currency, | ||
netRevenue: responseBody.bidResponse.netRevenue, | ||
ttl: responseBody.bidResponse.ttl, | ||
ad: responseBody.bidResponse.ad, | ||
vastUrl: responseBody.bidResponse.vastUrl, | ||
meta: { | ||
advertiserDomains: responseBody.bidResponse.meta.advertiserDomains | ||
} | ||
}; | ||
bidResponses.push(bidResponse); | ||
return bidResponses; | ||
}, | ||
}; | ||
registerBidder(spec); |
This file contains hidden or 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,211 @@ | ||
import { expect } from 'chai'; | ||
import { spec as adapter } from 'modules/welectBidAdapter.js'; | ||
|
||
describe('WelectAdapter', function () { | ||
describe('Check methods existance', function () { | ||
it('exists and is a function', function () { | ||
expect(adapter.isBidRequestValid).to.exist.and.to.be.a('function'); | ||
}); | ||
it('exists and is a function', function () { | ||
expect(adapter.buildRequests).to.exist.and.to.be.a('function'); | ||
}); | ||
it('exists and is a function', function () { | ||
expect(adapter.interpretResponse).to.exist.and.to.be.a('function'); | ||
}); | ||
}); | ||
|
||
describe('Check method isBidRequestValid return', function () { | ||
let bid = { | ||
bidder: 'welect', | ||
params: { | ||
placementId: 'exampleAlias', | ||
domain: 'www.welect.de' | ||
}, | ||
sizes: [[640, 360]], | ||
mediaTypes: { | ||
video: { | ||
context: 'instream' | ||
} | ||
}, | ||
}; | ||
let bid2 = { | ||
bidder: 'welect', | ||
params: { | ||
domain: 'www.welect.de' | ||
}, | ||
mediaTypes: { | ||
video: { | ||
context: 'instream', | ||
playerSize: [640, 360] | ||
} | ||
}, | ||
}; | ||
|
||
it('should be true', function () { | ||
expect(adapter.isBidRequestValid(bid)).to.be.true; | ||
}); | ||
|
||
it('should be false because the placementId is missing', function () { | ||
expect(adapter.isBidRequestValid(bid2)).to.be.false; | ||
}); | ||
}); | ||
|
||
describe('Check buildRequests method', function () { | ||
// Bids to be formatted | ||
let bid1 = { | ||
bidder: 'welect', | ||
params: { | ||
placementId: 'exampleAlias' | ||
}, | ||
sizes: [[640, 360]], | ||
mediaTypes: { | ||
video: { | ||
context: 'instream' | ||
} | ||
}, | ||
bidId: 'abdc' | ||
}; | ||
let bid2 = { | ||
bidder: 'welect', | ||
params: { | ||
placementId: 'exampleAlias', | ||
domain: 'www.welect2.de' | ||
}, | ||
sizes: [[640, 360]], | ||
mediaTypes: { | ||
video: { | ||
context: 'instream' | ||
} | ||
}, | ||
bidId: 'abdc', | ||
gdprConsent: { | ||
gdprApplies: 1, | ||
gdprConsent: 'some_string' | ||
} | ||
}; | ||
|
||
let data1 = { | ||
bid_id: 'abdc', | ||
width: 640, | ||
height: 360 | ||
} | ||
|
||
let data2 = { | ||
bid_id: 'abdc', | ||
width: 640, | ||
height: 360, | ||
gdpr_consent: { | ||
gdprApplies: 1, | ||
tcString: 'some_string' | ||
} | ||
} | ||
|
||
// Formatted requets | ||
let request1 = { | ||
method: 'POST', | ||
url: 'https://www.welect.de/api/v2/preflight/exampleAlias', | ||
data: data1, | ||
options: { | ||
contentType: 'application/json', | ||
withCredentials: false, | ||
crossOrigin: true, | ||
} | ||
}; | ||
|
||
let request2 = { | ||
method: 'POST', | ||
url: 'https://www.welect2.de/api/v2/preflight/exampleAlias', | ||
data: data2, | ||
options: { | ||
contentType: 'application/json', | ||
withCredentials: false, | ||
crossOrigin: true, | ||
} | ||
} | ||
|
||
it('defaults to www.welect.de, without gdpr object', function () { | ||
expect(adapter.buildRequests([bid1])).to.deep.equal([request1]); | ||
}) | ||
|
||
it('must return the right formatted requests, with gdpr object', function () { | ||
expect(adapter.buildRequests([bid2])).to.deep.equal([request2]); | ||
}); | ||
}); | ||
|
||
describe('Check interpretResponse method return', function () { | ||
// invalid server response | ||
let unavailableResponse = { | ||
body: { | ||
available: false | ||
} | ||
}; | ||
|
||
let availableResponse = { | ||
body: { | ||
available: true, | ||
bidResponse: { | ||
ad: { | ||
video: 'some vast url' | ||
}, | ||
meta: { | ||
advertiserDomains: [], | ||
}, | ||
cpm: 17, | ||
creativeId: 'svmpreview', | ||
currency: 'EUR', | ||
netRevenue: true, | ||
requestId: 'some bid id', | ||
ttl: 120, | ||
vastUrl: 'some vast url', | ||
height: 640, | ||
width: 320 | ||
} | ||
} | ||
} | ||
// bid Request | ||
let bid = { | ||
data: { | ||
bid_id: 'some bid id', | ||
width: 640, | ||
height: 320, | ||
gdpr_consent: { | ||
gdprApplies: 1, | ||
tcString: 'some_string' | ||
} | ||
}, | ||
method: 'POST', | ||
url: 'https://www.welect.de/api/v2/preflight/exampleAlias', | ||
options: { | ||
contentType: 'application/json', | ||
withCredentials: false, | ||
crossOrigin: true, | ||
} | ||
}; | ||
// Formatted reponse | ||
let result = { | ||
ad: { | ||
video: 'some vast url' | ||
}, | ||
meta: { | ||
advertiserDomains: [] | ||
}, | ||
cpm: 17, | ||
creativeId: 'svmpreview', | ||
currency: 'EUR', | ||
height: 640, | ||
netRevenue: true, | ||
requestId: 'some bid id', | ||
ttl: 120, | ||
vastUrl: 'some vast url', | ||
width: 320 | ||
} | ||
|
||
it('if response reflects unavailability, should be empty', function () { | ||
expect(adapter.interpretResponse(unavailableResponse, bid)).to.deep.equal([]); | ||
}); | ||
|
||
it('if response reflects availability, should equal result', function () { | ||
expect(adapter.interpretResponse(availableResponse, bid)).to.deep.equal([result]) | ||
}) | ||
}); | ||
}); |
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.
Can you please update this to import just the needed functions? We recently removed all the 'utils.' roots from adapters and modules.
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.
Yes will do, thank you