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

     1  package aidem
     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/aidem.json TODO: MUST BE CREATED
    11  func TestValidParams(t *testing.T) {
    12  	validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params")
    13  	if err != nil {
    14  		t.Fatalf("Failed to fetch the json-schemas. %v", err)
    15  	}
    16  
    17  	for _, validParam := range validParams {
    18  		if err := validator.Validate(openrtb_ext.BidderAidem, json.RawMessage(validParam)); err != nil {
    19  			t.Errorf("Schema rejected aidem params: %s", validParam)
    20  		}
    21  	}
    22  }
    23  
    24  func TestInvalidParams(t *testing.T) {
    25  	validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params")
    26  	if err != nil {
    27  		t.Fatalf("Failed to fetch the json-schemas. %v", err)
    28  	}
    29  
    30  	for _, invalidParam := range invalidParams {
    31  		if err := validator.Validate(openrtb_ext.BidderAidem, json.RawMessage(invalidParam)); err == nil {
    32  			t.Errorf("Schema allowed unexpected params: %s", invalidParam)
    33  		}
    34  	}
    35  }
    36  
    37  var validParams = []string{
    38  	`{"siteId":"123", "publisherId":"1234"}`,
    39  	`{"siteId":"123", "publisherId":"1234", "placementId":"12345"}`,
    40  	`{"siteId":"123", "publisherId":"1234", "rateLimit":1}`,
    41  	`{"siteId":"123", "publisherId":"1234", "placementId":"12345", "rateLimit":1}`,
    42  }
    43  
    44  var invalidParams = []string{
    45  	``,
    46  	`null`,
    47  	`true`,
    48  	`5`,
    49  	`4.2`,
    50  	`[]`,
    51  	`{}`,
    52  	`{"siteId":"", "publisherId":""}`,
    53  	`{"siteId":"only siteId is present"}`,
    54  	`{"publisherId":"only publisherId is present"}`,
    55  	`{"ssiteId":"123","ppublisherId":"123"}`,
    56  	`{"aid":123, "placementId":"123", "siteId":"321"}`,
    57  }