github.com/prebid/prebid-server@v0.275.0/adapters/smartyads/params_test.go (about)

     1  package smartyads
     2  
     3  import (
     4  	"encoding/json"
     5  	"testing"
     6  
     7  	"github.com/prebid/prebid-server/openrtb_ext"
     8  )
     9  
    10  var validParams = []string{
    11  	`{ "host": "ep1", "sourceid": "partner", "accountid": "hash" }`,
    12  }
    13  
    14  func TestValidParams(t *testing.T) {
    15  	validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params")
    16  	if err != nil {
    17  		t.Fatalf("Failed to fetch the json-schemas. %v", err)
    18  	}
    19  
    20  	for _, validParam := range validParams {
    21  		if err := validator.Validate(openrtb_ext.BidderSmartyAds, json.RawMessage(validParam)); err != nil {
    22  			t.Errorf("Schema rejected SmartyAds params: %s", validParam)
    23  		}
    24  	}
    25  }
    26  
    27  var invalidParams = []string{
    28  	``,
    29  	`null`,
    30  	`true`,
    31  	`5`,
    32  	`4.2`,
    33  	`[]`,
    34  	`{}`,
    35  	`{"adCode": "string", "seatCode": 5, "originalPublisherid": "string"}`,
    36  	`{ "host": "ep1", "sourceid": "partner" }`,
    37  	`{ "host": "ep1, "accountid": "hash" }`,
    38  	`{ "sourceid": "partner", "sourceid": "partner" }`,
    39  }
    40  
    41  func TestInvalidParams(t *testing.T) {
    42  	validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params")
    43  	if err != nil {
    44  		t.Fatalf("Failed to fetch the json-schemas. %v", err)
    45  	}
    46  
    47  	for _, invalidParam := range invalidParams {
    48  		if err := validator.Validate(openrtb_ext.BidderSmartyAds, json.RawMessage(invalidParam)); err == nil {
    49  			t.Errorf("Schema allowed unexpected params: %s", invalidParam)
    50  		}
    51  	}
    52  }