github.com/prebid/prebid-server@v0.275.0/adapters/taboola/params_test.go (about)

     1  package taboola
     2  
     3  import (
     4  	"encoding/json"
     5  	"github.com/prebid/prebid-server/openrtb_ext"
     6  	"testing"
     7  )
     8  
     9  func TestValidParams(t *testing.T) {
    10  	validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params")
    11  	if err != nil {
    12  		t.Fatalf("Failed to fetch the json schema. %v", err)
    13  	}
    14  
    15  	for _, p := range validParams {
    16  		if err := validator.Validate(openrtb_ext.BidderTaboola, json.RawMessage(p)); err != nil {
    17  			t.Errorf("Schema rejected valid params: %s", p)
    18  		}
    19  	}
    20  }
    21  
    22  func TestInvalidParams(t *testing.T) {
    23  	validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params")
    24  	if err != nil {
    25  		t.Fatalf("Failed to fetch the json schema. %v", err)
    26  	}
    27  
    28  	for _, p := range invalidParams {
    29  		if err := validator.Validate(openrtb_ext.BidderTaboola, json.RawMessage(p)); err == nil {
    30  			t.Errorf("Schema allowed invalid params: %s", p)
    31  		}
    32  	}
    33  }
    34  
    35  var validParams = []string{
    36  	`{"publisherId" : "1", "tagid": "tag-id-for-example"}`,
    37  	`{"publisherId" : "1", "tagId": "tag-id-for-example"}`,
    38  	`{"publisherId" : "1", "tagid": "tag-id-for-example","position":1}`,
    39  	`{"publisherId" : "1", "tagid": "tag-id-for-example","pageType":"pageType"}`,
    40  	`{"publisherId" : "1", "tagid": "tag-id-for-example", "bcat": ["excluded-category"], "badv": ["excluded-advertiser"], "bidfloor": 1.2, "publisherDomain": "http://domain.com"}`,
    41  }
    42  
    43  var invalidParams = []string{
    44  	`{}`,
    45  	`{"tagId" : "1"}`,
    46  	`{"publisherId" : "1", "bcat": ["excluded-category"], "badv": ["excluded-advertiser"], "bidfloor": 1.2, "publisherDomain": "http://domain.com"}`,
    47  	`{"publisherId" : 1, "tagid": "tag-id-for-example"}`,
    48  	`{"publisherId" : "1"", "tagid": 2}`,
    49  	`{"publisherId" : "1", "tagid": "tag-id-for-example", "bcat":"incorrect-type"}`,
    50  	`{"publisherId" : "1", "tagid": "tag-id-for-example", "badv":"incorrect-type"}`,
    51  	`{"publisherId" : "1", "tagid": "tag-id-for-example", "bidfloor":"incorrect-type"}`,
    52  	`{"publisherId" : "1", "tagid": "tag-id-for-example", "publisherDomain":1}`,
    53  	`{"tagid": "tag-id-for-example", "bcat": ["excluded-category"], "badv": ["excluded-advertiser"], "bidfloor": 1.2, "publisherDomain": "http://domain.com"}`,
    54  	`{"publisherId" : "1", "tagid": "tag-id-for-example","position":null}`,
    55  	`{"publisherId" : "1", "tagid": "tag-id-for-example","position":"1"}`,
    56  	`{"publisherId" : "1", "tagid": "tag-id-for-example","pageType":1}`,
    57  	`{"publisherId" : "1", "tagid": "tag-id-for-example","pageType":null}`,
    58  }