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

     1  package mobilefuse
     2  
     3  import (
     4  	"encoding/json"
     5  	"testing"
     6  
     7  	"github.com/prebid/prebid-server/v2/openrtb_ext"
     8  )
     9  
    10  func TestValidParams(test *testing.T) {
    11  	validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params")
    12  
    13  	if err != nil {
    14  		test.Fatalf("Failed to fetch the json-schemas. %v", err)
    15  	}
    16  
    17  	for _, validParam := range validParams {
    18  		err := validator.Validate(openrtb_ext.BidderMobileFuse, json.RawMessage(validParam))
    19  
    20  		if err != nil {
    21  			test.Errorf("Schema rejected MobileFuse params: %s\nError: %v", validParam, err)
    22  		}
    23  	}
    24  }
    25  
    26  func TestInvalidParams(test *testing.T) {
    27  	validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params")
    28  
    29  	if err != nil {
    30  		test.Fatalf("Failed to fetch the json-schemas. %v", err)
    31  	}
    32  
    33  	for _, invalidParam := range invalidParams {
    34  		err := validator.Validate(openrtb_ext.BidderMobileFuse, json.RawMessage(invalidParam))
    35  
    36  		if err == nil {
    37  			test.Errorf("Schema allowed unexpected params: %s", invalidParam)
    38  		}
    39  	}
    40  }
    41  
    42  var validParams = []string{
    43  	`{"placement_id":123,"pub_id":456}`,
    44  	`{"placement_id":123,"pub_id":456,"tagid_src":"ext"}`,
    45  	`{"placement_id":123, "pub_id":456, "tagid_src":""}`,
    46  }
    47  
    48  var invalidParams = []string{
    49  	`{"placement_id":123}`,
    50  	`{"pub_id":456}`,
    51  	`{"placement_id":"123","pub_id":"456"}`,
    52  	`{"placement_id":123, "placementId":123}`,
    53  	`{"tagid_src":"ext"}`,
    54  }