Skip to content

Commit

Permalink
IX Bid Adapter: fix request options field [PB-3461] (#12637)
Browse files Browse the repository at this point in the history
* fix: fix requests options field [PB-3461]

* feat: set credentials options field explicitly [PB-3461]

* fix: fix lint issue [PB-3461]

* chore: add fetch request header test [PB-3461]

* chore: add fetch request header test [PB-3461]

* chore: add fetch request header test [PB-3461]

* chore: update fetch test [PB-3461]

* chore: update fetch test [PB-3461]

* chore: change fetch stub approach [PB-3461]

---------

Co-authored-by: shahin.rahbariasl <[email protected]>
  • Loading branch information
shahinrahbariasl and shahin-rahbariasl authored Jan 9, 2025
1 parent 44ce97e commit fab7207
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
3 changes: 2 additions & 1 deletion modules/ixBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -751,8 +751,9 @@ function buildRequest(validBidRequests, bidderRequest, impressions, version) {
method: 'POST',
url: exchangeUrl,
data: deepClone(r),
option: {
options: {
contentType: 'text/plain',
withCredentials: true
},
validBidRequests
});
Expand Down
58 changes: 57 additions & 1 deletion test/spec/modules/ixBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { expect } from 'chai';
import { newBidder } from 'src/adapters/bidderFactory.js';
import { spec, storage, FEATURE_TOGGLES, LOCAL_STORAGE_FEATURE_TOGGLES_KEY, REQUESTED_FEATURE_TOGGLES, combineImps, bidToVideoImp, bidToNativeImp, deduplicateImpExtFields, removeSiteIDs, addDeviceInfo } from '../../../modules/ixBidAdapter.js';
import { deepAccess, deepClone } from '../../../src/utils.js';
import * as ajaxLib from 'src/ajax.js';

describe('IndexexchangeAdapter', function () {
const IX_SECURE_ENDPOINT = 'https://htlb.casalemedia.com/openrtb/pbjs';
Expand Down Expand Up @@ -2088,7 +2089,11 @@ describe('IndexexchangeAdapter', function () {
it('request should be made to IX endpoint with POST method and siteId in query param', function () {
expect(requestMethod).to.equal('POST');
expect(requestUrl).to.equal(IX_SECURE_ENDPOINT + '?s=' + DEFAULT_BANNER_VALID_BID[0].params.siteId);
expect(request.option.contentType).to.equal('text/plain')
});

it('request made to IX endpoint with POST method should have correct options fields set', function () {
expect(request.options.contentType).to.equal('text/plain')
expect(request.options.withCredentials).to.equal(true)
});

it('auction type should be set correctly', function () {
Expand Down Expand Up @@ -5003,6 +5008,7 @@ describe('IndexexchangeAdapter', function () {
expect(result['b8c6b5d5-76a1-4a90-b635-0c7eae1bfaa7'].ixImps.length).to.equal(1);
});
});

describe('apply floors test', function () {
it('video test', function() {
const bid = utils.deepClone(DEFAULT_VIDEO_VALID_BID[0]);
Expand Down Expand Up @@ -5367,6 +5373,7 @@ describe('IndexexchangeAdapter', function () {
expect(removeSiteIDs(request)).to.deep.equal(expected);
});
});

describe('addDeviceInfo', () => {
it('should add device to request when device already exists', () => {
let r = {
Expand All @@ -5385,4 +5392,53 @@ describe('IndexexchangeAdapter', function () {
expect(r.device.h).to.exist;
});
});

describe('fetch requests', function () {
let ajaxStub;

beforeEach(function () {
ajaxStub = sinon.stub(ajaxLib, 'ajaxBuilder').callsFake(() => {
return sinon.spy(function (url, callback, data, options) {
callback.success('OK');
});
});
});

afterEach(function () {
ajaxStub.restore();
});

it('should send the correct headers in the actual fetch call', function (done) {
const requests = spec.buildRequests(DEFAULT_BANNER_VALID_BID, DEFAULT_OPTION);
const request = requests[0];
const ajax = ajaxLib.ajaxBuilder();

ajax(
request.url,
{
success: () => {
try {
sinon.assert.calledOnce(ajaxStub);
const ajaxCall = ajaxStub.returnValues[0];
sinon.assert.calledOnce(ajaxCall);
const [calledUrl, callback, calledData, calledOptions] = ajaxCall.getCall(0).args;

expect(calledUrl).to.equal(request.url);
expect(calledData).to.equal(request.data);

expect(calledOptions.contentType).to.equal('text/plain');
expect(calledOptions.withCredentials).to.be.true;

done();
} catch (err) {
done(err);
}
},
error: (err) => done(err || new Error('Ajax request failed')),
},
request.data,
request.options
);
});
});
});

0 comments on commit fab7207

Please sign in to comment.