Skip to content

Commit

Permalink
Dailymotion Bid Adaptor: only support video adunits in context instream
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Siow authored and kvnsw committed Apr 19, 2024
1 parent 091eec5 commit 7a5b070
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 7 deletions.
19 changes: 18 additions & 1 deletion modules/dailymotionBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,24 @@ export const spec = {
* @return boolean True if this is a valid bid, and false otherwise.
*/
isBidRequestValid: function (bid) {
return typeof bid?.params?.apiKey === 'string' && bid.params.apiKey.length > 10;
if (bid?.params) {
// We only accept video adUnits
if (!bid?.mediaTypes?.[VIDEO]) return false;

// As `context`, `placement` & `plcmt` are optional (although recommended)
// values, we check the 3 of them to see if we are in an instream video context
const isInstream = bid.mediaTypes[VIDEO].context === 'instream' ||
bid.mediaTypes[VIDEO].placement === 1 ||
bid.mediaTypes[VIDEO].plcmt === 1;

// We only accept instream video context
if (!isInstream) return false;

// We need API key
return typeof bid.params.apiKey === 'string' && bid.params.apiKey.length > 10;
}

return false;
},

/**
Expand Down
23 changes: 18 additions & 5 deletions modules/dailymotionBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ Maintainer: ad-leo-engineering@dailymotion.com
# Description

Dailymotion prebid adapter.
Supports video ad units in instream context.

# Configuration options

Before calling this adapter, you need to set at least the API key in the bid parameters:
Before calling this adapter, you need to at least set a video adUnit in an instream context and the API key in the bid parameters:

```javascript
const adUnits = [
Expand All @@ -21,8 +22,14 @@ const adUnits = [
bidder: 'dailymotion',
params: {
apiKey: 'fake_api_key'
}
}]
},
}],
code: 'test-ad-unit',
mediaTypes: {
video: {
context: 'instream',
},
},
}
];
```
Expand All @@ -40,8 +47,14 @@ const adUnits = [
bidder: 'dailymotion',
params: {
apiKey: 'dailymotion-testing'
}
}]
},
}],
code: 'test-ad-unit',
mediaTypes: {
video: {
context: 'instream',
},
},
}
];
```
Expand Down
55 changes: 54 additions & 1 deletion test/spec/modules/dailymotionBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { config } from 'src/config.js';
import { expect } from 'chai';
import { spec } from 'modules/dailymotionBidAdapter.js';
import { VIDEO } from '../../../src/mediaTypes';
import { BANNER, VIDEO } from '../../../src/mediaTypes';

describe('dailymotionBidAdapterTests', () => {
// Validate that isBidRequestValid only validates requests with apiKey
Expand All @@ -12,6 +12,11 @@ describe('dailymotionBidAdapterTests', () => {
params: {
apiKey: '',
},
mediaTypes: {
[VIDEO]: {
context: 'instream',
},
},
};

expect(config.runWithBidder('dailymotion', () => spec.isBidRequestValid(bidWithEmptyApi))).to.be.false;
Expand All @@ -20,9 +25,57 @@ describe('dailymotionBidAdapterTests', () => {
params: {
apiKey: 'test_api_key',
},
mediaTypes: {
[VIDEO]: {
context: 'instream',
},
},
};

expect(config.runWithBidder('dailymotion', () => spec.isBidRequestValid(bidWithApi))).to.be.true;

const bidWithEmptyMediaTypes = {
params: {
apiKey: '',
},
};

expect(config.runWithBidder('dailymotion', () => spec.isBidRequestValid(bidWithEmptyMediaTypes))).to.be.false;

const bidWithEmptyVideoAdUnit = {
params: {
apiKey: '',
},
mediaTypes: {
[VIDEO]: {},
},
};

expect(config.runWithBidder('dailymotion', () => spec.isBidRequestValid(bidWithEmptyVideoAdUnit))).to.be.false;

const bidWithBannerMediaType = {
params: {
apiKey: 'test_api_key',
},
mediaTypes: {
[BANNER]: {},
},
};

expect(config.runWithBidder('dailymotion', () => spec.isBidRequestValid(bidWithBannerMediaType))).to.be.false;

const bidWithOutstreamContext = {
params: {
apiKey: 'test_api_key',
},
mediaTypes: {
video: {
context: 'outstream',
},
},
};

expect(config.runWithBidder('dailymotion', () => spec.isBidRequestValid(bidWithOutstreamContext))).to.be.false;
});

// Validate request generation
Expand Down

0 comments on commit 7a5b070

Please sign in to comment.