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

     1  package bidmyadz
     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  	`{ "placementId": "1234" }`,
    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.BidderBidmyadz, json.RawMessage(validParam)); err != nil {
    22  			t.Errorf("Schema rejected bidmyadz params: %s", validParam)
    23  		}
    24  	}
    25  }
    26  
    27  var invalidParams = []string{
    28  	`1234`,
    29  	``,
    30  	`true`,
    31  	`null`,
    32  	`[]`,
    33  	`{}`,
    34  	`{ "anyparam": "anyvalue" }`,
    35  	`{ "placementId": null }`,
    36  }
    37  
    38  func TestInvalidParams(t *testing.T) {
    39  	validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params")
    40  	if err != nil {
    41  		t.Fatalf("Failed to fetch the json-schemas. %v", err)
    42  	}
    43  
    44  	for _, invalidParam := range invalidParams {
    45  		if err := validator.Validate(openrtb_ext.BidderBidmyadz, json.RawMessage(invalidParam)); err == nil {
    46  			t.Errorf("Schema allowed unexpected params: %s", invalidParam)
    47  		}
    48  	}
    49  }