From c302ebe21e6fc1f99248e4ed8423d757f823a7b6 Mon Sep 17 00:00:00 2001 From: Demetrio Girardi Date: Tue, 29 Jul 2025 06:48:36 -0700 Subject: [PATCH 1/2] programmaticXBidAdapter: fix tests --- test/spec/modules/programmaticXBidAdapter_spec.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/test/spec/modules/programmaticXBidAdapter_spec.js b/test/spec/modules/programmaticXBidAdapter_spec.js index 91d1900d177..2ca47a9bc94 100644 --- a/test/spec/modules/programmaticXBidAdapter_spec.js +++ b/test/spec/modules/programmaticXBidAdapter_spec.js @@ -19,6 +19,7 @@ import { tryParseJSON, getUniqueDealId, } from '../../../libraries/vidazooUtils/bidderUtils.js'; +import {getGlobal} from '../../../src/prebidGlobal.js'; export const TEST_ID_SYSTEMS = ['criteoId', 'id5id', 'netId', 'tdid', 'pubProvidedId', 'intentIqId', 'liveIntentId']; @@ -273,7 +274,7 @@ describe('programmaticXBidAdapter', function () { describe('build requests', function () { let sandbox; before(function () { - $$PREBID_GLOBAL$$.bidderSettings = { + getGlobal().bidderSettings = { programmaticX: { storageAllowed: true } @@ -435,7 +436,7 @@ describe('programmaticXBidAdapter', function () { }); after(function () { - $$PREBID_GLOBAL$$.bidderSettings = {}; + getGlobal().bidderSettings = {}; sandbox.restore(); }); }); @@ -623,14 +624,14 @@ describe('programmaticXBidAdapter', function () { describe('unique deal id', function () { before(function () { - $$PREBID_GLOBAL$$.bidderSettings = { + getGlobal().bidderSettings = { programmaticX: { storageAllowed: true } }; }); after(function () { - $$PREBID_GLOBAL$$.bidderSettings = {}; + getGlobal().bidderSettings = {}; }); const key = 'myKey'; let uniqueDealId; @@ -658,14 +659,14 @@ describe('programmaticXBidAdapter', function () { describe('storage utils', function () { before(function () { - $$PREBID_GLOBAL$$.bidderSettings = { + getGlobal().bidderSettings = { programmaticX: { storageAllowed: true } }; }); after(function () { - $$PREBID_GLOBAL$$.bidderSettings = {}; + getGlobal().bidderSettings = {}; }); it('should get value from storage with create param', function () { const now = Date.now(); From 6fbeb869a11b044f2e5fecddbbf8ba6a4ae4746f Mon Sep 17 00:00:00 2001 From: Patrick McCann Date: Tue, 29 Jul 2025 10:00:43 -0400 Subject: [PATCH 2/2] Update adplusAnalyticsAdapter_spec.js --- .../modules/adplusAnalyticsAdapter_spec.js | 330 +++++++++--------- 1 file changed, 165 insertions(+), 165 deletions(-) diff --git a/test/spec/modules/adplusAnalyticsAdapter_spec.js b/test/spec/modules/adplusAnalyticsAdapter_spec.js index 559404b7b38..589a9a589ac 100644 --- a/test/spec/modules/adplusAnalyticsAdapter_spec.js +++ b/test/spec/modules/adplusAnalyticsAdapter_spec.js @@ -8,169 +8,169 @@ import sinon from 'sinon'; let events = require('src/events'); describe('AdPlus analytics adapter', function () { - let sandbox, clock; - - beforeEach(function () { - sandbox = sinon.createSandbox(); - sandbox.spy(console, 'log'); - - clock = sandbox.useFakeTimers(); - sandbox.stub(events, 'getEvents').returns([]); - adapterManager.enableAnalytics({ provider: 'adplus' }); - }); - - afterEach(function () { - sandbox.restore(); - adplusAnalyticsAdapter.reset(); - }); - - const auctionId = 'test-auction-123'; - - const bidsReceived = [ - { - bidderCode: 'adplus', - auctionId, - adUnitCode: 'adunit-1', - cpm: 5, - currency: 'USD', - size: '300x250', - width: 300, - height: 250, - creativeId: 'crea-1', - timeToRespond: 120, - netRevenue: true, - dealId: null - }, - { - bidderCode: 'adplus', - auctionId, - adUnitCode: 'adunit-2', - cpm: 7, - currency: 'USD', - size: '728x90', - width: 728, - height: 90, - creativeId: 'crea-2', - timeToRespond: 110, - netRevenue: true, - dealId: 'deal123' - } - ]; - - const bidWon1 = { - auctionId, - adUnitCode: 'adunit-1', - bidderCode: 'adplus', - cpm: 5, - currency: 'USD', - size: '300x250', - width: 300, - height: 250, - creativeId: 'crea-1', - timeToRespond: 120, - netRevenue: true, - dealId: null - }; - - const bidWon2 = { - auctionId, - adUnitCode: 'adunit-2', - bidderCode: 'adplus', - cpm: 7, - currency: 'USD', - size: '728x90', - width: 728, - height: 90, - creativeId: 'crea-2', - timeToRespond: 110, - netRevenue: true, - dealId: 'deal123' - }; - - it('should store bids on AUCTION_END and not send immediately', function () { - events.emit(EVENTS.AUCTION_END, { - auctionId, - bidsReceived - }); - - expect(server.requests.length).to.equal(0); - - const storedData = adplusAnalyticsAdapter.auctionBids[auctionId]; - expect(storedData).to.exist; - expect(Object.keys(storedData)).to.have.length(2); - expect(storedData['adunit-1'][0]).to.include({ - auctionId, - adUnitCode: 'adunit-1', - bidder: 'adplus', - cpm: 5, - currency: 'USD' - }); - }); - - it('should batch BID_WON events and send after delay with retries', function (done) { - // First, send AUCTION_END to prepare data - events.emit(EVENTS.AUCTION_END, { auctionId, bidsReceived }); - - // Emit first BID_WON - should send immediately - events.emit(EVENTS.BID_WON, bidWon1); - - clock.tick(0); - expect(server.requests.length).to.equal(1); - - // Fail first request, triggers retry after 200ms - server.requests[0].respond(500, {}, 'Internal Server Error'); - clock.tick(200); - - expect(server.requests.length).to.equal(2); - - // Fail second (retry) request, triggers next retry - server.requests[1].respond(500, {}, 'Internal Server Error'); - clock.tick(200); - - expect(server.requests.length).to.equal(3); - - // Succeed on third retry - server.requests[2].respond(200, { 'Content-Type': 'application/json' }, JSON.stringify({ status: 'ok' })); - - // Now emit second BID_WON - queue is empty, should send immediately - events.emit(EVENTS.BID_WON, bidWon2); - - // Should wait 200ms after emit. - expect(server.requests.length).to.equal(3); - - // Sends the second BID_WON data after 200ms - clock.tick(200); - expect(server.requests.length).to.equal(4); - - // Succeed second BID_WON send - server.requests[3].respond(200, { 'Content-Type': 'application/json' }, JSON.stringify({ status: 'ok' })); - - // Validate payloads - const payload1 = JSON.parse(server.requests[0].requestBody); - const payload2 = JSON.parse(server.requests[3].requestBody); - - expect(payload1.winningBid).to.include({ - auctionId, - adUnitCode: 'adunit-1', - bidder: 'adplus', - cpm: 5, - }); - - expect(payload2.winningBid).to.include({ - auctionId, - adUnitCode: 'adunit-2', - bidder: 'adplus', - cpm: 7, - }); - - done(); - }); - - it('should skip BID_WON if no auction data available', function () { - // Emit BID_WON without AUCTION_END first - expect(() => events.emit(EVENTS.BID_WON, bidWon1)).to.not.throw(); - - // No ajax call since no auctionData - expect(server.requests.length).to.equal(0); - }); + let sandbox, clock; + + beforeEach(function () { + sandbox = sinon.createSandbox(); + sandbox.spy(console, 'log'); + + clock = sandbox.useFakeTimers(); + sandbox.stub(events, 'getEvents').returns([]); + adapterManager.enableAnalytics({ provider: 'adplus' }); + }); + + afterEach(function () { + sandbox.restore(); + adplusAnalyticsAdapter.reset(); + }); + + const auctionId = 'test-auction-123'; + + const bidsReceived = [ + { + bidderCode: 'adplus', + auctionId, + adUnitCode: 'adunit-1', + cpm: 5, + currency: 'USD', + size: '300x250', + width: 300, + height: 250, + creativeId: 'crea-1', + timeToRespond: 120, + netRevenue: true, + dealId: null + }, + { + bidderCode: 'adplus', + auctionId, + adUnitCode: 'adunit-2', + cpm: 7, + currency: 'USD', + size: '728x90', + width: 728, + height: 90, + creativeId: 'crea-2', + timeToRespond: 110, + netRevenue: true, + dealId: 'deal123' + } + ]; + + const bidWon1 = { + auctionId, + adUnitCode: 'adunit-1', + bidderCode: 'adplus', + cpm: 5, + currency: 'USD', + size: '300x250', + width: 300, + height: 250, + creativeId: 'crea-1', + timeToRespond: 120, + netRevenue: true, + dealId: null + }; + + const bidWon2 = { + auctionId, + adUnitCode: 'adunit-2', + bidderCode: 'adplus', + cpm: 7, + currency: 'USD', + size: '728x90', + width: 728, + height: 90, + creativeId: 'crea-2', + timeToRespond: 110, + netRevenue: true, + dealId: 'deal123' + }; + + it('should store bids on AUCTION_END and not send immediately', function () { + events.emit(EVENTS.AUCTION_END, { + auctionId, + bidsReceived + }); + + expect(server.requests.length).to.equal(0); + + const storedData = adplusAnalyticsAdapter.auctionBids[auctionId]; + expect(storedData).to.exist; + expect(Object.keys(storedData)).to.have.length(2); + expect(storedData['adunit-1'][0]).to.include({ + auctionId, + adUnitCode: 'adunit-1', + bidder: 'adplus', + cpm: 5, + currency: 'USD' + }); + }); + + it('should batch BID_WON events and send after delay with retries', function (done) { + // First, send AUCTION_END to prepare data + events.emit(EVENTS.AUCTION_END, { auctionId, bidsReceived }); + + // Emit first BID_WON - should send immediately + events.emit(EVENTS.BID_WON, bidWon1); + + clock.tick(0); + expect(server.requests.length).to.equal(1); + + // Fail first request, triggers retry after 200ms + server.requests[0].respond(500, {}, 'Internal Server Error'); + clock.tick(200); + + expect(server.requests.length).to.equal(2); + + // Fail second (retry) request, triggers next retry + server.requests[1].respond(500, {}, 'Internal Server Error'); + clock.tick(200); + + expect(server.requests.length).to.equal(3); + + // Succeed on third retry + server.requests[2].respond(200, { 'Content-Type': 'application/json' }, JSON.stringify({ status: 'ok' })); + + // Now emit second BID_WON - queue is empty, should send immediately + events.emit(EVENTS.BID_WON, bidWon2); + + // Should wait 200ms after emit. + expect(server.requests.length).to.equal(3); + + // Sends the second BID_WON data after 200ms + clock.tick(200); + expect(server.requests.length).to.equal(4); + + // Succeed second BID_WON send + server.requests[3].respond(200, { 'Content-Type': 'application/json' }, JSON.stringify({ status: 'ok' })); + + // Validate payloads + const payload1 = JSON.parse(server.requests[0].requestBody); + const payload2 = JSON.parse(server.requests[3].requestBody); + + expect(payload1.winningBid).to.include({ + auctionId, + adUnitCode: 'adunit-1', + bidder: 'adplus', + cpm: 5, + }); + + expect(payload2.winningBid).to.include({ + auctionId, + adUnitCode: 'adunit-2', + bidder: 'adplus', + cpm: 7, + }); + + done(); + }); + + it('should skip BID_WON if no auction data available', function () { + // Emit BID_WON without AUCTION_END first + expect(() => events.emit(EVENTS.BID_WON, bidWon1)).to.not.throw(); + + // No ajax call since no auctionData + expect(server.requests.length).to.equal(0); + }); });