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

     1  package improvedigital
     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.BidderImprovedigital, json.RawMessage(validParam)); err != nil {
    18  			t.Errorf("Schema rejected improvedigital 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.BidderImprovedigital, json.RawMessage(invalidParam)); err == nil {
    31  			t.Errorf("Schema allowed unexpected params: %s", invalidParam)
    32  		}
    33  	}
    34  }
    35  
    36  var validParams = []string{
    37  	`{"placementId":13245}`,
    38  	`{"placementId":13245, "size": {"w":16, "h":9}}`,
    39  	`{"publisherId":13245, "placementKey": "slotA"}`,
    40  	`{"placementId":13245, "keyValues":{"target1":["foo"],"target2":["bar", "baz"]}}`,
    41  }
    42  
    43  var invalidParams = []string{
    44  	`null`,
    45  	`nil`,
    46  	``,
    47  	`[]`,
    48  	`true`,
    49  	`2`,
    50  	`{"size": {"w": 10, "h": 5}}`,
    51  	`{"other_optional": true}`,
    52  	`{"size":12345678}`,
    53  	`{"size":""}`,
    54  	`{"placementId":-9}`,
    55  	`{"publisherId":9}`,
    56  	`{"placementId": "1"}`,
    57  	`{"size": true}`,
    58  	`{"placementId": true, "size":"1234567"}`,
    59  	`{"placementId":13245, "publisherId":13245, "placementKey": "slotA"}`,
    60  }