From a7b95cfee400883c57dc440aee266a19f640f466 Mon Sep 17 00:00:00 2001 From: Antonios Sarhanis Date: Wed, 6 Mar 2024 06:35:31 +1100 Subject: [PATCH] Fix for bids without userId specified. (#11170) --- modules/adnuntiusBidAdapter.js | 15 +++++++------- test/spec/modules/adnuntiusBidAdapter_spec.js | 20 +++++++++++++++++++ 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/modules/adnuntiusBidAdapter.js b/modules/adnuntiusBidAdapter.js index 02dd7453be8..eb5f3c19dea 100644 --- a/modules/adnuntiusBidAdapter.js +++ b/modules/adnuntiusBidAdapter.js @@ -105,15 +105,16 @@ const storageTool = (function () { const getUsi = function (meta, ortb2, bidderRequest) { // Fetch user id from parameters. - const paramUsi = (bidderRequest.bids) ? bidderRequest.bids.find(bid => { - if (bid.params && bid.params.userId) return true - }).params.userId : false - let usi = (meta && meta.usi) ? meta.usi : false + for (let i = 0; i < (bidderRequest.bids || []).length; i++) { + const bid = bidderRequest.bids[i]; + if (bid.params && bid.params.userId) { + return bid.params.userId; + } + } if (ortb2 && ortb2.user && ortb2.user.id) { - usi = ortb2.user.id + return ortb2.user.id } - if (paramUsi) usi = paramUsi - return usi; + return (meta && meta.usi) ? meta.usi : false } const getSegmentsFromOrtb = function (ortb2) { diff --git a/test/spec/modules/adnuntiusBidAdapter_spec.js b/test/spec/modules/adnuntiusBidAdapter_spec.js index 20795b59e8c..71f0a6a3a6c 100644 --- a/test/spec/modules/adnuntiusBidAdapter_spec.js +++ b/test/spec/modules/adnuntiusBidAdapter_spec.js @@ -681,6 +681,26 @@ describe('adnuntiusBidAdapter', function() { expect(request[0]).to.have.property('url') expect(request[0].url).to.equal(`${ENDPOINT_URL_BASE}&userId=different_user_id`); }); + + it('should handle no user specified', function () { + config.setBidderConfig({ + bidders: ['adnuntius'], + }); + const req = [ + { + bidId: 'adn-000000000008b6bc', + bidder: 'adnuntius', + params: { + auId: '000000000008b6bc', + network: 'adnuntius' + } + } + ] + const request = config.runWithBidder('adnuntius', () => spec.buildRequests(req, { bids: req })); + expect(request.length).to.equal(1); + expect(request[0]).to.have.property('url') + expect(request[0].url).to.equal(ENDPOINT_URL); + }); }); describe('user privacy', function() {