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

     1  package adsinteractive
     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/adsinteractive.json
    11  
    12  func TestValidParams(t *testing.T) {
    13  	validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params")
    14  	if err != nil {
    15  		t.Fatalf("Failed to fetch the json-schemas. %v", err)
    16  	}
    17  
    18  	for _, validParam := range validParams {
    19  		if err := validator.Validate(openrtb_ext.BidderAdsinteractive, json.RawMessage(validParam)); err != nil {
    20  			t.Errorf("Schema rejected adsinteractive params: %s", validParam)
    21  		}
    22  	}
    23  }
    24  
    25  // TestInvalidParams makes sure that the Adsinteractive schema rejects all the imp.ext fields we don't support.
    26  func TestInvalidParams(t *testing.T) {
    27  	validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params")
    28  	if err != nil {
    29  		t.Fatalf("Failed to fetch the json-schemas. %v", err)
    30  	}
    31  
    32  	for _, invalidParam := range invalidParams {
    33  		if err := validator.Validate(openrtb_ext.BidderAdsinteractive, json.RawMessage(invalidParam)); err == nil {
    34  			t.Errorf("Schema allowed unexpected params: %s", invalidParam)
    35  		}
    36  	}
    37  }
    38  
    39  var validParams = []string{
    40  	`{"adUnit": "Example_ad_unit_1"}`,
    41  }
    42  
    43  var invalidParams = []string{
    44  	`{"adunit": "Example_ad_unit_1"}`,
    45  	`{"AdUnit": "Example_ad_unit_1"}`,
    46  	`{"ad_unit": Example_ad_unit_1}`,
    47  	``,
    48  	`null`,
    49  	`true`,
    50  	`[]`,
    51  	`{}`,
    52  	`nil`,
    53  	`53`,
    54  	`9.1`,
    55  }