github.com/prebid/prebid-server/v2@v2.18.0/adapters/pangle/param_test.go (about)

     1  package pangle
     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  	`{"token": "SomeAccessToken"}`,
    12  	`{"token": "SomeAccessToken", "appid": "12345", "placementid": "12345"}`,
    13  }
    14  
    15  var invalidParams = []string{
    16  	`{"token": ""}`,
    17  	`{"token": 42}`,
    18  	`{"token": null}`,
    19  	`{}`,
    20  	// appid & placementid
    21  	`{"appid": "12345", "placementid": "12345"}`,
    22  	`{"token": "SomeAccessToken", "appid": "12345"}`,
    23  	`{"token": "SomeAccessToken", "placementid": "12345"}`,
    24  	`{"token": "SomeAccessToken", "appid": 12345, "placementid": 12345}`,
    25  	`{"token": "SomeAccessToken", "appid": null, "placementid": null}`,
    26  }
    27  
    28  func TestValidParams(t *testing.T) {
    29  	validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params")
    30  	if err != nil {
    31  		t.Fatalf("Failed to fetch the json schema. %v", err)
    32  	}
    33  
    34  	for _, p := range validParams {
    35  		if err := validator.Validate(openrtb_ext.BidderPangle, json.RawMessage(p)); err != nil {
    36  			t.Errorf("Schema rejected valid params: %s", p)
    37  		}
    38  	}
    39  }
    40  
    41  func TestInvalidParams(t *testing.T) {
    42  	validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params")
    43  	if err != nil {
    44  		t.Fatalf("Failed to fetch the json schema. %v", err)
    45  	}
    46  
    47  	for _, p := range invalidParams {
    48  		if err := validator.Validate(openrtb_ext.BidderPangle, json.RawMessage(p)); err == nil {
    49  			t.Errorf("Schema allowed invalid params: %s", p)
    50  		}
    51  	}
    52  }