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

     1  package lemmadigital
     2  
     3  import (
     4  	"encoding/json"
     5  	"testing"
     6  
     7  	"github.com/prebid/prebid-server/v2/openrtb_ext"
     8  )
     9  
    10  // Tests for static/bidder-params/lemmadigital.json
    11  
    12  // Tests whether the schema supports the intended params.
    13  func TestValidParams(t *testing.T) {
    14  	validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params")
    15  	if err != nil {
    16  		t.Fatalf("Failed to fetch the json-schema. %v", err)
    17  	}
    18  
    19  	for _, validParam := range validParams {
    20  		if err := validator.Validate(openrtb_ext.BidderLemmadigital, json.RawMessage(validParam)); err != nil {
    21  			t.Errorf("Schema rejected params: %s \n Error: %s", validParam, err)
    22  		}
    23  	}
    24  }
    25  
    26  // Tests whether the schema rejects unsupported imp.ext fields.
    27  func TestInvalidParams(t *testing.T) {
    28  	validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params")
    29  	if err != nil {
    30  		t.Fatalf("Failed to fetch the json-schema. %v", err)
    31  	}
    32  
    33  	for _, invalidParam := range invalidParams {
    34  		if err := validator.Validate(openrtb_ext.BidderLemmadigital, json.RawMessage(invalidParam)); err == nil {
    35  			t.Errorf("Schema allowed invalid/unexpected params: %s", invalidParam)
    36  		}
    37  	}
    38  }
    39  
    40  var validParams = []string{
    41  	`{"pid":1, "aid": 1}`,
    42  	`{"pid":2147483647, "aid": 2147483647}`,
    43  }
    44  
    45  var invalidParams = []string{
    46  	``,
    47  	`null`,
    48  	`false`,
    49  	`0`,
    50  	`0.0`,
    51  	`[]`,
    52  	`{}`,
    53  	`{"pid":1}`,
    54  	`{"aid":1}`,
    55  	`{"pid":"1","aid":1}`,
    56  	`{"pid":1.0,"aid":"1"}`,
    57  	`{"pid":"1","aid":"1"}`,
    58  	`{"pid":false,"aid":true}`,
    59  }