github.com/prebid/prebid-server/v2@v2.18.0/adapters/ix/params_test.go (about)

     1  package ix
     2  
     3  import (
     4  	"encoding/json"
     5  	"testing"
     6  
     7  	"github.com/prebid/prebid-server/v2/openrtb_ext"
     8  )
     9  
    10  func TestValidParams(t *testing.T) {
    11  	validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params")
    12  	if err != nil {
    13  		t.Fatalf("Failed to fetch the json-schemas. %v", err)
    14  	}
    15  
    16  	for _, validParam := range validParams {
    17  		if err := validator.Validate(openrtb_ext.BidderIx, json.RawMessage(validParam)); err != nil {
    18  			t.Errorf("Schema rejected ix params: %s", validParam)
    19  		}
    20  	}
    21  }
    22  
    23  func TestInvalidParams(t *testing.T) {
    24  	validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params")
    25  	if err != nil {
    26  		t.Fatalf("Failed to fetch the json-schemas. %v", err)
    27  	}
    28  
    29  	for _, invalidParam := range invalidParams {
    30  		if err := validator.Validate(openrtb_ext.BidderIx, json.RawMessage(invalidParam)); err == nil {
    31  			t.Errorf("Schema allowed unexpected params: %s", invalidParam)
    32  		}
    33  	}
    34  }
    35  
    36  var validParams = []string{
    37  	`{"siteid":"1234"}`,
    38  	`{"siteID":"12345"}`,
    39  	`{"siteId":"123456"}`,
    40  	`{"siteid":"1234567", "size": [640,480]}`,
    41  	`{"siteId":"123456", "sid":"12345"}`,
    42  }
    43  
    44  var invalidParams = []string{
    45  	`{"siteid":""}`,
    46  	`{"siteID":""}`,
    47  	`{"siteId":""}`,
    48  	`{"siteid":"1234", "siteID":"12345"}`,
    49  	`{"siteid":"1234", "siteId":"123456"}`,
    50  	`{"siteid":123}`,
    51  	`{"siteids":"123"}`,
    52  	`{"notaparam":"123"}`,
    53  	`{"siteid":"123", "size": [1,2,3]}`,
    54  	`null`,
    55  	`true`,
    56  	`0`,
    57  	`abc`,
    58  	`[]`,
    59  	`{}`,
    60  }