Skip to content
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

PBS Bid Adapter: add dchain (demand chain object) to prebid server adapter #6383

Merged
merged 6 commits into from
Mar 4, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions modules/prebidServerBidAdapter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,7 @@ const OPEN_RTB_PROTOCOL = {
if (bid.burl) { bidObject.burl = bid.burl; }
bidObject.currency = (response.cur) ? response.cur : DEFAULT_S2S_CURRENCY;
bidObject.meta = bidObject.meta || {};
if (bid.ext && bid.ext.dchain) { bidObject.meta.dchain = bid.ext.dchain; }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the unit test below, dchain is an object, not a stringified object, so I think there's a problem here.
This isn't a deep copy -- believe the right way to copy a full object would be something like this:

Object.assign(bidObject.meta.dchain, bid.ext.dchain);

@ChrisHuie - please confirm?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

happy to make that change, but i'm curious why my test would have passed if this is a problem

Copy link
Collaborator

@ChrisHuie ChrisHuie Mar 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I am fully understanding what you are asking. Object.assign doesn't exactly deep copy but it does create a new clone from the source object that copies over the properties and is then allocated differently in memory. The "=" sign, in this case, instead is referencing the source property which acts just like a pointer to the same memory slot. So if bidObject.meta.dchain changes then bid.ext.dchain would also change and vice-versa I believe. With object.assign changing the property wouldn't affect bid.ext.dchain or the other way around.

I think object.assign is better for the side effect reason but shouldn't impact these tests

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i changed to utils.deepClone

if (bid.adomain) { bidObject.meta.advertiserDomains = bid.adomain; }

// the OpenRTB location for "TTL" as understood by Prebid.js is "exp" (expiration).
Expand Down
4 changes: 4 additions & 0 deletions test/spec/modules/prebidServerBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ const RESPONSE_OPENRTB = {
'win': 'http://wurl.org?id=333'
}
},
'dchain': { 'ver': '1.0', 'complete': 0, 'nodes': [ { 'asi': 'magnite.com', 'bsid': '123456789', } ] },
'bidder': {
'appnexus': {
'brand_id': 1,
Expand Down Expand Up @@ -1936,6 +1937,9 @@ describe('S2S Adapter', function () {
expect(response).to.have.property('meta');
expect(response.meta).to.have.property('advertiserDomains');
expect(response.meta.advertiserDomains[0]).to.equal('appnexus.com');
expect(response.meta).to.have.property('dchain');
expect(response.meta.dchain.ver).to.equal('1.0');
expect(response.meta.dchain.nodes[0].asi).to.equal('magnite.com');
expect(response).to.not.have.property('vastUrl');
expect(response).to.not.have.property('videoCacheKey');
expect(response).to.have.property('ttl', 60);
Expand Down