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

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