Skip to content

Commit

Permalink
Native ads: change asset param (#8371)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbartek25 authored May 10, 2022
1 parent 6dbad9a commit c66840c
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 22 deletions.
14 changes: 12 additions & 2 deletions modules/improvedigitalBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,10 @@ const ID_REQUEST = {
}

if (deepAccess(bidRequest, 'mediaTypes.native')) {
imp.native = this.buildNativeRequest(bidRequest);
const nativeImp = this.buildNativeRequest(bidRequest);
if (nativeImp) {
imp.native = nativeImp;
}
}

return imp;
Expand Down Expand Up @@ -358,7 +361,10 @@ const ID_REQUEST = {
},

buildNativeRequest(bidRequest) {
const nativeParams = bidRequest.mediaTypes.native;
const nativeParams = bidRequest.nativeParams;
if (!nativeParams) {
return null;
}
const request = {
assets: [],
}
Expand Down Expand Up @@ -392,6 +398,10 @@ const ID_REQUEST = {
request.assets.push(asset);
}
}
if (!request.assets.length) {
logWarn('No native assets recognized. Ignoring native ad request');
return null;
}
return { ver: NATIVE_DATA.VERSION, request: JSON.stringify(request) };
},

Expand Down
71 changes: 51 additions & 20 deletions test/spec/modules/improvedigitalBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect } from 'chai';
import { spec } from 'modules/improvedigitalBidAdapter.js';
import { config } from 'src/config.js';
import { deepClone } from 'src/utils.js';
import {BANNER, VIDEO} from '../../../src/mediaTypes';
import {BANNER, NATIVE, VIDEO} from '../../../src/mediaTypes';

describe('Improve Digital Adapter Tests', function () {
const METHOD = 'POST';
Expand Down Expand Up @@ -50,17 +50,31 @@ describe('Improve Digital Adapter Tests', function () {
}
};

const nativeBidRequest = deepClone(simpleBidRequest);
nativeBidRequest.mediaTypes = { native: {} };
nativeBidRequest.nativeParams = {
title: {required: true},
body: {required: true}
};

const multiFormatBidRequest = deepClone(simpleBidRequest);
multiFormatBidRequest.mediaTypes = {
banner: {
sizes: [[300, 250], [160, 600]]
},
native: {},
video: {
context: 'outstream',
playerSize: [640, 480]
}
};

multiFormatBidRequest.nativeParams = {
body: {
required: true
}
};

const simpleSmartTagBidRequest = {
bidder: 'improvedigital',
bidId: '1a2b3c',
Expand All @@ -87,6 +101,10 @@ describe('Improve Digital Adapter Tests', function () {
bids: [multiFormatBidRequest]
};

const nativeBidderRequest = {
bids: [nativeBidRequest]
};

const bidderRequestGdpr = {
bids: [simpleBidRequest],
gdprConsent: {
Expand Down Expand Up @@ -197,6 +215,10 @@ describe('Improve Digital Adapter Tests', function () {
expect(payload.imp).to.deep.equal([
{
id: '33e9500b21129f',
native: {
request: '{"assets":[{"id":3,"required":1,"data":{"type":2}}]}',
ver: '1.2'
},
secure: 0,
ext: {
bidder: {
Expand All @@ -220,6 +242,28 @@ describe('Improve Digital Adapter Tests', function () {
getConfigStub.restore();
});

it('should make a well-formed native request', function () {
const payload = JSON.parse(spec.buildRequests([nativeBidRequest])[0].data);
expect(payload.imp[0].native).to.deep.equal({
ver: '1.2',
request: '{\"assets\":[{\"id\":0,\"required\":1,\"title\":{\"len\":140}},{\"id\":3,\"required\":1,\"data\":{\"type\":2}}]}'
});
});

it('should not make native request when nativeParams is undefined', function () {
const request = deepClone(nativeBidRequest);
delete request.nativeParams;
const payload = JSON.parse(spec.buildRequests([request])[0].data);
expect(payload.imp[0].native).to.not.exist;
});

it('should not make native request when no assets', function () {
const request = deepClone(nativeBidRequest);
request.nativeParams = {};
const payload = JSON.parse(spec.buildRequests([request])[0].data);
expect(payload.imp[0].native).to.not.exist;
});

it('should set placementKey and publisherId for smart tags', function () {
const payload = JSON.parse(spec.buildRequests([simpleSmartTagBidRequest], bidderRequest)[0].data);
expect(payload.imp[0].ext.bidder.publisherId).to.equal(1032);
Expand All @@ -238,20 +282,6 @@ describe('Improve Digital Adapter Tests', function () {
expect(payload.imp[0].ext.bidder.keyValues).to.deep.equal(keyValues);
});

// it('should add single size filter', function () {
// const bidRequest = Object.assign({}, simpleBidRequest);
// const size = {
// w: 800,
// h: 600
// };
// bidRequest.params.size = size;
// const payload = JSON.parse(spec.buildRequests([bidRequest], bidderRequest).data);
// expect(payload.imp[0].banner).to.deep.equal(size);
// // When single size filter is set, format shouldn't be populated. This
// // is to maintain backward compatibily
// expect(payload.imp[0].banner.format).to.not.exist;
// });

it('should add currency', function () {
const bidRequest = Object.assign({}, simpleBidRequest);
const getConfigStub = sinon.stub(config, 'getConfig').returns('JPY');
Expand Down Expand Up @@ -790,7 +820,7 @@ describe('Improve Digital Adapter Tests', function () {
'id': '52098fad-20c1-476b-a4fa-41e275e5a4a5',
'price': 1.8600000000000003,
'adm': "{\"ver\":\"1.1\",\"imptrackers\":[\"https://secure.adnxs.com/imptr?id=52311&t=2\",\"https://euw-ice.360yield.com/imp_pixel?ic=hcUBlCANx1FabHBf6FR2gC7UO4xEyXahdZAn0-B5qL-bb3A74BJ1smyWIyW7IWcC0SOjSXzVpevTHXxTqJ.sf.Qhahyy6tSo.0j1QWfXlH8sM4-8vKWjMjw-x.IrJJNlwkQ0s1CdwcwTefcLXm5l2E-W19VhACuV7f3mgrZMNjiSw.SjJAfyPC3SIyAMRjYfj53UmjriQ46T7lhmkqxK8wHmksYCdbZc3PZESk8NWl28sxdjNvnYYCFMcJbeav.LOLabyTXfwy-1cEPbQs.IKMRZIKaqccTDPV3wOtzbNv0jQzatd3Nnv-PGFQcjQ-GW3i27W04Fws4kodpFSn-B6VwZAjzLzoyd5gBncyRnAyCplEbgHU5sZ1IyKHWjgCl3ZtRIK5vqrRD5D-xqgSnOi7-phG.CqZWDZ4bMDSfQg2ZnbvUTyGKcEl0WR59dW5izTMV4Fjizcrvr5T-t.zMbGwz.hGnmLIyhTqh.IcwW.GiDLVExlDlix5S1LXIWVsSyrQ==\"],\"assets\":[{\"id\":1,\"data\":{\"value\":\"ImproveDigital\",\"type\":1}},{\"id\":3,\"data\":{\"value\":\"Test content.\",\"type\":2}},{\"id\":0,\"title\":{\"text\":\"Sample Prebid Test Title\"}}],\"link\":{\"url\":\"https://euw-ice.360yield.com/click/hcUBlHOV7YhVse8RyBa0ajjyPa9Vt17e4g-1m3cRj3E67vq-RYux.SiUeAmBfNBcoOqkUc6A15AWmi4yFu5K-BdkaYjildyyk7fNLyR6hWr411kv4vrFwm5jrIBceuHS6K8oN69f.uCo8zGTdR2TbSlldwcpahQPlufZU.6VaMsu4IC53uEiUT5vb7kAw6TTlxuGBNq6zaGryiWEV2.N3YYJDTyYPh8tv-ZFyeFZFm0Gnjv.xWbC.70JcRUVU9UelQaPsTpTWYTXBhJt84YJUw1-GNtaLNVLSjjZbVoA2fsMti5p6OBmF.7u39on2OPgvseIkSmge7Pqg63pRqdP75hp.DAEk6OkcN1jGnwP2DSbvpaSbin5lVqjfO0B-wnQgfQTCUtM5v4JmkNweLhUf9Q-x.nPKLW5SccEk9ZFXzY2-1wpT3PWm8Tix3NRscLPZub9wHzL..pl6ip8cQ9hp16UjwT4H6RMAxL0R7bl-h2pAicGAzYmuO7ntRESKUoIWA==//http%3A%2F%2Fquantum-advertising.com%2Ffr%2F\"},\"jstracker\":\"<script type=\\\"application/javascript\\\">var js_tracker = ['https://secure.adnxs.com/imptr?id=52312&t=1', 'https://pixel.adsafeprotected.com/rjss/st/291611/36974035/skeleton.js?ias_adpath=[class~=ea_improve_pid_${TAG_ID}]']</script>\"}",
'impid': '2d7a7db325c6f',
'impid': '33e9500b21129f',
'cid': '196108'
}
],
Expand Down Expand Up @@ -1043,10 +1073,6 @@ describe('Improve Digital Adapter Tests', function () {
//
// Native ads
it('should return a well-formed native ad bid', function () {
const nativeBidderRequest = JSON.parse(JSON.stringify(bidderRequest));
nativeBidderRequest.bids[0].bidId = '2d7a7db325c6f';
delete nativeBidderRequest.bids[0].mediaTypes.banner;
nativeBidderRequest.bids[0].mediaTypes.native = {};
const bids = spec.interpretResponse(serverResponseNative, {bidderRequest: nativeBidderRequest});
// Verify Native Response
expect(bids[0].native).to.exist;
Expand All @@ -1063,6 +1089,11 @@ describe('Improve Digital Adapter Tests', function () {
expect(nativeBid.body).to.exist.and.equal('Test content.');
});

it('should return a well-formed native bid for multi-format ad unit', function () {
const bids = spec.interpretResponse(serverResponseNative, {bidderRequest: multiFormatBidderRequest});
expect(bids[0].mediaType).to.equal(NATIVE);
});

// Video
it('should return a well-formed instream video bid', function () {
const bids = spec.interpretResponse(serverResponseVideo, {bidderRequest: instreamBidderRequest});
Expand Down

0 comments on commit c66840c

Please sign in to comment.