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

     1  package smaato
     2  
     3  import (
     4  	"encoding/json"
     5  	"testing"
     6  
     7  	"github.com/prebid/prebid-server/v2/openrtb_ext"
     8  )
     9  
    10  // This file intends to test static/bidder-params/smaato.json
    11  
    12  // These also validate the format of the external API: request.imp[i].bidRequestExt.smaato
    13  
    14  // TestValidParams makes sure that the Smaato schema accepts all imp.bidRequestExt fields which Smaato supports.
    15  func TestValidParams(t *testing.T) {
    16  	validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params")
    17  	if err != nil {
    18  		t.Fatalf("Failed to fetch the json-schemas. %v", err)
    19  	}
    20  
    21  	for _, validParam := range validParams {
    22  		if err := validator.Validate(openrtb_ext.BidderSmaato, json.RawMessage(validParam)); err != nil {
    23  			t.Errorf("Schema rejected smaato params: %s \n Error: %s", validParam, err)
    24  		}
    25  	}
    26  }
    27  
    28  // TestInvalidParams makes sure that the Smaato schema rejects all the imp.bidRequestExt fields which are not support.
    29  func TestInvalidParams(t *testing.T) {
    30  	validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params")
    31  	if err != nil {
    32  		t.Fatalf("Failed to fetch the json-schemas. %v", err)
    33  	}
    34  
    35  	for _, invalidParam := range invalidParams {
    36  		if err := validator.Validate(openrtb_ext.BidderSmaato, json.RawMessage(invalidParam)); err == nil {
    37  			t.Errorf("Schema allowed unexpected params: %s", invalidParam)
    38  		}
    39  	}
    40  }
    41  
    42  var validParams = []string{
    43  	`{"publisherId":"test-id-1234-smaato","adspaceId": "1123581321"}`,
    44  	`{"publisherId":"test-id-1234-smaato","adbreakId": "4123581321"}`,
    45  	`{"publisherId":"test-id-1234-smaato","adspaceId": "1123581321","adbreakId": "4123581321"}`,
    46  }
    47  
    48  var invalidParams = []string{
    49  	``,
    50  	`null`,
    51  	`true`,
    52  	`5`,
    53  	`4.2`,
    54  	`[]`,
    55  	`{}`,
    56  	`{"publisherId":"test-id-1234-smaato"}`,
    57  	`{"adspaceId": "1123581321"}`,
    58  	`{"publisherId":false}`,
    59  	`{"adspaceId":false}`,
    60  	`{"publisherId":0,"adspaceId": 1123581321}`,
    61  	`{"publisherId":false,"adspaceId": true}`,
    62  	`{"instl": 0}`,
    63  	`{"secure": 0}`,
    64  	`{"adspaceId": "1123581321","instl": 0,"secure": 0}`,
    65  	`{"instl": 0,"secure": 0}`,
    66  	`{"publisherId":"test-id-1234-smaato","instl": 0,"secure": 0}`,
    67  }