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

     1  package tpmn
     2  
     3  import (
     4  	"encoding/json"
     5  	"github.com/prebid/prebid-server/openrtb_ext"
     6  	"testing"
     7  )
     8  
     9  var validParams = []string{
    10  	`{"inventoryId": 10000001}`,
    11  }
    12  
    13  var invalidParams = []string{
    14  	`{"inventoryId": "00000001"}`,
    15  	`{"inventoryid": 100000000}`,
    16  }
    17  
    18  // TestValidParams makes sure that the tpmn schema accepts all imp.ext fields which we intend to support.
    19  func TestValidParams(t *testing.T) {
    20  	validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params")
    21  	if err != nil {
    22  		t.Fatalf("Failed to fetch the json-schemas. %v", err)
    23  	}
    24  
    25  	for _, validParam := range validParams {
    26  		if err := validator.Validate(openrtb_ext.BidderTpmn, json.RawMessage(validParam)); err != nil {
    27  			t.Errorf("Schema rejected TPMN params: %s", validParam)
    28  		}
    29  	}
    30  }
    31  
    32  // TestInvalidParams makes sure that the tpmn schema rejects all the imp.ext fields we don't support.
    33  func TestInvalidParams(t *testing.T) {
    34  	validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params")
    35  	if err != nil {
    36  		t.Fatalf("Failed to fetch the json-schemas. %v", err)
    37  	}
    38  
    39  	for _, invalidParam := range invalidParams {
    40  		if err := validator.Validate(openrtb_ext.BidderTpmn, json.RawMessage(invalidParam)); err == nil {
    41  			t.Errorf("Schema allowed unexpected params: %s", invalidParam)
    42  		}
    43  	}
    44  }