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

Nativo Bid Adapter: refactored validity check to be more informative #7632

Merged
merged 21 commits into from
Oct 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
38e1ade
Initial nativoBidAdapter document creation (js, md and spec)
jsfledd Feb 22, 2021
0792373
Fulling working prebid using nativoBidAdapter. Support for GDPR and C…
jsfledd Mar 12, 2021
008e906
Added defult size settings based on the largest ad unit. Added respon…
jsfledd Apr 5, 2021
21f3e0c
Changed bidder endpoint url
jsfledd Apr 7, 2021
1a33f2c
Changed double quotes to single quotes.
jsfledd Apr 7, 2021
517cd5b
Reverted package-json.lock to remove modifications from PR
jsfledd Apr 8, 2021
44bf428
Added optional bidder param 'url' so the ad server can force- match a…
jsfledd Apr 15, 2021
bfe0e1e
Lint fix. Added space after if.
jsfledd Apr 15, 2021
e927584
Added new QS param to send various adUnit data to adapter endpopint
jsfledd May 26, 2021
8ac4419
Merged latest prebid master branch
jsfledd May 26, 2021
26d8b86
Updated unit test for new QS param
jsfledd May 26, 2021
ead77de
Added qs param to keep track of ad unit refreshes
jsfledd Jul 20, 2021
4ed371c
Merged latest prebid master
jsfledd Jul 20, 2021
e59a770
Merged latest. Added adUnitCode as alternate to placementID. Removed …
jsfledd Sep 29, 2021
c338c4d
Updated bidMap key default value
jsfledd Sep 30, 2021
bfe7b02
Updated refresh increment logic
jsfledd Oct 12, 2021
06407a1
Merged latest
jsfledd Oct 25, 2021
978ffd7
Refactored spread operator for IE11 support
jsfledd Oct 25, 2021
f74f370
Updated isBidRequestValid check
jsfledd Oct 26, 2021
e1554d0
Merge branch 'master' of https://github.com/prebid/Prebid.js
jsfledd Oct 26, 2021
7b9c9bb
Refactored Object.enties to use Object.keys to fix CircleCI testing e…
jsfledd Oct 26, 2021
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
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