From 08b1fd684a906400b81209aea7ecf2f6a84e1dd5 Mon Sep 17 00:00:00 2001 From: Jeremy Sadwith Date: Mon, 23 May 2022 14:08:58 -0400 Subject: [PATCH] Kargo Bid Adapter: onTimeout Support --- modules/kargoBidAdapter.js | 23 ++++++++++++++++++++++- test/spec/modules/kargoBidAdapter_spec.js | 23 +++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/modules/kargoBidAdapter.js b/modules/kargoBidAdapter.js index 1842231721b..abeb706151a 100644 --- a/modules/kargoBidAdapter.js +++ b/modules/kargoBidAdapter.js @@ -1,4 +1,4 @@ -import { _each } from '../src/utils.js'; +import { _each, buildUrl, triggerPixel } from '../src/utils.js'; import { config } from '../src/config.js'; import { registerBidder } from '../src/adapters/bidderFactory.js'; import { getStorageManager } from '../src/storageManager.js'; @@ -133,6 +133,27 @@ export const spec = { return syncs; }, supportedMediaTypes: SUPPORTED_MEDIA_TYPES, + onTimeout: function(timeoutData) { + if (timeoutData == null) { + return; + } + + timeoutData.forEach((bid) => { + let params = { + aid: bid.auctionId, + ato: bid.timeout, + }; + + let timeoutRequestUrl = buildUrl({ + protocol: 'https', + hostname: 'krk.kargo.com', + pathname: '/api/v1/event/timeout', + search: params + }); + + triggerPixel(timeoutRequestUrl); + }); + }, // PRIVATE _readCookie(name) { diff --git a/test/spec/modules/kargoBidAdapter_spec.js b/test/spec/modules/kargoBidAdapter_spec.js index 1515ed0820e..11ea88bdffa 100644 --- a/test/spec/modules/kargoBidAdapter_spec.js +++ b/test/spec/modules/kargoBidAdapter_spec.js @@ -1,6 +1,7 @@ import {expect, assert} from 'chai'; import {spec} from 'modules/kargoBidAdapter.js'; import {config} from 'src/config.js'; +const utils = require('src/utils'); describe('kargo adapter tests', function () { var sandbox, clock, frozenNow = new Date(); @@ -683,4 +684,26 @@ describe('kargo adapter tests', function () { safelyRun(() => expect(getUserSyncsWhenForbidden()).to.be.an('array').that.is.empty); }); }); + + describe('timeout pixel trigger', function () { + let triggerPixelStub; + + beforeEach(function () { + triggerPixelStub = sinon.stub(utils, 'triggerPixel'); + }); + + afterEach(function () { + utils.triggerPixel.restore(); + }); + + it('should call triggerPixel utils function when timed out is filled', function () { + spec.onTimeout(); + expect(triggerPixelStub.getCall(0)).to.be.null; + spec.onTimeout([{ auctionId: '1234', timeout: 2000 }]); + expect(triggerPixelStub.getCall(0)).to.not.be.null; + expect(triggerPixelStub.getCall(0).args[0]).to.exist.and.to.include('https://krk.kargo.com/api/v1/event/timeout'); + expect(triggerPixelStub.getCall(0).args[0]).to.include('aid=1234'); + expect(triggerPixelStub.getCall(0).args[0]).to.include('ato=2000'); + }); + }); });