Skip to content

Commit

Permalink
Adriver Bid and Id Modules: buyerid bug fix (prebid#8768)
Browse files Browse the repository at this point in the history
* initial commit

* adriver id submodule add

* add id system tests, fix adriver bid adapter tests

* adriver: fix buyerid

* remarks fixing

* removal of excess

* delete custom parameter

* bug fixes
  • Loading branch information
m-oranskaya authored and JacobKlein26 committed Feb 8, 2023
1 parent b2f846c commit 823c7a6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 34 deletions.
17 changes: 5 additions & 12 deletions modules/adriverBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ADRIVER BID ADAPTER for Prebid 1.13
import { logInfo, getWindowLocation, getBidIdParameter, _each } from '../src/utils.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { getStorageManager } from '../src/storageManager.js';

const BIDDER_CODE = 'adriver';
Expand All @@ -22,8 +22,6 @@ export const spec = {
},

buildRequests: function (validBidRequests, bidderRequest) {
logInfo('validBidRequests', validBidRequests);

let win = getWindowLocation();
let customID = Math.round(Math.random() * 999999999) + '-' + Math.round(new Date() / 1000) + '-1-46-';
let siteId = getBidIdParameter('siteid', validBidRequests[0].params) + '';
Expand Down Expand Up @@ -99,22 +97,17 @@ export const spec = {
});
});

let userid = validBidRequests[0].userId;
let adrcidCookie = storage.getDataFromLocalStorage('adrcid') || validBidRequests[0].userId.adrcid;

let adrcidCookie = storage.getDataFromLocalStorage('adrcid') || validBidRequests[0].userId?.adrcid;
if (adrcidCookie) {
payload.adrcid = adrcidCookie;
payload.id5 = userid.id5id;
payload.sharedid = userid.pubcid;
payload.unifiedid = userid.tdid;
payload.user.buyerid = adrcidCookie;
}
const payloadString = JSON.stringify(payload);

return {
method: 'POST',
url: ADRIVER_BID_URL,
data: payloadString,
};
data: payloadString
}
},

interpretResponse: function (serverResponse, bidRequest) {
Expand Down
3 changes: 2 additions & 1 deletion modules/adriverIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ export const adriverIdSubmodule = {
callback();
}
};
ajax(url, callbacks, undefined, {method: 'GET'});
let newUrl = url + '&cid=' + (storage.getDataFromLocalStorage('adrcid') || storage.getCookie('adrcid'));
ajax(newUrl, callbacks, undefined, {method: 'GET'});
}
};
return {callback: resp};
Expand Down
19 changes: 6 additions & 13 deletions test/spec/modules/adriverBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,25 +297,18 @@ describe('adriverAdapter', function () {
{ adrcid: undefined }
]
cookieValues.forEach(cookieValue => describe('test cookie exist or not behavior', function () {
let expectedValues = {
adrcid: cookieValue.adrcid,
at: '',
cur: '',
tmax: '',
site: '',
id: '',
user: '',
device: '',
imp: ''
}
let expectedValues = [
'buyerid',
'ext'
]

it('check adrcid if it exists', function () {
bidRequests[0].userId.adrcid = cookieValue.adrcid;
const payload = JSON.parse(spec.buildRequests(bidRequests).data);
if (cookieValue.adrcid) {
expect(Object.keys(payload)).to.have.members(Object.keys(expectedValues));
expect(Object.keys(payload.user)).to.have.members(expectedValues);
} else {
expect(payload.adrcid).to.equal(undefined);
expect(payload.user.buyerid).to.equal(0);
}
});
}));
Expand Down
11 changes: 3 additions & 8 deletions test/spec/modules/adriverIdSystem_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ describe('AdriverIdSystem', function () {
expect(request.url).to.include('https://ad.adriver.ru/cgi-bin/json.cgi');
request.respond(503, null, 'Unavailable');
expect(logErrorStub.calledOnce).to.be.true;
expect(callbackSpy.calledOnce).to.be.true;
});

it('test call user sync url with the right params', function() {
Expand Down Expand Up @@ -67,16 +66,12 @@ describe('AdriverIdSystem', function () {
let request = server.requests[0];
request.respond(200, { 'Content-Type': 'application/json' }, JSON.stringify({ adrcid: response.adrcid }));

let expectedExpiration = new Date();
expectedExpiration.setTime(expectedExpiration.getTime() + 86400 * 1825 * 1000);
let now = new Date();
now.setTime(now.getTime() + 86400 * 1825 * 1000);
const minimalDate = new Date(0).toString();

function dateStringFor(date, maxDeltaMs = 2000) {
return sinon.match((val) => Math.abs(date.getTime() - new Date(val).getTime()) <= maxDeltaMs)
}

if (response.adrcid) {
expect(setCookieStub.calledWith('adrcid', response.adrcid, dateStringFor(expectedExpiration))).to.be.true;
expect(setCookieStub.calledWith('adrcid', response.adrcid, now.toUTCString())).to.be.true;
expect(setLocalStorageStub.calledWith('adrcid', response.adrcid)).to.be.true;
} else {
expect(setCookieStub.calledWith('adrcid', '', minimalDate)).to.be.false;
Expand Down

0 comments on commit 823c7a6

Please sign in to comment.