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

Adriver Bid and Id Modules: buyerid bug fix #8768

Merged
merged 9 commits into from
Aug 18, 2022
Merged
Show file tree
Hide file tree
Changes from 8 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
15 changes: 4 additions & 11 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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

During my tests, I saw the fallback throw an error during the first auction, because the userId is not defined.

Please just update to something like : || 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