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

     1  package beachfront
     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.BidderBeachfront, json.RawMessage(validParam)); err != nil {
    18  			t.Errorf("Schema rejected beachfront 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.BidderBeachfront, json.RawMessage(invalidParam)); err == nil {
    31  			t.Errorf("Schema allowed unexpected params: %s", invalidParam)
    32  		}
    33  	}
    34  }
    35  
    36  var validParams = []string{
    37  	`{"appId":"eitherBannerOrVideoAppId", "bidfloor":9.21}`,
    38  	`{"appId":"eitherBannerOrVideoAppId", "bidfloor":9.23129837662781}`,
    39  	`{"appId":"eitherBannerOrVideoAppId", "bidfloor":0.01}`,
    40  	`{"appId":"eitherBannerOrVideoAppId", "bidfloor":0}`,
    41  	`{"appId":"eitherBannerOrVideoAppId"}`,
    42  	`{"appIds": {
    43  		"banner":"aBannerAppId"
    44  		}
    45  	}`,
    46  	`{"appIds": {
    47  		"video":"aVideoAppId"
    48  		}
    49  	}`,
    50  	`{"appIds": {
    51  		"video":"aVideoAppId",
    52  		"banner":"aBannerAppId"
    53  		}
    54  	}`,
    55  	`{"bidfloor":2.50,
    56  		"appIds": {
    57  			"video":"aVideoAppId",
    58  			"banner":"aBannerAppId"
    59  		},
    60  		"videoResponseType":"nurl"
    61  	}`,
    62  }
    63  
    64  var invalidParams = []string{
    65  	`{"appId":1176, "bidfloor":0.01}`,
    66  	`{"appIds":"eitherBannerOrVideoAppId"}`,
    67  	`{"appIds":{"cerebralUplink":"cerebralUplinkAppId"}}`,
    68  	`{"appId":"eitherBannerOrVideoAppId",
    69  		"appIds": {
    70  			"video":"aVideoAppId",
    71  			"banner":"aBannerAppId"
    72  		}
    73  	}`,
    74  	`{}`,
    75  }