|
| 1 | +package iqiyi |
| 2 | + |
| 3 | +import ( |
| 4 | + "encoding/json" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/prebid/prebid-server/v3/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.BidderIqiyi, json.RawMessage(validParam)); err != nil { |
| 18 | + t.Errorf("Schema rejected iqiyi 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.BidderIqiyi, json.RawMessage(invalidParam)); err == nil { |
| 31 | + t.Errorf("Schema allowed unexpected params: %s", invalidParam) |
| 32 | + } |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +var validParams = []string{ |
| 37 | + `{"accountid":"123"}`, |
| 38 | + `{"accountid":"test-account-id"}`, |
| 39 | + `{"accountid":"a"}`, |
| 40 | + `{"accountid":"account-id-with-dashes"}`, |
| 41 | + `{"accountid":"account_id_with_underscores"}`, |
| 42 | + `{"accountid":"AccountID123"}`, |
| 43 | +} |
| 44 | + |
| 45 | +var invalidParams = []string{ |
| 46 | + ``, |
| 47 | + `null`, |
| 48 | + `true`, |
| 49 | + `false`, |
| 50 | + `5`, |
| 51 | + `4.2`, |
| 52 | + `[]`, |
| 53 | + `{}`, |
| 54 | + `{"accountid":""}`, |
| 55 | + `{"accountid":123}`, |
| 56 | + `{"accountid":null}`, |
| 57 | + `{"accountid":true}`, |
| 58 | + `{"accountid":[]}`, |
| 59 | + `{"accountid":{}}`, |
| 60 | + `{"accountId":"123"}`, |
| 61 | + `{"AccountID":"123"}`, |
| 62 | + `{"account_id":"123"}`, |
| 63 | +} |
| 64 | + |
0 commit comments