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

     1  package bliink
     2  
     3  import (
     4  	"encoding/json"
     5  	"testing"
     6  
     7  	"github.com/prebid/prebid-server/v2/openrtb_ext"
     8  )
     9  
    10  var validParams = []string{
    11  	`{"tagId": "hash", "imageUrl": "https://www.test.com"}`,
    12  }
    13  
    14  func TestValidParams(t *testing.T) {
    15  	validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params")
    16  	if err != nil {
    17  		t.Fatalf("Failed to fetch the json schema. %v", err)
    18  	}
    19  
    20  	for _, validParam := range validParams {
    21  		if err := validator.Validate(openrtb_ext.BidderBliink, json.RawMessage(validParam)); err != nil {
    22  			t.Errorf("Schema rejected valid params: %s", validParam)
    23  		}
    24  	}
    25  }
    26  
    27  var invalidParams = []string{
    28  	``,
    29  	`null`,
    30  	`{"tagId": 32}`,
    31  	`{"imageUrl": 32}`,
    32  }
    33  
    34  func TestInvalidParams(t *testing.T) {
    35  	validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params")
    36  	if err != nil {
    37  		t.Fatalf("Failed to fetch the json schema. %v", err)
    38  	}
    39  
    40  	for _, invalidParam := range invalidParams {
    41  		if err := validator.Validate(openrtb_ext.BidderBliink, json.RawMessage(invalidParam)); err == nil {
    42  			t.Errorf("Schema allowed invalid params: %s", invalidParam)
    43  		}
    44  	}
    45  }