diff --git a/modules/adnuntiusBidAdapter.js b/modules/adnuntiusBidAdapter.js index 02dd7453be81..eb5f3c19dea1 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 20795b59e8cd..71f0a6a3a6c6 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() {