Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kargo Bid Adapter: replaces triggerPixel with fetch #12387

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions modules/kargoBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { _each, isEmpty, buildUrl, deepAccess, pick, triggerPixel, logError } from '../src/utils.js';
import { _each, isEmpty, buildUrl, deepAccess, pick, logError } 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 @@ -452,21 +452,20 @@ function getRequestCount() {
}

function sendTimeoutData(auctionId, auctionTimeout) {
let params = {
aid: auctionId,
ato: auctionTimeout
};

try {
let timeoutRequestUrl = buildUrl({
protocol: 'https',
hostname: BIDDER.HOST,
pathname: BIDDER.TIMEOUT_ENDPOINT,
search: params
});
const params = { aid: auctionId, ato: auctionTimeout };
const timeoutRequestUrl = buildUrl({
protocol: 'https',
hostname: BIDDER.HOST,
pathname: BIDDER.TIMEOUT_ENDPOINT,
search: params,
});

triggerPixel(timeoutRequestUrl);
} catch (e) {}
fetch(timeoutRequestUrl, {
method: 'GET',
keepalive: true,
}).catch((e) => {
logError('Kargo: sendTimeoutData/fetch threw an error: ', e);
});
}

function getImpression(bid) {
Expand Down
46 changes: 32 additions & 14 deletions test/spec/modules/kargoBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2030,31 +2030,49 @@ describe('kargo adapter tests', function() {
});
});

describe('onTimeout', function() {
describe('onTimeout', function () {
let fetchStub;

beforeEach(function () {
sinon.stub(utils, 'triggerPixel');
fetchStub = sinon.stub(global, 'fetch').resolves(); // Stub fetch globally
});

afterEach(function () {
utils.triggerPixel.restore();
fetchStub.restore(); // Restore the original fetch function
});

it('does not call triggerPixel if timeout data is not provided', function() {
it('does not call fetch if timeout data is not provided', function () {
spec.onTimeout(null);
expect(utils.triggerPixel.callCount).to.equal(0);
expect(fetchStub.callCount).to.equal(0);
});

it('calls triggerPixel if any timeout data is provided', function() {
it('calls fetch with the correct URLs if timeout data is provided', function () {
spec.onTimeout([
{auctionId: 'test-auction-id', timeout: 400},
{auctionId: 'test-auction-id-2', timeout: 100},
{auctionId: 'test-auction-id-3', timeout: 450},
{auctionId: 'test-auction-id-4', timeout: 500},
{ auctionId: 'test-auction-id', timeout: 400 },
{ auctionId: 'test-auction-id-2', timeout: 100 },
{ auctionId: 'test-auction-id-3', timeout: 450 },
{ auctionId: 'test-auction-id-4', timeout: 500 },
]);
expect(utils.triggerPixel.calledWith('https://krk2.kargo.com/api/v1/event/timeout?aid=test-auction-id&ato=400')).to.be.true;
expect(utils.triggerPixel.calledWith('https://krk2.kargo.com/api/v1/event/timeout?aid=test-auction-id-2&ato=100')).to.be.true;
expect(utils.triggerPixel.calledWith('https://krk2.kargo.com/api/v1/event/timeout?aid=test-auction-id-3&ato=450')).to.be.true;
expect(utils.triggerPixel.calledWith('https://krk2.kargo.com/api/v1/event/timeout?aid=test-auction-id-4&ato=500')).to.be.true;

expect(fetchStub.calledWith(
'https://krk2.kargo.com/api/v1/event/timeout?aid=test-auction-id&ato=400',
{ method: 'GET', keepalive: true }
)).to.be.true;

expect(fetchStub.calledWith(
'https://krk2.kargo.com/api/v1/event/timeout?aid=test-auction-id-2&ato=100',
{ method: 'GET', keepalive: true }
)).to.be.true;

expect(fetchStub.calledWith(
'https://krk2.kargo.com/api/v1/event/timeout?aid=test-auction-id-3&ato=450',
{ method: 'GET', keepalive: true }
)).to.be.true;

expect(fetchStub.calledWith(
'https://krk2.kargo.com/api/v1/event/timeout?aid=test-auction-id-4&ato=500',
{ method: 'GET', keepalive: true }
)).to.be.true;
});
});
});
Loading