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

JW Demand: Implemented isBidRequestValid with Unit Tests. #25

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
40 changes: 23 additions & 17 deletions modules/jwplayerBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,53 @@
import * as utils from 'src/utils';
import { registerBidder } from 'src/adapters/bidderFactory';
import { config } from 'src/config';
import { VIDEO } from 'src/mediaTypes';
// import * as utils from 'src/utils';
import { registerBidder } from '../src/adapters/bidderFactory.js';
// import { config } from 'src/config';
import { VIDEO } from '../src/mediaTypes.js';

const BIDDER_CODE = 'jwplayer';
const GVLID = 1046;
const SUPPORTED_AD_TYPES = [VIDEO];

export const spec = {
code: BIDDER_CODE,
gvlid: GVLID,
supportedMediaTypes: SUPPORTED_AD_TYPES,
code: BIDDER_CODE,
gvlid: GVLID,
supportedMediaTypes: SUPPORTED_AD_TYPES,

/**
* Determines whether or not the given bid request is valid.
*
* @param {object} bid The bid to validate.
* @return boolean True if this is a valid bid, and false otherwise.
*/
isBidRequestValid: function(bid) {},
isBidRequestValid: function(bid) {
if (!bid || !bid.params) {
return false;
}

return !!bid.params.placementId && !!bid.params.pubId;
},

/**
* Make a server request from the list of BidRequests.
*
* @param {BidRequest[]} bidRequests A non-empty list of bid requests which should be sent to the Server.
* @return ServerRequest Info describing the request to the server.
*/
buildRequests: function(validBidRequests, bidderRequest) {},
buildRequests: function(validBidRequests, bidderRequest) {},

/**
* Unpack the response from the server into a list of bids.
*
* @param {*} serverResponse A successful response from the server.
* @return {Bid[]} An array of bids which were nested inside the server.
*/
interpretResponse: function(serverResponse, request) {},
getUserSyncs: function(syncOptions, serverResponses, gdprConsent, uspConsent) {},

interpretResponse: function(serverResponse, request) {},
getUserSyncs: function(syncOptions, serverResponses, gdprConsent, uspConsent) {},

// Optional?
onTimeout: function(timeoutData) {},
onBidWon: function(bid) {},
onSetTargeting: function(bid) {},
onBidderError: function({ error, bidderRequest }) {}
// Optional?
// onTimeout: function(timeoutData) {},
// onBidWon: function(bid) {},
// onSetTargeting: function(bid) {},
// onBidderError: function({ error, bidderRequest }) {}
};

registerBidder(spec);
42 changes: 31 additions & 11 deletions test/spec/modules/jwplayerBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,43 @@ import { spec } from 'modules/jwplayerBidAdapter.js';
import { config } from 'src/config.js';

describe('jwplayer adapter tests', function() {
var sandbox, clock, frozenNow = new Date();
var sandbox, clock, frozenNow = new Date();

beforeEach(function() {
sandbox = sinon.sandbox.create();
clock = sinon.useFakeTimers(frozenNow.getTime());
beforeEach(function() {
sandbox = sinon.sandbox.create();
clock = sinon.useFakeTimers(frozenNow.getTime());
});

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

describe('isBidRequestValid', function() {
it('passes when the bid includes a placement ID and a publisher ID', function() {
assert(spec.isBidRequestValid({params: {placementId: 'foo', pubId: 'bar'}}) === true);
});

it('fails when the bid does not include a placement ID', function() {
assert(spec.isBidRequestValid({params: {pubId: 'foo'}}) === false);
});

afterEach(function() {
sandbox.restore();
clock.restore();
it('fails when the bid does not include a publisher ID', function() {
assert(spec.isBidRequestValid({params: {placementId: 'foo'}}) === false);
});

describe('isBidRequestValid', function() {});
it('fails when bid is falsey', function() {
assert(spec.isBidRequestValid() === false);
});

it('fails when the bid has no params at all', function() {
assert(spec.isBidRequestValid({}) === false);
});
});

describe('buildRequests for video', function() {});
describe('buildRequests for video', function() {});

describe('interpretResponse for video', function() {});
describe('interpretResponse for video', function() {});

describe('user sync handler', function() {});
describe('user sync handler', function() {});
});