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

UNICORN Adapter - accept multiple formats #6255

Merged
merged 3 commits into from
Feb 3, 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
18 changes: 14 additions & 4 deletions modules/unicornBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const BIDDER_CODE = 'unicorn';
const UNICORN_ENDPOINT = 'https://ds.uncn.jp/pb/0/bid.json';
const UNICORN_DEFAULT_CURRENCY = 'JPY';
const UNICORN_PB_COOKIE_KEY = '__pb_unicorn_aud';
const UNICORN_PB_VERSION = '1.0';

/**
* Placement ID and Account ID are required.
Expand Down Expand Up @@ -47,12 +48,12 @@ function buildOpenRtbBidRequestPayload(validBidRequests, bidderRequest) {
bidderRequest
);
const imp = validBidRequests.map(br => {
const sizes = utils.parseSizesInput(br.sizes)[0];
return {
id: br.bidId,
banner: {
w: sizes.split('x')[0],
h: sizes.split('x')[1]
format: makeFormat(br.sizes),
w: br.sizes[0][0],
h: br.sizes[0][1],
},
tagid: utils.deepAccess(br, 'params.placementId') || br.adUnitCode,
secure: 1,
Expand Down Expand Up @@ -84,7 +85,8 @@ function buildOpenRtbBidRequestPayload(validBidRequests, bidderRequest) {
source: {
ext: {
stype: 'prebid_uncn',
bidder: BIDDER_CODE
bidder: BIDDER_CODE,
prebid_version: UNICORN_PB_VERSION
}
},
ext: {
Expand Down Expand Up @@ -138,6 +140,14 @@ const getUid = () => {
}
};

/**
* Make imp.banner.format
* @param {Array<Number>} arr
*/
const makeFormat = arr => arr.map((s) => {
return { w: s[0], h: s[1] };
});

export const spec = {
code: BIDDER_CODE,
aliases: ['uncn'],
Expand Down
51 changes: 37 additions & 14 deletions test/spec/modules/unicornBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ const bidRequests = [
},
mediaTypes: {
banner: {
sizes: [[300, 250]]
sizes: [[300, 250], [336, 280]]
}
},
adUnitCode: '/19968336/header-bid-tag-0',
transactionId: 'ea0aa332-a6e1-4474-8180-83720e6b87bc',
sizes: [[300, 250]],
sizes: [[300, 250], [336, 280]],
bidId: '226416e6e6bf41',
bidderRequestId: '1f41cbdcbe58d5',
auctionId: '77987c3a-9be9-4e43-985a-26fc91d84724',
Expand Down Expand Up @@ -81,12 +81,12 @@ const validBidRequests = [
},
mediaTypes: {
banner: {
sizes: [[300, 250]]
sizes: [[300, 250], [336, 280]]
}
},
adUnitCode: '/19968336/header-bid-tag-0',
transactionId: 'fbf94ccf-f377-4201-a662-32c2feb8ab6d',
sizes: [[300, 250]],
sizes: [[300, 250], [336, 280]],
bidId: '2fb90842443e24',
bidderRequestId: '123ae4cc3eeb7e',
auctionId: 'c594a888-6744-46c6-8b0e-d188e40e83ef',
Expand Down Expand Up @@ -156,12 +156,12 @@ const bidderRequest = {
},
mediaTypes: {
banner: {
sizes: [[300, 250]]
sizes: [[300, 250], [336, 280]]
}
},
adUnitCode: '/19968336/header-bid-tag-0',
transactionId: 'fbf94ccf-f377-4201-a662-32c2feb8ab6d',
sizes: [[300, 250]],
sizes: [[300, 250], [336, 280]],
bidId: '2fb90842443e24',
bidderRequestId: '123ae4cc3eeb7e',
auctionId: 'c594a888-6744-46c6-8b0e-d188e40e83ef',
Expand Down Expand Up @@ -234,8 +234,18 @@ const openRTBRequest = {
{
id: '216255f234b602',
banner: {
w: '300',
h: '250'
w: 300,
h: 250,
format: [
{
w: 300,
h: 250
},
{
w: 336,
h: 280
}
]
},
secure: 1,
bidfloor: 0,
Expand All @@ -244,8 +254,14 @@ const openRTBRequest = {
{
id: '31e2b28ced2475',
banner: {
w: '300',
h: '250'
w: 300,
h: 250,
format: [
{
w: 300,
h: 250
}
]
},
secure: 1,
bidfloor: 0,
Expand All @@ -254,8 +270,14 @@ const openRTBRequest = {
{
id: '40a333e047a9bd',
banner: {
w: '300',
h: '250'
w: 300,
h: 250,
format: [
{
w: 300,
h: 250
}
]
},
secure: 1,
bidfloor: 0,
Expand Down Expand Up @@ -287,7 +309,8 @@ const openRTBRequest = {
source: {
ext: {
stype: 'prebid_uncn',
bidder: 'unicorn'
bidder: 'unicorn',
prebid_version: '1.0'
}
}
};
Expand Down Expand Up @@ -378,7 +401,7 @@ const request = {
method: 'POST',
url: 'https://ds.uncn.jp/pb/0/bid.json',
data:
'{"id":"5ebea288-f13a-4754-be6d-4ade66c68877","at":1,"imp":[{"id":"216255f234b602","banner":{"w":"300","h":"250"},"secure":1,"bidfloor":0,"tagid":"/19968336/header-bid-tag-0"},{"id":"31e2b28ced2475","banner":{"w":"300","h":"250"},"secure":1,"bidfloor":0"tagid":"/19968336/header-bid-tag-1"},{"id":"40a333e047a9bd","banner":{"w":"300","h":"250"},"secure":1,"bidfloor":0,"tagid":"/19968336/header-bid-tag-2"}],"cur":"JPY","site":{"id":"uni-corn.net","publisher":{"id":12345},"domain":"uni-corn.net","page":"https://uni-corn.net/","ref":"https://uni-corn.net/"},"device":{"language":"ja","ua":"Mozilla/5.0 (Linux; Android 8.0.0; ONEPLUS A5000) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.93 Mobile Safari/537.36"},"user":{"id":"69d9e1c2-801e-4901-a665-fad467550fec"},"bcat":[],"source":{"ext":{"stype":"prebid_uncn","bidder":"unicorn"}}}'
'{"id":"5ebea288-f13a-4754-be6d-4ade66c68877","at":1,"imp":[{"id":"216255f234b602","banner":{"w":300,"h":250},"format":[{"w":300,"h":250},{"w":336,"h":280}],"secure":1,"bidfloor":0,"tagid":"/19968336/header-bid-tag-0"},{"id":"31e2b28ced2475","banner":{"w":"300","h":"250"},"format":[{"w":"300","h":"250"}],"secure":1,"bidfloor":0"tagid":"/19968336/header-bid-tag-1"},{"id":"40a333e047a9bd","banner":{"w":300,"h":250},"format":[{"w":300,"h":250}],"secure":1,"bidfloor":0,"tagid":"/19968336/header-bid-tag-2"}],"cur":"JPY","site":{"id":"uni-corn.net","publisher":{"id":12345},"domain":"uni-corn.net","page":"https://uni-corn.net/","ref":"https://uni-corn.net/"},"device":{"language":"ja","ua":"Mozilla/5.0 (Linux; Android 8.0.0; ONEPLUS A5000) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.93 Mobile Safari/537.36"},"user":{"id":"69d9e1c2-801e-4901-a665-fad467550fec"},"bcat":[],"source":{"ext":{"stype":"prebid_uncn","bidder":"unicorn","prebid_version":"1.0"}}}'
};

const interpretedBids = [
Expand Down