github.com/prebid/prebid-server/v2@v2.18.0/adapters/liftoff/param_test.go (about) 1 package liftoff 2 3 import ( 4 "encoding/json" 5 "testing" 6 7 "github.com/prebid/prebid-server/v2/openrtb_ext" 8 ) 9 10 var validParams = []string{ 11 `{"app_store_id": "12345", "placement_reference_id": "12345"}`, 12 } 13 14 var invalidParams = []string{ 15 `{}`, 16 // placement_reference_id 17 `{"placement_reference_id": "12345"}`, 18 `{"app_store_id": "12345"}`, 19 `{"app_store_id": null, "placement_reference_id": null}`, 20 } 21 22 func TestValidParams(t *testing.T) { 23 validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params") 24 if err != nil { 25 t.Fatalf("Failed to fetch the json schema. %v", err) 26 } 27 28 for _, p := range validParams { 29 if err := validator.Validate(openrtb_ext.BidderLiftoff, json.RawMessage(p)); err != nil { 30 t.Errorf("Schema rejected valid params: %s", p) 31 } 32 } 33 } 34 35 func TestInvalidParams(t *testing.T) { 36 validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params") 37 if err != nil { 38 t.Fatalf("Failed to fetch the json schema. %v", err) 39 } 40 41 for _, p := range invalidParams { 42 if err := validator.Validate(openrtb_ext.BidderLiftoff, json.RawMessage(p)); err == nil { 43 t.Errorf("Schema allowed invalid params: %s", p) 44 } 45 } 46 }