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

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