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

     1  package vox
     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 schema. %v", err)
    14  	}
    15  
    16  	for _, p := range validParams {
    17  		if err := validator.Validate(openrtb_ext.BidderVox, json.RawMessage(p)); err != nil {
    18  			t.Errorf("Schema rejected valid params: %s", p)
    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 schema. %v", err)
    27  	}
    28  
    29  	for _, p := range invalidParams {
    30  		if err := validator.Validate(openrtb_ext.BidderVox, json.RawMessage(p)); err == nil {
    31  			t.Errorf("Schema allowed invalid params: %s", p)
    32  		}
    33  	}
    34  }
    35  
    36  var validParams = []string{
    37  	`{"placementId": "64be6fe6685a271d37e900d2"}`,
    38  	`{"placementId": "Any String Basically"}`,
    39  	`{"placementId":""}`,
    40  	`{"placementId":"id", "imageUrl":"http://site.com/img1.png"}`,
    41  	`{"placementId":"id", "imageUrl":"http://site.com/img1.png", "displaySizes":["123x90", "1x1", "987x1111"]}`,
    42  }
    43  
    44  var invalidParams = []string{
    45  	`{"placementId": 42}`,
    46  	`{"placementId": null}`,
    47  	`{"placementId": 3.1415}`,
    48  	`{"placementId": true}`,
    49  	`{"placementId": false}`,
    50  	`{"placementId":"id", "imageUrl": null}`,
    51  	`{"placementId":"id", "imageUrl": true}`,
    52  	`{"placementId":"id", "imageUrl": []}`,
    53  	`{"placementId":"id", "imageUrl": "http://some.url", "displaySizes": null}`,
    54  	`{"placementId":"id", "imageUrl": "http://some.url", "displaySizes": {}}`,
    55  	`{"placementId":"id", "imageUrl": "http://some.url", "displaySizes": "String"}`,
    56  }