Skip to content

Commit

Permalink
convert bidders: beachfront
Browse files Browse the repository at this point in the history
  • Loading branch information
dgirardi committed May 20, 2022
1 parent 97ea0df commit b29945e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 36 deletions.
14 changes: 2 additions & 12 deletions modules/beachfrontBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
parseSizesInput,
parseUrl
} from '../src/utils.js';
import {config} from '../src/config.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {Renderer} from '../src/Renderer.js';
import {BANNER, VIDEO} from '../src/mediaTypes.js';
Expand Down Expand Up @@ -305,16 +304,7 @@ function isBannerBidValid(bid) {
}

function getTopWindowLocation(bidderRequest) {
let url = bidderRequest && bidderRequest.refererInfo && bidderRequest.refererInfo.referer;
return parseUrl(config.getConfig('pageUrl') || url, { decodeSearchAsString: true });
}

function getTopWindowReferrer() {
try {
return window.top.document.referrer;
} catch (e) {
return '';
}
return parseUrl(bidderRequest?.refererInfo?.page, { decodeSearchAsString: true });
}

function getEids(bid) {
Expand Down Expand Up @@ -433,7 +423,7 @@ function createVideoRequestData(bid, bidderRequest) {

function createBannerRequestData(bids, bidderRequest) {
let topLocation = getTopWindowLocation(bidderRequest);
let topReferrer = getTopWindowReferrer();
let topReferrer = bidderRequest.refererInfo?.ref;
let slots = bids.map(bid => {
return {
slot: bid.adUnitCode,
Expand Down
18 changes: 11 additions & 7 deletions test/spec/modules/appierBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,24 @@ describe('AppierAdapter', function () {
'auctionId': '1d1a030790a475',
};
const fakeBidRequests = [bid];
const fakeBidderRequest = {refererInfo: {
'referer': 'fakeReferer',
'reachedTop': true,
'numIframes': 1,
'stack': []
}};
const fakeBidderRequest = {
refererInfo: {
legacy: {
'referer': 'fakeReferer',
'reachedTop': true,
'numIframes': 1,
'stack': []
}
}
};

const builtRequests = spec.buildRequests(fakeBidRequests, fakeBidderRequest);
expect(builtRequests.length).to.equal(1);
expect(builtRequests[0].method).to.equal('POST');
expect(builtRequests[0].url).match(/v1\/prebid\/bid/);
expect(builtRequests[0].data).deep.equal({
'bids': fakeBidRequests,
'refererInfo': fakeBidderRequest.refererInfo,
'refererInfo': fakeBidderRequest.refererInfo.legacy,
'version': ADAPTER_VERSION
});
});
Expand Down
6 changes: 3 additions & 3 deletions test/spec/modules/beachfrontBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ describe('BeachfrontAdapter', function () {
const topLocation = parseUrl('http://www.example.com?foo=bar', { decodeSearchAsString: true });
const bidderRequest = {
refererInfo: {
referer: topLocation.href
page: topLocation.href
}
};
const requests = spec.buildRequests([ bidRequest ], bidderRequest);
Expand Down Expand Up @@ -398,7 +398,7 @@ describe('BeachfrontAdapter', function () {
const topLocation = parseUrl('http://www.example.com?foo=bar', { decodeSearchAsString: true });
const bidderRequest = {
refererInfo: {
referer: topLocation.href
page: topLocation.href
}
};
const requests = spec.buildRequests([ bidRequest ], bidderRequest);
Expand Down Expand Up @@ -572,7 +572,7 @@ describe('BeachfrontAdapter', function () {
bidRequest.mediaTypes = { video: {} };
const bidderRequest = {
refererInfo: {
referer: 'http://example.com/page.html'
page: 'http://example.com/page.html'
},
ortb2
};
Expand Down
28 changes: 14 additions & 14 deletions test/spec/refererDetection_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe('Referer detection', () => {
const testWindow = buildWindowTree(['https://example.com/some/page'], 'https://othersite.com/'),
result = detectReferer(testWindow)();

expect(result).to.deep.equal({
sinon.assert.match(result, {
topmostLocation: 'https://example.com/some/page',
location: 'https://example.com/some/page',
reachedTop: true,
Expand All @@ -120,7 +120,7 @@ describe('Referer detection', () => {
const testWindow = buildWindowTree(['https://example.com/some/page'], 'https://othersite.com/', 'https://example.com/canonical/page'),
result = detectReferer(testWindow)();

expect(result).to.deep.equal({
sinon.assert.match(result, {
topmostLocation: 'https://example.com/some/page',
location: 'https://example.com/some/page',
reachedTop: true,
Expand All @@ -140,7 +140,7 @@ describe('Referer detection', () => {
const testWindow = buildWindowTree(['https://example.com/some/page', 'https://example.com/other/page', 'https://example.com/third/page'], 'https://othersite.com/'),
result = detectReferer(testWindow)();

expect(result).to.deep.equal({
sinon.assert.match(result, {
topmostLocation: 'https://example.com/some/page',
location: 'https://example.com/some/page',
reachedTop: true,
Expand All @@ -162,7 +162,7 @@ describe('Referer detection', () => {
const testWindow = buildWindowTree(['https://example.com/some/page', 'https://example.com/other/page', 'https://example.com/third/page'], 'https://othersite.com/', 'https://example.com/canonical/page'),
result = detectReferer(testWindow)();

expect(result).to.deep.equal({
sinon.assert.match(result, {
topmostLocation: 'https://example.com/some/page',
location: 'https://example.com/some/page',
reachedTop: true,
Expand All @@ -186,7 +186,7 @@ describe('Referer detection', () => {
const testWindow = buildWindowTree(['https://example.com/some/page', 'https://example.com/other/page', 'https://example.com/third/page'], 'https://othersite.com/', 'https://example.com/canonical/page'),
result = detectReferer(testWindow)();

expect(result).to.deep.equal({
sinon.assert.match(result, {
topmostLocation: 'https://example.com/some/page',
location: 'https://example.com/some/page',
reachedTop: true,
Expand All @@ -211,7 +211,7 @@ describe('Referer detection', () => {
const testWindow = buildWindowTree(['https://example.com/some/page', 'https://safe.frame/ad'], 'https://othersite.com/', 'https://canonical.example.com/'),
result = detectReferer(testWindow)();

expect(result).to.deep.equal({
sinon.assert.match(result, {
location: 'https://example.com/some/page',
topmostLocation: 'https://example.com/some/page',
reachedTop: true,
Expand All @@ -232,7 +232,7 @@ describe('Referer detection', () => {
const testWindow = buildWindowTree(['https://example.com/some/page', 'https://safe.frame/ad', 'https://safe.frame/ad'], 'https://othersite.com/', 'https://canonical.example.com/'),
result = detectReferer(testWindow)();

expect(result).to.deep.equal({
sinon.assert.match(result, {
topmostLocation: 'https://example.com/some/page',
location: 'https://example.com/some/page',
reachedTop: true,
Expand All @@ -254,7 +254,7 @@ describe('Referer detection', () => {
const testWindow = buildWindowTree(['https://example.com/some/page', 'https://safe.frame/ad', 'https://otherfr.ame/ad'], 'https://othersite.com/', 'https://canonical.example.com/'),
result = detectReferer(testWindow)();

expect(result).to.deep.equal({
sinon.assert.match(result, {
topmostLocation: 'https://safe.frame/ad',
location: null,
reachedTop: false,
Expand All @@ -276,7 +276,7 @@ describe('Referer detection', () => {
const testWindow = buildWindowTree(['https://example.com/some/page', 'https://safe.frame/ad', 'https://otherfr.ame/ad'], 'https://othersite.com/', 'https://canonical.example.com/', true),
result = detectReferer(testWindow)();

expect(result).to.deep.equal({
sinon.assert.match(result, {
topmostLocation: 'https://example.com/',
location: 'https://example.com/',
reachedTop: false,
Expand Down Expand Up @@ -306,7 +306,7 @@ describe('Referer detection', () => {

const result = detectReferer(testWindow)();

expect(result).to.deep.equal({
sinon.assert.match(result, {
location: 'https://example.com/some/page/amp/',
topmostLocation: 'https://example.com/some/page/amp/',
reachedTop: true,
Expand All @@ -333,7 +333,7 @@ describe('Referer detection', () => {

const result = detectReferer(testWindow)();

expect(result).to.deep.equal({
sinon.assert.match(result, {
topmostLocation: 'https://example.com/some/page/amp/',
location: 'https://example.com/some/page/amp/',
reachedTop: true,
Expand Down Expand Up @@ -361,7 +361,7 @@ describe('Referer detection', () => {

const result = detectReferer(testWindow)();

expect(result).to.deep.equal({
sinon.assert.match(result, {
topmostLocation: 'https://example.com/some/page/amp/',
location: 'https://example.com/some/page/amp/',
reachedTop: false,
Expand Down Expand Up @@ -389,7 +389,7 @@ describe('Referer detection', () => {

const result = detectReferer(testWindow)();

expect(result).to.deep.equal({
sinon.assert.match(result, {
location: 'https://example.com/some/page/amp/',
topmostLocation: 'https://example.com/some/page/amp/',
reachedTop: false,
Expand Down Expand Up @@ -417,7 +417,7 @@ describe('Referer detection', () => {

const result = detectReferer(testWindow)();

expect(result).to.deep.equal({
sinon.assert.match(result, {
location: 'https://example.com/some/page/amp/',
topmostLocation: 'https://example.com/some/page/amp/',
reachedTop: false,
Expand Down

0 comments on commit b29945e

Please sign in to comment.