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

     1  package kidoz
     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.BidderKidoz, json.RawMessage(validParam)); err != nil {
    18  			t.Errorf("Schema rejected kidoz params: %s \n Error: %s", validParam, err)
    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-schemas. %v", err)
    27  	}
    28  
    29  	for _, invalidParam := range invalidParams {
    30  		if err := validator.Validate(openrtb_ext.BidderKidoz, json.RawMessage(invalidParam)); err == nil {
    31  			t.Errorf("Schema allowed unexpected params: %s", invalidParam)
    32  		}
    33  	}
    34  }
    35  
    36  var validParams = []string{
    37  	`{"publisher_id":"pub-valid-0", "access_token":"token-valid-0"}`,
    38  }
    39  
    40  var invalidParams = []string{
    41  	``,
    42  	`null`,
    43  	`true`,
    44  	`5`,
    45  	`4.2`,
    46  	`[]`,
    47  	`{}`,
    48  	`{"some_random_field":""}`,
    49  	`{"publisher_id":""}`,
    50  	`{"publisher_id": 1}`,
    51  	`{"publisher_id": 1.2}`,
    52  	`{"publisher_id": null}`,
    53  	`{"publisher_id": true}`,
    54  	`{"publisher_id": []}`,
    55  	`{"publisher_id": {}}`,
    56  	`{"publisher_id":"", "access_token":"token-valid-0"}`,
    57  	`{"publisher_id": 1, "access_token":"token-valid-0"}`,
    58  	`{"publisher_id": 1.2, "access_token":"token-valid-0"}`,
    59  	`{"publisher_id": null, "access_token":"token-valid-0"}`,
    60  	`{"publisher_id": true, "access_token":"token-valid-0"}`,
    61  	`{"publisher_id": [], "access_token":"token-valid-0"}`,
    62  	`{"publisher_id": {}, "access_token":"token-valid-0"}`,
    63  	`{"access_token":""}`,
    64  	`{"access_token": 1}`,
    65  	`{"access_token": 1.2}`,
    66  	`{"access_token": null}`,
    67  	`{"access_token": true}`,
    68  	`{"access_token": []}`,
    69  	`{"access_token": {}}`,
    70  	`{"access_token":"", "publisher_id":"pub-valid-0"}`,
    71  	`{"access_token": 1, "publisher_id":"pub-valid-0"}`,
    72  	`{"access_token": 1.2, "publisher_id":"pub-valid-0"}`,
    73  	`{"access_token": null, "publisher_id":"pub-valid-0"}`,
    74  	`{"access_token": true, "publisher_id":"pub-valid-0"}`,
    75  	`{"access_token": [], "publisher_id":"pub-valid-0"}`,
    76  	`{"access_token": {}, "publisher_id":"pub-valid-0"}`,
    77  	`{"access_token": 1, "publisher_id":"pub-valid-0"}`,
    78  	`{"access_token":"token-valid-0", "publisher_id": 1}`,
    79  }