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

     1  package jixie
     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  	if err != nil {
    13  		t.Fatalf("Failed to fetch the json-schemas. %v", err)
    14  	}
    15  
    16  	for _, validParam := range validParams {
    17  		if err := validator.Validate(openrtb_ext.BidderJixie, json.RawMessage(validParam)); err != nil {
    18  			t.Errorf("Schema rejected jixie params: %s", validParam)
    19  		}
    20  	}
    21  }
    22  
    23  func TestInvalidParams(t *testing.T) {
    24  	validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params")
    25  	if err != nil {
    26  		t.Fatalf("Failed to fetch the json-schemas. %v", err)
    27  	}
    28  
    29  	for _, invalidParam := range invalidParams {
    30  		if err := validator.Validate(openrtb_ext.BidderJixie, json.RawMessage(invalidParam)); err == nil {
    31  			t.Errorf("Schema allowed unexpected params: %s", invalidParam)
    32  		}
    33  	}
    34  }
    35  
    36  var validParams = []string{
    37  	`{"unit": "1000008-AA77BB88CC" }`,
    38  	`{"unit": "1000008-AA77BB88CC", "accountid": "9988776655", "jxprop1": "somethingimportant" }`,
    39  }
    40  
    41  var invalidParams = []string{
    42  	`null`,
    43  	`nil`,
    44  	``,
    45  	`[]`,
    46  	`true`,
    47  	`{}`,
    48  	`{"unit":12345678}`,
    49  	`{"Unit":"12345678"}`,
    50  	`{"Unit": 12345678}`,
    51  	`{"AdUnit": "1"}`,
    52  	`{"adUnit": 1}`,
    53  	`{"unit": ""}`,
    54  	`{"unit": "12345678901234567"}`,
    55  	`{"unit":"1000008-AA77BB88CC", "accountid",  "jxprop1": "somethingimportant" }`,
    56  	`{"unit":"1000008-AA77BB88CC", malformed, }`,
    57  }