Skip to content

Commit

Permalink
Ogury Bid Adapter: adding onTimeout support (prebid#7535)
Browse files Browse the repository at this point in the history
* [SPY-10216] adding onTimeout support

* [SPY-12216] reformulating test name
  • Loading branch information
mbouallagui authored and Chris Pabst committed Jan 10, 2022
1 parent 15af727 commit 2395256
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 11 deletions.
11 changes: 10 additions & 1 deletion modules/oguryBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { ajax } from '../src/ajax.js'
const BIDDER_CODE = 'ogury';
const DEFAULT_TIMEOUT = 1000;
const BID_HOST = 'https://mweb-hb.presage.io/api/header-bidding-request';
const TIMEOUT_MONITORING_HOST = 'https://ms-ads-monitoring-events.presage.io';
const MS_COOKIE_SYNC_DOMAIN = 'https://ms-cookie-sync.presage.io';

function isBidRequestValid(bid) {
Expand Down Expand Up @@ -141,6 +142,13 @@ function onBidWon(bid) {
if (bid && bid.hasOwnProperty('nurl') && bid.nurl.length > 0) ajax(bid['nurl'], null);
}

function onTimeout(timeoutData) {
ajax(`${TIMEOUT_MONITORING_HOST}/bid_timeout`, null, JSON.stringify(timeoutData[0]), {
method: 'POST',
contentType: 'application/json'
});
}

export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [BANNER],
Expand All @@ -149,7 +157,8 @@ export const spec = {
buildRequests,
interpretResponse,
getFloor,
onBidWon
onBidWon,
onTimeout
}

registerBidder(spec);
50 changes: 40 additions & 10 deletions test/spec/modules/oguryBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { expect } from 'chai';
import { spec } from 'modules/oguryBidAdapter';
import { deepClone } from 'src/utils.js';

const BID_HOST = 'https://mweb-hb.presage.io/api/header-bidding-request';
const BID_URL = 'https://mweb-hb.presage.io/api/header-bidding-request';
const TIMEOUT_URL = 'https://ms-ads-monitoring-events.presage.io/bid_timeout'

describe('OguryBidAdapter', function () {
let bidRequests;
Expand Down Expand Up @@ -150,7 +151,7 @@ describe('OguryBidAdapter', function () {
const userSyncs = spec.getUserSyncs(syncOptions, [], gdprConsent);
expect(userSyncs).to.have.lengthOf(1);
expect(userSyncs[0].type).to.equal('image');
expect(userSyncs[0].url).to.equal('https://ms-cookie-sync.presage.io/v1/init-sync/bid-switch?iab_string=&source=prebid');
expect(userSyncs[0].url).to.equal('https://ms-cookie-sync.presage.io/v1/init-sync/bid-switch?iab_string=&source=prebid')
});

it('should return syncs array with an element of type image when consentString is null', () => {
Expand All @@ -162,7 +163,7 @@ describe('OguryBidAdapter', function () {
const userSyncs = spec.getUserSyncs(syncOptions, [], gdprConsent);
expect(userSyncs).to.have.lengthOf(1);
expect(userSyncs[0].type).to.equal('image');
expect(userSyncs[0].url).to.equal('https://ms-cookie-sync.presage.io/v1/init-sync/bid-switch?iab_string=&source=prebid');
expect(userSyncs[0].url).to.equal('https://ms-cookie-sync.presage.io/v1/init-sync/bid-switch?iab_string=&source=prebid')
});

it('should return syncs array with an element of type image when gdprConsent is undefined', () => {
Expand All @@ -171,7 +172,7 @@ describe('OguryBidAdapter', function () {
const userSyncs = spec.getUserSyncs(syncOptions, [], gdprConsent);
expect(userSyncs).to.have.lengthOf(1);
expect(userSyncs[0].type).to.equal('image');
expect(userSyncs[0].url).to.equal('https://ms-cookie-sync.presage.io/v1/init-sync/bid-switch?iab_string=&source=prebid');
expect(userSyncs[0].url).to.equal('https://ms-cookie-sync.presage.io/v1/init-sync/bid-switch?iab_string=&source=prebid')
});

it('should return syncs array with an element of type image when gdprConsent is null', () => {
Expand All @@ -180,7 +181,7 @@ describe('OguryBidAdapter', function () {
const userSyncs = spec.getUserSyncs(syncOptions, [], gdprConsent);
expect(userSyncs).to.have.lengthOf(1);
expect(userSyncs[0].type).to.equal('image');
expect(userSyncs[0].url).to.equal('https://ms-cookie-sync.presage.io/v1/init-sync/bid-switch?iab_string=&source=prebid');
expect(userSyncs[0].url).to.equal('https://ms-cookie-sync.presage.io/v1/init-sync/bid-switch?iab_string=&source=prebid')
});

it('should return syncs array with an element of type image when gdprConsent is null and gdprApplies is false', () => {
Expand All @@ -192,7 +193,7 @@ describe('OguryBidAdapter', function () {
const userSyncs = spec.getUserSyncs(syncOptions, [], gdprConsent);
expect(userSyncs).to.have.lengthOf(1);
expect(userSyncs[0].type).to.equal('image');
expect(userSyncs[0].url).to.equal('https://ms-cookie-sync.presage.io/v1/init-sync/bid-switch?iab_string=&source=prebid');
expect(userSyncs[0].url).to.equal('https://ms-cookie-sync.presage.io/v1/init-sync/bid-switch?iab_string=&source=prebid')
});

it('should return syncs array with an element of type image when gdprConsent is empty string and gdprApplies is false', () => {
Expand All @@ -204,7 +205,7 @@ describe('OguryBidAdapter', function () {
const userSyncs = spec.getUserSyncs(syncOptions, [], gdprConsent);
expect(userSyncs).to.have.lengthOf(1);
expect(userSyncs[0].type).to.equal('image');
expect(userSyncs[0].url).to.equal('https://ms-cookie-sync.presage.io/v1/init-sync/bid-switch?iab_string=&source=prebid');
expect(userSyncs[0].url).to.equal('https://ms-cookie-sync.presage.io/v1/init-sync/bid-switch?iab_string=&source=prebid')
});
});

Expand Down Expand Up @@ -255,7 +256,7 @@ describe('OguryBidAdapter', function () {
const validBidRequests = deepClone(bidRequests)

const request = spec.buildRequests(validBidRequests, bidderRequest);
expect(request.url).to.equal(BID_HOST);
expect(request.url).to.equal(BID_URL);
expect(request.method).to.equal('POST');
});

Expand Down Expand Up @@ -453,11 +454,11 @@ describe('OguryBidAdapter', function () {
})

afterEach(function() {
xhr.restore();
xhr.restore()
})

it('Should not create nurl request if bid is undefined', function() {
spec.onBidWon();
spec.onBidWon()
expect(requests.length).to.equal(0);
})

Expand All @@ -473,4 +474,33 @@ describe('OguryBidAdapter', function () {
expect(requests[0].method).to.equal('GET')
})
})

describe('onTimeout', function () {
let xhr;
let requests;

beforeEach(function() {
xhr = sinon.useFakeXMLHttpRequest();
requests = [];
xhr.onCreate = (xhr) => {
requests.push(xhr);
};
})

afterEach(function() {
xhr.restore()
})

it('should send notification on bid timeout', function() {
const bid = {
ad: '<img style="width: 300px; height: 250px;" src="https://assets.afcdn.com/recipe/20190529/93153_w1024h768c1cx2220cy1728cxt0cyt0cxb4441cyb3456.jpg" alt="cookies" />',
cpm: 3
}
spec.onTimeout(bid);
expect(requests).to.not.be.undefined;
expect(requests.length).to.equal(1);
expect(requests[0].url).to.equal(TIMEOUT_URL);
expect(requests[0].method).to.equal('POST');
})
});
});

0 comments on commit 2395256

Please sign in to comment.