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

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