From ec9303bba2be7208c4da1eb4a297aa2a2242d11c Mon Sep 17 00:00:00 2001 From: "shahin.rahbariasl" Date: Mon, 4 Nov 2024 09:27:31 -0500 Subject: [PATCH 1/9] fix: fix requests options field [PB-3461] --- modules/ixBidAdapter.js | 2 +- test/spec/modules/ixBidAdapter_spec.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/ixBidAdapter.js b/modules/ixBidAdapter.js index 0ec60b51ca2..39d375b3a9d 100644 --- a/modules/ixBidAdapter.js +++ b/modules/ixBidAdapter.js @@ -751,7 +751,7 @@ function buildRequest(validBidRequests, bidderRequest, impressions, version) { method: 'POST', url: exchangeUrl, data: deepClone(r), - option: { + options: { contentType: 'text/plain', }, validBidRequests diff --git a/test/spec/modules/ixBidAdapter_spec.js b/test/spec/modules/ixBidAdapter_spec.js index e0162617be3..98bd006fc37 100644 --- a/test/spec/modules/ixBidAdapter_spec.js +++ b/test/spec/modules/ixBidAdapter_spec.js @@ -2088,7 +2088,7 @@ 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') + expect(request.options.contentType).to.equal('text/plain') }); it('auction type should be set correctly', function () { From 7c59ad6518693790b162a22395b91599cdefcd60 Mon Sep 17 00:00:00 2001 From: "shahin.rahbariasl" Date: Mon, 6 Jan 2025 18:18:25 -0500 Subject: [PATCH 2/9] feat: set credentials options field explicitly [PB-3461] --- modules/ixBidAdapter.js | 1 + test/spec/modules/ixBidAdapter_spec.js | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/modules/ixBidAdapter.js b/modules/ixBidAdapter.js index 39d375b3a9d..e2a712e0afc 100644 --- a/modules/ixBidAdapter.js +++ b/modules/ixBidAdapter.js @@ -753,6 +753,7 @@ function buildRequest(validBidRequests, bidderRequest, impressions, version) { data: deepClone(r), options: { contentType: 'text/plain', + withCredentials: true }, validBidRequests }); diff --git a/test/spec/modules/ixBidAdapter_spec.js b/test/spec/modules/ixBidAdapter_spec.js index 98bd006fc37..893ddcee6d7 100644 --- a/test/spec/modules/ixBidAdapter_spec.js +++ b/test/spec/modules/ixBidAdapter_spec.js @@ -2088,7 +2088,12 @@ 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); + + }); + + 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 () { From 85da1b99b7861a96286b094ba5735ccd09aba3aa Mon Sep 17 00:00:00 2001 From: "shahin.rahbariasl" Date: Mon, 6 Jan 2025 18:22:11 -0500 Subject: [PATCH 3/9] fix: fix lint issue [PB-3461] --- test/spec/modules/ixBidAdapter_spec.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/spec/modules/ixBidAdapter_spec.js b/test/spec/modules/ixBidAdapter_spec.js index 893ddcee6d7..51b54f7d4ce 100644 --- a/test/spec/modules/ixBidAdapter_spec.js +++ b/test/spec/modules/ixBidAdapter_spec.js @@ -2088,7 +2088,6 @@ 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); - }); it('request made to IX endpoint with POST method should have correct options fields set', function () { From 1cf445381c04ddf37ad9ffd0a7e3b83143f84d2b Mon Sep 17 00:00:00 2001 From: "shahin.rahbariasl" Date: Tue, 7 Jan 2025 14:47:32 -0500 Subject: [PATCH 4/9] chore: add fetch request header test [PB-3461] --- test/spec/modules/ixBidAdapter_spec.js | 42 ++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/test/spec/modules/ixBidAdapter_spec.js b/test/spec/modules/ixBidAdapter_spec.js index 51b54f7d4ce..73edcc94922 100644 --- a/test/spec/modules/ixBidAdapter_spec.js +++ b/test/spec/modules/ixBidAdapter_spec.js @@ -5007,6 +5007,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]); @@ -5371,6 +5372,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 = { @@ -5389,4 +5391,44 @@ describe('IndexexchangeAdapter', function () { expect(r.device.h).to.exist; }); }); + + describe('fetch requests', function () { + let fetchStub; + + beforeEach(() => { + fetchStub = sinon.stub(window, 'fetch'); + }); + + afterEach(() => { + fetchStub.restore(); + }); + + it('should send the correct headers in the actual fetch call', async function () { + const requests = spec.buildRequests(DEFAULT_BANNER_VALID_BID, DEFAULT_OPTION); + + requests.forEach((request) => { + fetch(request.url, { + method: request.method, + headers: { + 'Content-Type': request.options.contentType, + }, + credentials: request.options.withCredentials ? 'include' : 'omit', + body: JSON.stringify(request.data), + }); + }); + + sinon.assert.called(fetchStub); + + const fetchArgs = fetchStub.getCall(0).args; + const fetchUrl = fetchArgs[0]; + const fetchOptions = fetchArgs[1]; + + expect(fetchUrl).to.equal(requests[0].url); + expect(fetchOptions.method).to.equal('POST'); + expect(fetchOptions.credentials).to.equal('include'); + expect(fetchOptions.headers['Content-Type']).to.equal('text/plain'); + }); + }); + }); + From 2de5d574995845df8b784cde97484d7a0e6b0372 Mon Sep 17 00:00:00 2001 From: "shahin.rahbariasl" Date: Tue, 7 Jan 2025 14:50:22 -0500 Subject: [PATCH 5/9] chore: add fetch request header test [PB-3461] --- test/spec/modules/ixBidAdapter_spec.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/spec/modules/ixBidAdapter_spec.js b/test/spec/modules/ixBidAdapter_spec.js index 73edcc94922..9ef98cb2a8c 100644 --- a/test/spec/modules/ixBidAdapter_spec.js +++ b/test/spec/modules/ixBidAdapter_spec.js @@ -5429,6 +5429,5 @@ describe('IndexexchangeAdapter', function () { expect(fetchOptions.headers['Content-Type']).to.equal('text/plain'); }); }); - }); From f67219407ce65814c52caaaaa0488a043e1af76f Mon Sep 17 00:00:00 2001 From: "shahin.rahbariasl" Date: Tue, 7 Jan 2025 14:53:49 -0500 Subject: [PATCH 6/9] chore: add fetch request header test [PB-3461] --- test/spec/modules/ixBidAdapter_spec.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/spec/modules/ixBidAdapter_spec.js b/test/spec/modules/ixBidAdapter_spec.js index 9ef98cb2a8c..3ceb987f7d5 100644 --- a/test/spec/modules/ixBidAdapter_spec.js +++ b/test/spec/modules/ixBidAdapter_spec.js @@ -5430,4 +5430,3 @@ describe('IndexexchangeAdapter', function () { }); }); }); - From 7bb5b1e13b2eceb408203384866927341f36a27d Mon Sep 17 00:00:00 2001 From: "shahin.rahbariasl" Date: Wed, 8 Jan 2025 08:57:43 -0500 Subject: [PATCH 7/9] chore: update fetch test [PB-3461] --- test/spec/modules/ixBidAdapter_spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/spec/modules/ixBidAdapter_spec.js b/test/spec/modules/ixBidAdapter_spec.js index 3ceb987f7d5..9d963568e82 100644 --- a/test/spec/modules/ixBidAdapter_spec.js +++ b/test/spec/modules/ixBidAdapter_spec.js @@ -5412,7 +5412,7 @@ describe('IndexexchangeAdapter', function () { headers: { 'Content-Type': request.options.contentType, }, - credentials: request.options.withCredentials ? 'include' : 'omit', + credentials: request.options.withCredentials, body: JSON.stringify(request.data), }); }); @@ -5425,7 +5425,7 @@ describe('IndexexchangeAdapter', function () { expect(fetchUrl).to.equal(requests[0].url); expect(fetchOptions.method).to.equal('POST'); - expect(fetchOptions.credentials).to.equal('include'); + expect(fetchOptions.credentials).to.equal(true); expect(fetchOptions.headers['Content-Type']).to.equal('text/plain'); }); }); From 43363add1b94b6e985d3d34475db1410141a511e Mon Sep 17 00:00:00 2001 From: "shahin.rahbariasl" Date: Wed, 8 Jan 2025 09:09:40 -0500 Subject: [PATCH 8/9] chore: update fetch test [PB-3461] --- test/spec/modules/ixBidAdapter_spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/spec/modules/ixBidAdapter_spec.js b/test/spec/modules/ixBidAdapter_spec.js index 9d963568e82..3ceb987f7d5 100644 --- a/test/spec/modules/ixBidAdapter_spec.js +++ b/test/spec/modules/ixBidAdapter_spec.js @@ -5412,7 +5412,7 @@ describe('IndexexchangeAdapter', function () { headers: { 'Content-Type': request.options.contentType, }, - credentials: request.options.withCredentials, + credentials: request.options.withCredentials ? 'include' : 'omit', body: JSON.stringify(request.data), }); }); @@ -5425,7 +5425,7 @@ describe('IndexexchangeAdapter', function () { expect(fetchUrl).to.equal(requests[0].url); expect(fetchOptions.method).to.equal('POST'); - expect(fetchOptions.credentials).to.equal(true); + expect(fetchOptions.credentials).to.equal('include'); expect(fetchOptions.headers['Content-Type']).to.equal('text/plain'); }); }); From 28a78efb94f57bc8373c3280e9bbb6f8b01f8e72 Mon Sep 17 00:00:00 2001 From: "shahin.rahbariasl" Date: Thu, 9 Jan 2025 16:14:19 -0500 Subject: [PATCH 9/9] chore: change fetch stub approach [PB-3461] --- test/spec/modules/ixBidAdapter_spec.js | 64 +++++++++++++++----------- 1 file changed, 38 insertions(+), 26 deletions(-) diff --git a/test/spec/modules/ixBidAdapter_spec.js b/test/spec/modules/ixBidAdapter_spec.js index 3ceb987f7d5..5f75e224b50 100644 --- a/test/spec/modules/ixBidAdapter_spec.js +++ b/test/spec/modules/ixBidAdapter_spec.js @@ -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'; @@ -5393,40 +5394,51 @@ describe('IndexexchangeAdapter', function () { }); describe('fetch requests', function () { - let fetchStub; + let ajaxStub; - beforeEach(() => { - fetchStub = sinon.stub(window, 'fetch'); + beforeEach(function () { + ajaxStub = sinon.stub(ajaxLib, 'ajaxBuilder').callsFake(() => { + return sinon.spy(function (url, callback, data, options) { + callback.success('OK'); + }); + }); }); - afterEach(() => { - fetchStub.restore(); + afterEach(function () { + ajaxStub.restore(); }); - it('should send the correct headers in the actual fetch call', async function () { + 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(); - requests.forEach((request) => { - fetch(request.url, { - method: request.method, - headers: { - 'Content-Type': request.options.contentType, + 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); + } }, - credentials: request.options.withCredentials ? 'include' : 'omit', - body: JSON.stringify(request.data), - }); - }); - - sinon.assert.called(fetchStub); - - const fetchArgs = fetchStub.getCall(0).args; - const fetchUrl = fetchArgs[0]; - const fetchOptions = fetchArgs[1]; - - expect(fetchUrl).to.equal(requests[0].url); - expect(fetchOptions.method).to.equal('POST'); - expect(fetchOptions.credentials).to.equal('include'); - expect(fetchOptions.headers['Content-Type']).to.equal('text/plain'); + error: (err) => done(err || new Error('Ajax request failed')), + }, + request.data, + request.options + ); }); }); });