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

     1  package bidmachine
     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.BidderBidmachine, json.RawMessage(validParam)); err != nil {
    18  			t.Errorf("Schema rejected Bidmachine params: %s \n Error: %s", validParam, err)
    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.BidderBidmachine, json.RawMessage(invalidParam)); err == nil {
    31  			t.Errorf("Schema allowed unexpected params: %s", invalidParam)
    32  		}
    33  	}
    34  }
    35  
    36  var validParams = []string{
    37  	`{"seller_id":"1", "host":"api-eu", "path":"auction/rtb/v2"}`,
    38  	`{"seller_id":"1", "host":"api-us", "path":"auction/rtb/v2"}`,
    39  }
    40  
    41  var invalidParams = []string{
    42  	``,
    43  	`null`,
    44  	`true`,
    45  	`5`,
    46  	`4.2`,
    47  	`[]`,
    48  	`{}`,
    49  	`{"some_random_field":""}`,
    50  	`{"seller_id":""}`,
    51  	`{"seller_id": 1}`,
    52  	`{"seller_id": 1.2}`,
    53  	`{"seller_id": null}`,
    54  	`{"seller_id": true}`,
    55  	`{"seller_id": []}`,
    56  	`{"seller_id": {}}`,
    57  	`{"host":""}`,
    58  	`{"host": 1}`,
    59  	`{"host": 1.2}`,
    60  	`{"host": null}`,
    61  	`{"host": true}`,
    62  	`{"host": []}`,
    63  	`{"host": {}}`,
    64  	`{"path":""}`,
    65  	`{"path": 1}`,
    66  	`{"path": 1.2}`,
    67  	`{"path": null}`,
    68  	`{"path": true}`,
    69  	`{"path": []}`,
    70  	`{"path": {}}`,
    71  	`{"seller_id":"", "path": "", host: ""}`,
    72  	`{"seller_id": 1, "path": 2, host: 3}`,
    73  	`{"seller_id": 1.2}, "path": 5.5, host: 3.3`,
    74  	`{"seller_id": null, "path": null, host: null}`,
    75  	`{"seller_id": true, "path": false, host: true}`,
    76  	`{"seller_id": [], "path": [], host: []}`,
    77  	`{"seller_id": {}, "path": {}, host: {}}`,
    78  }