Skip to content

Commit

Permalink
added params test
Browse files Browse the repository at this point in the history
  • Loading branch information
TommyHPettersen committed Dec 16, 2024
1 parent c51b0e5 commit cf56a4d
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions adapters/kobler/params_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package kobler

import (
"encoding/json"
"testing"

"github.com/prebid/prebid-server/v3/openrtb_ext"
)

var validParams = []string{
`{}`,
`{ "test": true }`,
`{ "test": false }`,
}

func TestValidParams(t *testing.T) {
validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params")
if err != nil {
t.Fatalf("Failed to fetch the json-schemas. %v", err)
}

for _, validParam := range validParams {
if err := validator.Validate(openrtb_ext.BidderKobler, json.RawMessage(validParam)); err != nil {
t.Errorf("Schema rejected Kobler params: %s", validParam)
}
}
}

var invalidParams = []string{
``,
`null`,
`true`,
`5`,
`4.2`,
`[]`,
`{ "key": 2 }`,
`{ "anyparam": "anyvalue" }`,
}

func TestInvalidParams(t *testing.T) {
validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params")
if err != nil {
t.Fatalf("Failed to fetch the json-schemas. %v", err)
}

for _, invalidParam := range invalidParams {
if err := validator.Validate(openrtb_ext.BidderKrushmedia, json.RawMessage(invalidParam)); err == nil {
t.Errorf("Schema allowed unexpected params: %s", invalidParam)
}
}
}

0 comments on commit cf56a4d

Please sign in to comment.