github.com/prebid/prebid-server/v2@v2.18.0/adapters/unicorn/params_test.go (about) 1 package unicorn 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.BidderUnicorn, 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.BidderUnicorn, json.RawMessage(p)); err == nil { 31 t.Errorf("Schema allowed invalid params: %s", p) 32 } 33 } 34 } 35 36 var validParams = []string{ 37 `{ 38 "accountId": 12345, 39 "publisherId": "123456", 40 "mediaId": "test_media", 41 "placementId": "test_placement" 42 }`, 43 `{ 44 "accountId": 12345, 45 "publisherId": "123456-pub", 46 "mediaId": "test_media", 47 "placementId": "test_placement" 48 }`, 49 `{ 50 "accountId": 12345, 51 "publisherId": "12341234123412341234", 52 "mediaId": "test_media", 53 "placementId": "test_placement" 54 }`, 55 `{ 56 "accountId": 12345, 57 "mediaId": "test_media" 58 }`, 59 `{ 60 "accountId": 12345 61 }`, 62 } 63 64 var invalidParams = []string{ 65 `{}`, 66 `{ 67 "accountId": "12345", 68 "publisherId": "123456", 69 "mediaId": 12345, 70 "placementId": 12345 71 }`, 72 `{ 73 "accountId": 12345, 74 "publisherId": 12341234123412341234, 75 "mediaId": "test_media", 76 "placementId": "test_placement" 77 }`, 78 `{ 79 "publisherId": 123456, 80 "placementId": "test_placement" 81 }`, 82 }