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

     1  package flipp
     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.BidderFlipp, 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.BidderFlipp, json.RawMessage(p)); err == nil {
    31  			t.Errorf("Schema allowed invalid params: %s", p)
    32  		}
    33  	}
    34  }
    35  
    36  var validParams = []string{
    37  	`{
    38  		"publisherNameIdentifier": "wishabi-test-publisher",
    39  		"creativeType": "NativeX",
    40  		"siteId": 1243066,
    41  		"zoneIds": [285431]
    42  	}`,
    43  	`{
    44  		"publisherNameIdentifier": "wishabi-test-publisher",
    45  		"creativeType": "NativeX",
    46  		"siteId": 1243066,
    47  		"options": {}
    48  	}`,
    49  	`{
    50  		"publisherNameIdentifier": "wishabi-test-publisher",
    51  		"creativeType": "NativeX",
    52  		"siteId": 1243066,
    53  		"zoneIds": [285431],
    54  		"options": {
    55  			"startCompact": true
    56  		}
    57  	}`,
    58  	`{
    59  		"publisherNameIdentifier": "wishabi-test-publisher",
    60  		"creativeType": "NativeX",
    61  		"siteId": 1243066,
    62  		"zoneIds": [285431],
    63  		"options": {
    64  			"startCompact": false,
    65  			"dwellExpand": true,
    66  			"contentCode": "test-code"
    67  		}
    68  	}`,
    69  	`{
    70  		"publisherNameIdentifier": "wishabi-test-publisher",
    71  		"creativeType": "NativeX",
    72  		"siteId": 1243066,
    73  		"zoneIds": [285431],
    74  		"ip": "123.123.123.123",
    75  		"options": {
    76  			"startCompact": false
    77  		}
    78  	}`,
    79  }
    80  
    81  var invalidParams = []string{
    82  	`{
    83  		"publisherNameIdentifier": "wishabi-test-publisher",
    84  		"creativeType": "NativeX",
    85  		"zoneIds": [285431]
    86  	}`,
    87  	`{
    88  		"publisherNameIdentifier": "wishabi-test-publisher",
    89  		"siteId": 1243066,
    90  		"zoneIds": [285431]
    91  	}`,
    92  	`{
    93  		"publisherNameIdentifier": "wishabi-test-publisher",
    94  		"creativeType": "abc",
    95  		"siteId": 1243066,
    96  		"zoneIds": [285431]
    97  	}`,
    98  	`{
    99  		"creativeType": "NativeX",
   100  		"siteId": 1243066,
   101  		"zoneIds": [285431]
   102  	}`,
   103  	`{
   104  		"publisherNameIdentifier": "wishabi-test-publisher",
   105  		"creativeType": "NativeX",
   106  		"siteId": "123abc",
   107  		"zoneIds": [285431]
   108  	}`,
   109  	`{
   110  		"publisherNameIdentifier": "wishabi-test-publisher",
   111  		"creativeType": "NativeX",
   112  		"siteId": 1243066,
   113  		"zoneIds": ["abc123"]
   114  	}`,
   115  	`{
   116  		"publisherNameIdentifier": "wishabi-test-publisher",
   117  		"siteId": 1243066,
   118  		"startCompact": "true"
   119  	}`,
   120  	`{
   121  		"publisherNameIdentifier": "wishabi-test-publisher",
   122  		"siteId": 1243066,
   123  		"options": {
   124  			"startCompact": "true"
   125  		}
   126  	}`,
   127  }