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

     1  package amx
     2  
     3  import (
     4  	"encoding/json"
     5  	"testing"
     6  
     7  	"github.com/prebid/prebid-server/v2/openrtb_ext"
     8  	"github.com/stretchr/testify/assert"
     9  )
    10  
    11  var validBidParams = []string{
    12  	`{"tagId":"sampleTagId", "adUnitId": "sampleAdUnitId"}`,
    13  	`{"tagId":"sampleTagId", "adUnitId": ""}`,
    14  	`{"adUnitId": ""}`,
    15  	`{"adUnitId": "sampleAdUnitId"}`,
    16  	`{"tagId":"sampleTagId"}`,
    17  	`{"tagId":""}`,
    18  	`{}`,
    19  	`{"otherValue": "ignored"}`,
    20  	`{"tagId": "sampleTagId", "otherValue": "ignored"}`,
    21  	`{"otherValue": "ignored", "adUnitId": "sampleAdUnitId"}`,
    22  }
    23  
    24  var invalidBidParams = []string{
    25  	`{"tagId":1234}`,
    26  	`{"tagId": true}`,
    27  	`{"adUnitId": true}`,
    28  	`{"adUnitId": null}`,
    29  	`{"adUnitId": null, "tagId": "sampleTagId"}`,
    30  	`{"adUnitId": 1234, "tagId": "sampleTagId"}`,
    31  }
    32  
    33  func TestValidParams(t *testing.T) {
    34  	validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params")
    35  	assert.Nil(t, err)
    36  	for _, params := range validBidParams {
    37  		assert.Nil(t, validator.Validate(openrtb_ext.BidderAMX, json.RawMessage(params)))
    38  	}
    39  }
    40  
    41  func TestInValidParams(t *testing.T) {
    42  	validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params")
    43  	assert.Nil(t, err)
    44  	for _, params := range invalidBidParams {
    45  		assert.NotNil(t, validator.Validate(openrtb_ext.BidderAMX, json.RawMessage(params)))
    46  	}
    47  }