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

     1  package admixer
     2  
     3  import (
     4  	"encoding/json"
     5  	"testing"
     6  
     7  	"github.com/prebid/prebid-server/v2/openrtb_ext"
     8  )
     9  
    10  // This file actually intends to test static/bidder-params/admixer.json
    11  //
    12  // These also validate the format of the external API: request.imp[i].ext.prebid.bidder.admixer
    13  
    14  // TestValidParams makes sure that the admixer schema accepts all imp.ext fields which we intend to support.
    15  func TestValidParams(t *testing.T) {
    16  	validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params")
    17  	if err != nil {
    18  		t.Fatalf("Failed to fetch the json-schemas. %v", err)
    19  	}
    20  
    21  	for _, validParam := range validParams {
    22  		if err := validator.Validate(openrtb_ext.BidderAdmixer, json.RawMessage(validParam)); err != nil {
    23  			t.Errorf("Schema rejected admixer params: %s", validParam)
    24  		}
    25  	}
    26  }
    27  
    28  // TestInvalidParams makes sure that the admixer schema rejects all the imp.ext fields we don't support.
    29  func TestInvalidParams(t *testing.T) {
    30  	validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params")
    31  	if err != nil {
    32  		t.Fatalf("Failed to fetch the json-schemas. %v", err)
    33  	}
    34  
    35  	for _, invalidParam := range invalidParams {
    36  		if err := validator.Validate(openrtb_ext.BidderAdmixer, json.RawMessage(invalidParam)); err == nil {
    37  			t.Errorf("Schema allowed unexpected params: %s", invalidParam)
    38  		}
    39  	}
    40  }
    41  
    42  var validParams = []string{
    43  	`{"zone": "9FF668A2-4122-462E-AAF8-36EA3A54BA21"}`,
    44  	`{"zone": "9ff668a2-4122-462e-aaf8-36ea3a54ba21"}`,
    45  	`{"zone": "9FF668A2-4122-462E-AAF8-36EA3A54BA21", "customFloor": 0.1}`,
    46  	`{"zone": "9FF668A2-4122-462E-AAF8-36EA3A54BA21", "customParams": {"foo": "bar"}}`,
    47  	`{"zone": "9ff668a2-4122-462e-aaf8-36ea3a54ba21", "customFloor": 0.1, "customParams": {"foo": ["bar", "baz"]}}`,
    48  	`{"zone": "9FF668A24122462EAAF836EA3A54BA21"}`,
    49  	`{"zone": "9FF668A24122462EAAF836EA3A54BA212"}`,
    50  }
    51  
    52  var invalidParams = []string{
    53  	`{"zone": "123"}`,
    54  	`{"zone": ""}`,
    55  	`{"zone": "ZFF668A2-4122-462E-AAF8-36EA3A54BA21"}`,
    56  	`{"zone": "9FF668A2-4122-462E-AAF8-36EA3A54BA211"}`,
    57  	`{"zone": "123", "customFloor": "0.1"}`,
    58  	`{"zone": "9FF668A2-4122-462E-AAF8-36EA3A54BA21",  "customFloor": -0.1}`,
    59  	`{"zone": "9FF668A2-4122-462E-AAF8-36EA3A54BA21",  "customParams": "foo: bar"}`,
    60  	`{"zone": "9FF668A24122462EAAF836EA3A54BA2"}`,
    61  	`{"zone": "9FF668A24122462EAAF836EA3A54BA2112336"}`,
    62  }