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

     1  package algorix
     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.BidderAlgorix, json.RawMessage(validParam)); err != nil {
    18  			t.Errorf("Schema rejected algoirx params: %s", validParam)
    19  		}
    20  	}
    21  }
    22  
    23  // TestInvalidParams makes sure that the algorix schema rejects all the imp.ext fields we don't support.
    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.BidderAlgorix, json.RawMessage(invalidParam)); err == nil {
    32  			t.Errorf("Schema allowed unexpected params: %s", invalidParam)
    33  		}
    34  	}
    35  }
    36  
    37  var validParams = []string{
    38  	`{"sid": "11233", "token": "sin", "placementId": "123", "appId": "abc"}`,
    39  	`{"sid": "11244", "token": "iad"}`,
    40  	`{"sid": "11244", "token": "iad", "region": "APAC"}`,
    41  	`{"sid": "11244", "token": "iad", "region": "USE"}`,
    42  	`{"sid": "11244", "token": "iad", "region": "EUC"}`,
    43  }
    44  
    45  var invalidParams = []string{
    46  	`{"sid": "11233"}`,
    47  	`{"token": "aaa"}`,
    48  	`{"sid": 123, "token": "sin"}`,
    49  	`{"sid": "", "token": "iad"}`,
    50  	`{"sid": "11233", "token": ""}`,
    51  	`{"sid": "11233", "token": "sin", "placementId": 123, "appId": "abc"}`,
    52  	`{"sid": "11233", "token": "sin", "placementId": "123", "appId": 456}`,
    53  	`{"sid": "11233", "token": "sin", "placementId": 123, "appId": 456}`,
    54  	`{"sid": "11233", "token": "sin", "region": 123}`,
    55  }