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

Outbrain adapter: Read OB user token from local storage #10382

Merged
merged 6 commits into from
Oct 3, 2023
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
9 changes: 9 additions & 0 deletions modules/outbrainBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import {registerBidder} from '../src/adapters/bidderFactory.js';
import {BANNER, NATIVE, VIDEO} from '../src/mediaTypes.js';
import { getStorageManager } from '../src/storageManager.js';
import {OUTSTREAM} from '../src/video.js';
import {_map, deepAccess, deepSetValue, isArray, logWarn, replaceAuctionPrice} from '../src/utils.js';
import {ajax} from '../src/ajax.js';
Expand All @@ -23,6 +24,9 @@ const NATIVE_PARAMS = {
cta: { id: 1, type: 12, name: 'data' }
};
const OUTSTREAM_RENDERER_URL = 'https://acdn.adnxs.com/video/outstream/ANOutstreamVideo.js';
const OB_USER_TOKEN_KEY = 'OB-USER-TOKEN';

export const storage = getStorageManager({bidderCode: BIDDER_CODE});

export const spec = {
code: BIDDER_CODE,
Expand Down Expand Up @@ -130,6 +134,11 @@ export const spec = {
request.test = 1;
}

const obUserToken = storage.getDataFromLocalStorage(OB_USER_TOKEN_KEY)
if (obUserToken) {
deepSetValue(request, 'user.ext.obusertoken', obUserToken)
}

if (deepAccess(bidderRequest, 'gdprConsent.gdprApplies')) {
deepSetValue(request, 'user.ext.consent', bidderRequest.gdprConsent.consentString)
deepSetValue(request, 'regs.ext.gdpr', bidderRequest.gdprConsent.gdprApplies & 1)
Expand Down
25 changes: 22 additions & 3 deletions test/spec/modules/outbrainBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from 'chai';
import { spec } from 'modules/outbrainBidAdapter.js';
import { spec, storage } from 'modules/outbrainBidAdapter.js';
import { config } from 'src/config.js';
import { server } from 'test/mocks/xhr';

Expand Down Expand Up @@ -213,15 +213,18 @@ describe('Outbrain Adapter', function () {
})

describe('buildRequests', function () {
let getDataFromLocalStorageStub;

before(() => {
getDataFromLocalStorageStub = sinon.stub(storage, 'getDataFromLocalStorage')
config.setConfig({
outbrain: {
bidderUrl: 'https://bidder-url.com',
}
}
)
})
})
after(() => {
getDataFromLocalStorageStub.restore()
config.resetConfig()
})

Expand Down Expand Up @@ -522,6 +525,22 @@ describe('Outbrain Adapter', function () {
]);
});

it('should pass OB user token', function () {
getDataFromLocalStorageStub.returns('12345');

let bidRequest = {
bidId: 'bidId',
params: {},
...commonBidRequest,
};

let res = spec.buildRequests([bidRequest], commonBidderRequest);
const resData = JSON.parse(res.data)
expect(resData.user.ext.obusertoken).to.equal('12345')
expect(getDataFromLocalStorageStub.called).to.be.true;
sinon.assert.calledWith(getDataFromLocalStorageStub, 'OB-USER-TOKEN');
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry to be a stickler on this but could you please do the stubbing and restoring in the before and after hooks?

This helps us not hurt downstream tests if for some reason your test fails in the middle of execution.

I know other adapters have it, but trying to set a better standard:

IX has a good example of this: https://github.com/prebid/Prebid.js/blob/master/test/spec/modules/ixBidAdapter_spec.js#L3814-L3833

Or you could use a sandbox if you were stubbing more things, but prob not needed.

Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hey, thanks for the suggestion! I don't want to stub return of the method before each test because I don't want to fix other tests (the response should stay the same if we don't read anything from local storage). So I hope this is ok
9fd5d42


it('should pass bidfloor', function () {
const bidRequest = {
...commonBidRequest,
Expand Down