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

AdYouLike Bid Adapter: replace shorthand "image" native config #6401

Merged
merged 5 commits into from
Mar 19, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
32 changes: 31 additions & 1 deletion modules/adyoulikeBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,30 @@ const VERSION = '1.0';
const BIDDER_CODE = 'adyoulike';
const DEFAULT_DC = 'hb-api';

const NATIVE_IMAGE = {
image: {
required: true
},
title: {
required: true
},
sponsoredBy: {
required: true
},
clickUrl: {
required: true
},
body: {
required: false
},
icon: {
required: false
},
cta: {
required: false
}
};

export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [BANNER, NATIVE],
Expand Down Expand Up @@ -44,7 +68,13 @@ export const spec = {
accumulator[bid.bidId].Width = size.width;
accumulator[bid.bidId].Height = size.height;
accumulator[bid.bidId].AvailableSizes = sizesArray.join(',');
if (bid.mediaTypes && bid.mediaTypes.native) accumulator[bid.bidId].Native = bid.mediaTypes.native;
if (bid.mediaTypes && bid.mediaTypes.native) {
let nativeReq = bid.mediaTypes.native;
if (nativeReq.type === 'image') {
nativeReq = Object.assign({}, NATIVE_IMAGE, nativeReq);
}
accumulator[bid.bidId].Native = nativeReq;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

@guiann So when a pub defines a "short native config type" will it always only have the single key type ?

Is it possible that a pub would want to use the short type, but also be able to override the default fields?

Maybe instead of

nativeReq = NATIVE_IMAGE;

We merge the pub provided bid.mediaTypes.native onto the NATIVE_IMAGE default?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was thinking if a publisher uses the shorthand they won't want to spend time with fine tuning... but yes we can handle this case. I'll do the merge of the two objects.

Again, do every adapters have to handle this case by themselves ? Unfolding shorthand formats should be a more global treatment, don't you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

change is done.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, agrees we should handle shorthands in core prebid

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You can upvote the issue I've opened here :
#6389

Thank you.

return accumulator;
}, {}),
PageRefreshed: getPageRefreshed()
Expand Down
71 changes: 71 additions & 0 deletions test/spec/modules/adyoulikeBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,29 @@ describe('Adyoulike Adapter', function () {
}
];

const bidRequestWithNativeImageType = [
{
'bidId': 'bid_id_0',
'bidder': 'adyoulike',
'placementCode': 'adunit/hb-0',
'params': {
'placement': 'placement_0'
},
'sizes': '300x250',
'mediaTypes':
{
'native': {
'type': 'image',
'additional': {
'will': 'be',
'sent': ['300x250']
}
},
},
'transactionId': 'bid_id_0_transaction_id'
}
];

const sentBidNative = {
'bid_id_0': {
'PlacementID': 'e622af275681965d3095808561a1e510',
Expand Down Expand Up @@ -135,6 +158,37 @@ describe('Adyoulike Adapter', function () {
}
};

const sentNativeImageType = {
'additional': {
'sent': [
'300x250'
],
'will': 'be'
},
'body': {
'required': false
},
'clickUrl': {
'required': true
},
'cta': {
'required': false
},
'icon': {
'required': false
},
'image': {
'required': true
},
'sponsoredBy': {
'required': true
},
'title': {
'required': true
},
'type': 'image'
};

const bidRequestWithDCPlacement = [
{
'bidId': 'bid_id_0',
Expand Down Expand Up @@ -341,6 +395,23 @@ describe('Adyoulike Adapter', function () {
canonicalQuery.restore();
});

it('Should expand short native image config type', function() {
const request = spec.buildRequests(bidRequestWithNativeImageType, bidderRequest);
const payload = JSON.parse(request.data);

expect(request.url).to.contain(getEndpoint());
expect(request.method).to.equal('POST');
expect(request.url).to.contains('CanonicalUrl=' + encodeURIComponent(canonicalUrl));
expect(request.url).to.contains('RefererUrl=' + encodeURIComponent(referrerUrl));
expect(request.url).to.contains('PublisherDomain=http%3A%2F%2Flocalhost%3A9876');

expect(payload.Version).to.equal('1.0');
expect(payload.Bids['bid_id_0'].PlacementID).to.be.equal('placement_0');
expect(payload.PageRefreshed).to.equal(false);
expect(payload.Bids['bid_id_0'].TransactionID).to.be.equal('bid_id_0_transaction_id');
expect(payload.Bids['bid_id_0'].Native).deep.equal(sentNativeImageType);
});

it('should add gdpr/usp consent information to the request', function () {
let consentString = 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A==';
let uspConsentData = '1YCC';
Expand Down