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

     1  package pubmatic
     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/pubmatic.json
    11  //
    12  // These also validate the format of the external API: request.imp[i].ext.prebid.bidder.pubmatic
    13  
    14  // TestValidParams makes sure that the pubmatic schema accepts all imp.ext fields which we intend to support.
    15  func TestValidParams(t *testing.T) {
    16  	validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params")
    17  	if err != nil {
    18  		t.Fatalf("Failed to fetch the json-schemas. %v", err)
    19  	}
    20  
    21  	for _, validParam := range validParams {
    22  		if err := validator.Validate(openrtb_ext.BidderPubmatic, json.RawMessage(validParam)); err != nil {
    23  			t.Errorf("Schema rejected pubmatic params: %s \n Error: %s", validParam, err)
    24  		}
    25  	}
    26  }
    27  
    28  // TestInvalidParams makes sure that the pubmatic schema rejects all the imp.ext fields we don't support.
    29  func TestInvalidParams(t *testing.T) {
    30  	validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params")
    31  	if err != nil {
    32  		t.Fatalf("Failed to fetch the json-schemas. %v", err)
    33  	}
    34  
    35  	for _, invalidParam := range invalidParams {
    36  		if err := validator.Validate(openrtb_ext.BidderPubmatic, json.RawMessage(invalidParam)); err == nil {
    37  			t.Errorf("Schema allowed unexpected params: %s", invalidParam)
    38  		}
    39  	}
    40  }
    41  
    42  var validParams = []string{
    43  	`{"publisherId":"7890"}`,
    44  	`{"adSlot":"","publisherId":"7890"}`,
    45  	`{"adSlot":"AdTag_Div1","publisherId":"7890"}`,
    46  	`{"adSlot":"AdTag_Div1@728x90","publisherId":"7890"}`,
    47  	`{"adSlot":"AdTag_Div1@728x90","publisherId":"7890","keywords":[{"key": "pmZoneID", "value":["zone1"]},{"key": "dctr", "value":[ "v1","v2"]}]}`,
    48  	`{"adSlot":"AdTag_Div1@728x90","publisherId":"7890","keywords":[{"key": "pmZoneID", "value":["zone1", "zone2"]}], "wrapper":{"profile":5123}}`,
    49  }
    50  
    51  var invalidParams = []string{
    52  	``,
    53  	`null`,
    54  	`true`,
    55  	`5`,
    56  	`4.2`,
    57  	`[]`,
    58  	`{}`,
    59  	`{"adSlot":"AdTag_Div1@728x90:0"}`,
    60  	`{"adSlot":"AdTag_Div1@728x90:0","publisherId":1}`,
    61  	`{"adSlot":123,"publisherId":"7890"}`,
    62  	`{"adSlot":123,"publisherId":7890}`,
    63  	`{"adSlot":"AdTag_Div1@728x90","publisherId":"7890", "keywords":[]}`,
    64  	`{"adSlot":"AdTag_Div1@728x90","publisherId":"7890", "keywords":["foo"]}`,
    65  	`{"adSlot":"AdTag_Div1@728x90","publisherId":"7890", "keywords":[{"key": "foo", "value":[]}]}`,
    66  	`{"adSlot":"AdTag_Div1@728x90","publisherId":"7890", "keywords":[{"key": "foo"}]}`,
    67  	`{"adSlot":"AdTag_Div1@728x90","publisherId":"7890", "keywords":[{"value":[]}]}`,
    68  	`{"adSlot":"AdTag_Div1@728x90","publisherId":"7890", "wrapper":{}}`,
    69  	`{"adSlot":"AdTag_Div1@728x90","publisherId":"7890", "wrapper":{"version":"1","profile":5123}}`,
    70  	`{"adSlot":"AdTag_Div1@728x90","publisherId":"7890", "wrapper":{"version":"1"}}`,
    71  	`{"adSlot":"AdTag_Div1@728x90","publisherId":"7890","keywords":[{"key": "pmZoneID", "value":["1"]}], "wrapper":{"version":1,"profile":"5123"}}`,
    72  }