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

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