Skip to content

Commit

Permalink
Kargo Bid Adapter: onTimeout Support (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsadwith authored May 23, 2022
1 parent 2d79302 commit 0a03e35
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
23 changes: 22 additions & 1 deletion modules/kargoBidAdapter.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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) {
Expand Down
23 changes: 23 additions & 0 deletions test/spec/modules/kargoBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -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();
Expand Down Expand Up @@ -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');
});
});
});

0 comments on commit 0a03e35

Please sign in to comment.