Skip to content

Commit

Permalink
Nativo Bid Adapter: refactored validity check to be more informative (#…
Browse files Browse the repository at this point in the history
…7632)

* Initial nativoBidAdapter document creation (js, md and spec)

* Fulling working prebid using nativoBidAdapter. Support for GDPR and CCPA in user syncs.

* Added defult size settings based on the largest ad unit. Added response body validation. Added consent to request url qs params.

* Changed bidder endpoint url

* Changed double quotes to single quotes.

* Reverted package-json.lock to remove modifications from PR

* Added optional bidder param 'url' so the ad server can force- match an existing placement

* Lint fix. Added space after if.

* Added new QS param to send various adUnit data to adapter endpopint

* Updated unit test for new QS param

* Added qs param to keep track of ad unit refreshes

* Updated bidMap key default value

* Updated refresh increment logic

* Refactored spread operator for IE11 support

* Updated isBidRequestValid check

* Refactored Object.enties to use Object.keys to fix CircleCI testing errors

Co-authored-by: Joshua Fledderjohn <jfledderjohn@nativo.com>
  • Loading branch information
jsfledd and jsfledd committed Oct 28, 2021
1 parent 8d02037 commit 7cba586
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 19 deletions.
28 changes: 27 additions & 1 deletion modules/nativoBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ const adUnitsRequested = {}

// Prebid adapter referrence doc: https://docs.prebid.org/dev-docs/bidder-adaptor.html

// Validity checks for optionsl paramters
const validParameter = {
url: (value) => typeof value === 'string',
placementId: (value) => {
const isString = typeof value === 'string'
const isNumber = typeof value === 'number'
return isString || isNumber
},
}

export const spec = {
code: BIDDER_CODE,
gvlid: GVLID,
Expand All @@ -30,7 +40,23 @@ export const spec = {
* @return boolean True if this is a valid bid, and false otherwise.
*/
isBidRequestValid: function (bid) {
return true
// We don't need any specific parameters to make a bid request
// If not parameters are supplied just verify it's the correct bidder code
if (!bid.params) return bid.bidder === BIDDER_CODE

// Check if any supplied parameters are invalid
const hasInvalidParameters = Object.keys(bid.params).some(key => {
const value = bid.params[key]
const validityCheck = validParameter[key]

// We don't have a test for this so it's not a paramter we care about
if (!validityCheck) return false

// Return if the check is not passed
return !validityCheck(value)
})

return !hasInvalidParameters
},

/**
Expand Down
53 changes: 35 additions & 18 deletions test/spec/modules/nativoBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,46 @@ import { spec } from 'modules/nativoBidAdapter.js'
describe('nativoBidAdapterTests', function () {
describe('isBidRequestValid', function () {
let bid = {
bidder: 'nativo',
params: {
placementId: '10433394',
},
adUnitCode: 'adunit-code',
sizes: [
[300, 250],
[300, 600],
],
bidId: '27b02036ccfa6e',
bidderRequestId: '1372cd8bd8d6a8',
auctionId: 'cfc467e4-2707-48da-becb-bcaab0b2c114',
bidder: 'nativo'
}

it('should return true when required params found', function () {
it('should return true if no params found', function () {
expect(spec.isBidRequestValid(bid)).to.equal(true)
})

it('should return true for valid placementId value', function () {
bid.params = {
placementId: '10433394',
}
expect(spec.isBidRequestValid(bid)).to.equal(true)
})

it('should return true for valid placementId value', function () {
bid.params = {
placementId: 10433394,
}
expect(spec.isBidRequestValid(bid)).to.equal(true)
})

it('should return false for invalid placementId value', function () {
bid.params = {
placementId: true,
}
expect(spec.isBidRequestValid(bid)).to.equal(false)
})

it('should return true for valid placementId value', function () {
bid.params = {
url: 'www.test.com',
}
expect(spec.isBidRequestValid(bid)).to.equal(true)
})

it('should return true when params are not passed', function () {
let bid2 = Object.assign({}, bid)
delete bid2.params
bid2.params = {}
expect(spec.isBidRequestValid(bid2)).to.equal(true)
it('should return false for invalid placementId value', function () {
bid.params = {
url: 4567890,
}
expect(spec.isBidRequestValid(bid)).to.equal(false)
})
})

Expand Down

0 comments on commit 7cba586

Please sign in to comment.