Skip to content
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
4 changes: 2 additions & 2 deletions modules/yaleoBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Module that connects to Yaleo's demand sources.

# Test parameters

**Note:** to receive bids when testing without proper integration with the demand source, enable Prebid.js debug mode. See [how to enable debug mode](https://docs.prebid.org/dev-docs/publisher-api-reference/setConfig.html#debugging) for details.
**Note:** to receive test bids without proper integration with the demand source, add `yaleo_test=true` to the page URL (e.g. `https://example.com/page?yaleo_test=true`). The adapter then sends the bid request with the OpenRTB `test: 1` flag, and the endpoint answers with test bids. Setting `test: 1` in the first party data with `pbjs.setConfig({ ortb2: { test: 1 } })` works too, but marks the request as test traffic for every bidder.

```js
const adUnits = [
Expand All @@ -30,7 +30,7 @@ const adUnits = [
bids: [{
bidder: "yaleo",
params: {
placementId: "95a09f24-afb8-441c-977b-08b4039cb88e",
placementId: "9c752583-d856-4b44-a227-c0ce6c7a8cfa",
}
}]
}
Expand Down
9 changes: 8 additions & 1 deletion modules/yaleoBidAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { pbsExtensions } from '../libraries/pbsExtensions/pbsExtensions.js';
import { BidderSpec, registerBidder } from '../src/adapters/bidderFactory.js';
import { config } from '../src/config.js';
import { BANNER } from '../src/mediaTypes.js';
import { logWarn } from '../src/utils.js';
import { getParameterByName, logWarn } from '../src/utils.js';

interface YaleoBidParams {
/**
Expand Down Expand Up @@ -53,6 +53,13 @@ const converter = ortbConverter<typeof BIDDER_CODE>({
ttl: DEFAULT_TTL,
},
processors: pbsExtensions,
request(buildRequest, imps, bidderRequest, context) {
const request = buildRequest(imps, bidderRequest, context);
if (getParameterByName('yaleo_test').toUpperCase() === 'TRUE') {
request.test = 1;
}
return request;
},
});

const resolveEndpoint = (): string => {
Expand Down
64 changes: 64 additions & 0 deletions test/spec/modules/yaleoBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { cloneDeep } from "lodash";
import sinon from 'sinon';
import { config } from "src/config.js";
import * as utils from "src/utils.js";
import { spec } from "../../../modules/yaleoBidAdapter.ts";

const bannerBidRequestBase = {
Expand Down Expand Up @@ -210,6 +212,68 @@ describe('Yaleo bid adapter', () => {
expect(request.url).to.equal('https://bidder.yaleo.com/prebid');
});

describe('test mode', () => {
let getParameterByNameStub;

const buildRequest = (ortb2) => spec.buildRequests([bannerBidRequest], {
bids: [bannerBidRequest],
auctionId: bannerBidRequest.auctionId,
bidderRequestId: bannerBidRequest.bidderRequestId,
ortb2,
});

const setTestQueryParam = (value) => {
getParameterByNameStub = sinon.stub(utils, 'getParameterByName')
.callsFake((name) => (name === 'yaleo_test' ? value : ''));
};

afterEach(() => {
getParameterByNameStub?.restore();
getParameterByNameStub = undefined;
});

['true', 'TRUE', 'True'].forEach((value) => {
it(`sets test: 1 when the page URL has yaleo_test=${value}`, () => {
setTestQueryParam(value);

expect(buildRequest().data.test).to.equal(1);
});
});

['', 'false', '1'].forEach((value) => {
it(`does not flag the request as a test when yaleo_test is "${value}"`, () => {
setTestQueryParam(value);

expect(buildRequest().data.test).to.not.equal(1);
});
});

it('does not flag the request as a test in Prebid.js debug mode', () => {
config.setConfig({ debug: true });

const request = buildRequest();

expect(request.data.test).to.not.equal(1);
expect(request.data.ext.prebid.debug).to.be.true;
});

it('keeps test: 1 set through ortb2', () => {
expect(buildRequest({ test: 1 }).data.test).to.equal(1);
});

it('keeps test: 1 set through ortb2 when yaleo_test=false', () => {
setTestQueryParam('false');

expect(buildRequest({ test: 1 }).data.test).to.equal(1);
});

it('sets test: 1 when yaleo_test=true and ortb2 sets test: 0', () => {
setTestQueryParam('true');

expect(buildRequest({ test: 0 }).data.test).to.equal(1);
});
});

it('checks that all params are passed to the request', () => {
bannerBidRequest.params = {
placementId: '12345',
Expand Down
Loading