Skip to content

Commit

Permalink
ZetaGlobalSspBidAdapter: change logic around mediaType (#10074)
Browse files Browse the repository at this point in the history
* ZetaGlobalSsp: change logic with mediaType

* ZetaGlobalSsp: fix build

* ZetaGlobalSsp: fix tests

* ZetaGlobalSsp: fix tests (2)

* ZetaGlobalSsp: fix lint

* ZetaGlobalSsp: fix tests (3)

* ZetaGlobalSsp: fix tests (4)

---------

Co-authored-by: Surovenko Alexey <surovenko.alexey@gmail.com>
Co-authored-by: Alexey Surovenko <ASurovenko@vdhk6ddf9m.home>
  • Loading branch information
3 people authored Jun 8, 2023
1 parent ebd801c commit cfe7b5c
Show file tree
Hide file tree
Showing 2 changed files with 152 additions and 22 deletions.
27 changes: 9 additions & 18 deletions modules/zeta_global_sspBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ const TIMEOUT_URL = 'https://ssp.disqus.com/timeout/prebid';
const USER_SYNC_URL_IFRAME = 'https://ssp.disqus.com/sync?type=iframe';
const USER_SYNC_URL_IMAGE = 'https://ssp.disqus.com/sync?type=image';
const DEFAULT_CUR = 'USD';
const TTL = 200;
const TTL = 300;
const NET_REV = true;

const VIDEO_REGEX = new RegExp(/VAST\s+version/);

const DATA_TYPES = {
'NUMBER': 'number',
'STRING': 'string',
Expand Down Expand Up @@ -201,7 +199,10 @@ export const spec = {
advertiserDomains: zetaBid.adomain
};
}
provideMediaType(zetaBid, bid);
provideMediaType(zetaBid, bid, bidRequest.data);
if (bid.mediaType === VIDEO) {
bid.vastXml = bid.ad;
}
bidResponses.push(bid);
})
})
Expand Down Expand Up @@ -333,21 +334,11 @@ function provideEids(request, payload) {
}
}

function provideMediaType(zetaBid, bid) {
if (zetaBid.ext && zetaBid.ext.bidtype) {
if (zetaBid.ext.bidtype === VIDEO) {
bid.mediaType = VIDEO;
bid.vastXml = bid.ad;
} else {
bid.mediaType = BANNER;
}
function provideMediaType(zetaBid, bid, bidRequest) {
if (zetaBid.ext && zetaBid.ext.prebid && zetaBid.ext.prebid.type) {
bid.mediaType = zetaBid.ext.prebid.type === VIDEO ? VIDEO : BANNER;
} else {
if (VIDEO_REGEX.test(bid.ad)) {
bid.mediaType = VIDEO;
bid.vastXml = bid.ad;
} else {
bid.mediaType = BANNER;
}
bid.mediaType = bidRequest.imp[0].video ? VIDEO : BANNER;
}
}

Expand Down
147 changes: 143 additions & 4 deletions test/spec/modules/zeta_global_sspBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,87 @@ describe('Zeta Ssp Bid Adapter', function () {
params: params
}];

const zetaResponse = {
body: {
id: '12345',
seatbid: [
{
bid: [
{
id: 'auctionId',
impid: 'impId',
price: 0.0,
adm: 'adMarkup',
crid: 'creativeId',
adomain: [
'https://example.com'
],
h: 250,
w: 300
}
]
}
],
cur: 'USD'
}
}

const responseBannerPayload = {
data: {
id: '123',
site: {
id: 'SITE_ID',
page: 'page.com',
domain: 'domain.com'
},
user: {
id: '45asdf9tydhrty789adfad4678rew656789',
buyeruid: '1234567890'
},
cur: [
'USD'
],
imp: [
{
id: '1',
banner: {
h: 600,
w: 160
}
}
],
at: 1
}
};

const responseVideoPayload = {
data: {
id: '123',
site: {
id: 'SITE_ID',
page: 'page.com',
domain: 'domain.com'
},
user: {
id: '45asdf9tydhrty789adfad4678rew656789',
buyeruid: '1234567890'
},
cur: [
'USD'
],
imp: [
{
id: '1',
video: {
h: 600,
w: 160
}
}
],
at: 1
}
};

it('Test the bid validation function', function () {
const validBid = spec.isBidRequestValid(bannerRequest[0]);
const invalidBid = spec.isBidRequestValid(null);
Expand Down Expand Up @@ -224,7 +305,12 @@ describe('Zeta Ssp Bid Adapter', function () {
'https://example.com'
],
h: 250,
w: 300
w: 300,
ext: {
prebid: {
type: 'banner'
}
}
},
{
id: 'auctionId2',
Expand All @@ -238,7 +324,9 @@ describe('Zeta Ssp Bid Adapter', function () {
h: 150,
w: 200,
ext: {
bidtype: 'video'
prebid: {
type: 'video'
}
}
},
{
Expand All @@ -251,7 +339,12 @@ describe('Zeta Ssp Bid Adapter', function () {
'https://example3.com'
],
h: 400,
w: 300
w: 300,
ext: {
prebid: {
type: 'video'
}
}
}
]
}
Expand All @@ -260,7 +353,7 @@ describe('Zeta Ssp Bid Adapter', function () {
}
};

const bidResponse = spec.interpretResponse(response, null);
const bidResponse = spec.interpretResponse(response, responseBannerPayload);
expect(bidResponse).to.not.be.empty;

const bid1 = bidResponse[0];
Expand Down Expand Up @@ -465,4 +558,50 @@ describe('Zeta Ssp Bid Adapter', function () {
expect(payload.imp[0].banner.format[2].w).to.eql(100);
expect(payload.imp[0].banner.format[2].h).to.eql(150);
});

it('Test the response default mediaType:banner', function () {
const bidResponse = spec.interpretResponse(zetaResponse, responseBannerPayload);
expect(bidResponse).to.not.be.empty;
expect(bidResponse.length).to.eql(1);
expect(bidResponse[0].mediaType).to.eql(BANNER);
expect(bidResponse[0].ad).to.eql(zetaResponse.body.seatbid[0].bid[0].adm);
expect(bidResponse[0].vastXml).to.be.undefined;
});

it('Test the response default mediaType:video', function () {
const bidResponse = spec.interpretResponse(zetaResponse, responseVideoPayload);
expect(bidResponse).to.not.be.empty;
expect(bidResponse.length).to.eql(1);
expect(bidResponse[0].mediaType).to.eql(VIDEO);
expect(bidResponse[0].ad).to.eql(zetaResponse.body.seatbid[0].bid[0].adm);
expect(bidResponse[0].vastXml).to.eql(zetaResponse.body.seatbid[0].bid[0].adm);
});

it('Test the response mediaType:video from ext param', function () {
zetaResponse.body.seatbid[0].bid[0].ext = {
prebid: {
type: 'video'
}
}
const bidResponse = spec.interpretResponse(zetaResponse, responseBannerPayload);
expect(bidResponse).to.not.be.empty;
expect(bidResponse.length).to.eql(1);
expect(bidResponse[0].mediaType).to.eql(VIDEO);
expect(bidResponse[0].ad).to.eql(zetaResponse.body.seatbid[0].bid[0].adm);
expect(bidResponse[0].vastXml).to.eql(zetaResponse.body.seatbid[0].bid[0].adm);
});

it('Test the response mediaType:banner from ext param', function () {
zetaResponse.body.seatbid[0].bid[0].ext = {
prebid: {
type: 'banner'
}
}
const bidResponse = spec.interpretResponse(zetaResponse, responseVideoPayload);
expect(bidResponse).to.not.be.empty;
expect(bidResponse.length).to.eql(1);
expect(bidResponse[0].mediaType).to.eql(BANNER);
expect(bidResponse[0].ad).to.eql(zetaResponse.body.seatbid[0].bid[0].adm);
expect(bidResponse[0].vastXml).to.be.undefined;
});
});

0 comments on commit cfe7b5c

Please sign in to comment.