Skip to content

Commit

Permalink
feat(sublimeBidAdapter): updating sublimeBidAdapter module (#6113)
Browse files Browse the repository at this point in the history
- using a simple-request for the POST bid request
- renaming our internal ver pixel param to pbav
  • Loading branch information
fgcloutier authored Dec 14, 2020
1 parent 94c9dcc commit 2102f4a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 12 deletions.
11 changes: 6 additions & 5 deletions modules/sublimeBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const DEFAULT_CURRENCY = 'EUR';
const DEFAULT_PROTOCOL = 'https';
const DEFAULT_TTL = 600;
const SUBLIME_ANTENNA = 'antenna.ayads.co';
const SUBLIME_VERSION = '0.6.0';
const SUBLIME_VERSION = '0.7.0';

/**
* Debug log message
Expand Down Expand Up @@ -50,7 +50,7 @@ export function sendEvent(eventName) {
src: 'pa',
puid: state.transactionId || state.notifyId,
trId: state.transactionId || state.notifyId,
ver: SUBLIME_VERSION,
pbav: SUBLIME_VERSION,
};

log('Sending pixel for event: ' + eventName, eventObject);
Expand Down Expand Up @@ -128,10 +128,10 @@ function buildRequests(validBidRequests, bidderRequest) {
return {
method: 'POST',
url: protocol + '://' + bidHost + '/bid',
data: payload,
data: JSON.stringify(payload),
options: {
contentType: 'application/json',
withCredentials: true
contentType: 'text/plain',
withCredentials: false
},
}
});
Expand Down Expand Up @@ -210,6 +210,7 @@ export const spec = {
code: BIDDER_CODE,
gvlid: BIDDER_GVLID,
aliases: [],
sendEvent: sendEvent,
isBidRequestValid: isBidRequestValid,
buildRequests: buildRequests,
interpretResponse: interpretResponse,
Expand Down
47 changes: 40 additions & 7 deletions test/spec/modules/sublimeBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from 'chai';
import { spec, sendEvent, log, setState, state } from 'modules/sublimeBidAdapter.js';
import { spec } from 'modules/sublimeBidAdapter.js';
import { newBidder } from 'src/adapters/bidderFactory.js';

let utils = require('src/utils');
Expand All @@ -9,15 +9,27 @@ describe('Sublime Adapter', function() {

describe('sendEvent', function() {
let sandbox;
const triggeredPixelProperties = [
't',
'tse',
'z',
'e',
'src',
'puid',
'trId',
'pbav',
];

beforeEach(function () {
sandbox = sinon.sandbox.create();
});

it('should trigger pixel', function () {
sandbox.spy(utils, 'triggerPixel');
sendEvent('test', true);
spec.sendEvent('test');
expect(utils.triggerPixel.called).to.equal(true);
const params = utils.parseUrl(utils.triggerPixel.args[0][0]).search;
expect(Object.keys(params)).to.have.members(triggeredPixelProperties);
});

afterEach(function () {
Expand Down Expand Up @@ -94,8 +106,9 @@ describe('Sublime Adapter', function() {
});

it('should contains a request id equals to the bid id', function() {
expect(request[0].data.requestId).to.equal(bidRequests[0].bidId);
expect(request[1].data.requestId).to.equal(bidRequests[1].bidId);
for (let i = 0; i < request.length; i = i + 1) {
expect(JSON.parse(request[i].data).requestId).to.equal(bidRequests[i].bidId);
}
});

it('should have an url that contains bid keyword', function() {
Expand Down Expand Up @@ -149,7 +162,7 @@ describe('Sublime Adapter', function() {
currency: 'USD',
netRevenue: true,
ttl: 600,
pbav: '0.6.0',
pbav: '0.7.0',
ad: '',
},
];
Expand Down Expand Up @@ -191,7 +204,7 @@ describe('Sublime Adapter', function() {
netRevenue: true,
ttl: 600,
ad: '<!-- Creative -->',
pbav: '0.6.0',
pbav: '0.7.0',
};

expect(result[0]).to.deep.equal(expectedResponse);
Expand Down Expand Up @@ -241,7 +254,7 @@ describe('Sublime Adapter', function() {
netRevenue: true,
ttl: 600,
ad: '<!-- ad -->',
pbav: '0.6.0',
pbav: '0.7.0',
};

expect(result[0]).to.deep.equal(expectedResponse);
Expand Down Expand Up @@ -279,4 +292,24 @@ describe('Sublime Adapter', function() {
});
});
});

describe('onBidWon', function() {
let sandbox;
let bid = { foo: 'bar' };

beforeEach(function () {
sandbox = sinon.sandbox.create();
});

it('should trigger "bidwon" pixel', function () {
sandbox.spy(utils, 'triggerPixel');
spec.onBidWon(bid);
const params = utils.parseUrl(utils.triggerPixel.args[0][0]).search;
expect(params.e).to.equal('bidwon');
});

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

0 comments on commit 2102f4a

Please sign in to comment.