forked from prebid/prebid-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparams_test.go
54 lines (48 loc) · 1.96 KB
/
params_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package dmx
import (
"encoding/json"
"testing"
"github.com/prebid/prebid-server/v3/openrtb_ext"
)
func TestValidParams(t *testing.T) {
validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params")
if err != nil {
t.Fatalf("Failed to fetch the json-schemas. %v", err)
}
for _, validParam := range validParams {
if err := validator.Validate(openrtb_ext.BidderDmx, json.RawMessage(validParam)); err != nil {
t.Errorf("Schema rejected dmx params: %s", validParam)
}
}
for _, invalidParam := range invalidParams {
if err := validator.Validate(openrtb_ext.BidderDmx, json.RawMessage(invalidParam)); err == nil {
t.Errorf("Schema was not supposed to be valid: %s", invalidParam)
}
}
}
var validParams = []string{
`{"memberid": "anyMemberId", "placement_id":"anyPlacementId", "seller_id":"anySellerId", "dmxid":"anyDmxid", "tagid": "25251", "bidfloor": 0.01}`,
`{"memberid": "anyMemberId", "seller_id": "anySellerId", "dmxid": "anyDmxid", "tagid": "25251", "bidfloor": 0.01}`,
`{"memberid": "anyMemberId", "placement_id": "anyPlacementId", "dmxid": "anyDmxid", "tagid": "25251", "bidfloor": 0.01}`,
`{"memberid": "anyMemberId", "placement_id": "anyPlacementId", "seller_id": "anySellerId", "tagid": "25251", "bidfloor": 0.01}`,
`{"memberid": "anyMemberId", "placement_id": "anyPlacementId", "seller_id": "anySellerId", "dmxid": "anyDmxid", "bidfloor": 0.01}`,
`{"memberid": "anyMemberId", "placement_id": "anyPlacementId", "seller_id": "anySellerId", "dmxid": "anyDmxid", "tagid": "25251"}`,
`{"memberid": "anyMemberId"}`,
}
var invalidParams = []string{
`null`,
`nil`,
``,
`[]`,
`true`,
`{}`,
// Invalid because missing "memberid"
`{"placement_id":"anyPlacementId", "seller_id":"anySellerId", "dmxid":"anyDmxid", "tagid": "25251", "bidfloor": 0.01}`,
// Invalid because "memberid" not a string
`{"memberid": 5}`,
// Invalid since dmxid need to be a string
`{"memberid": "1222", "dmxid": 432423}`,
//
// ...more invalid param scenarios
//
}