-
Notifications
You must be signed in to change notification settings - Fork 937
Expand file tree
/
Copy pathparams_test.go
More file actions
65 lines (56 loc) · 2.4 KB
/
Copy pathparams_test.go
File metadata and controls
65 lines (56 loc) · 2.4 KB
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
55
56
57
58
59
60
61
62
63
64
65
package vdoai
import (
"encoding/json"
"testing"
"github.com/prebid/prebid-server/v4/openrtb_ext"
)
// This file tests static/bidder-params/vdoai.json
// These also validate the format of the external API: request.imp[i].ext.prebid.bidder.vdoai
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.BidderVdoai, json.RawMessage(validParam)); err != nil {
t.Errorf("Schema rejected vdoai params: %s", validParam)
}
}
}
func TestInvalidParams(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 _, invalidParam := range invalidParams {
if err := validator.Validate(openrtb_ext.BidderVdoai, json.RawMessage(invalidParam)); err == nil {
t.Errorf("Schema allowed unexpected params: %s", invalidParam)
}
}
}
var validParams = []string{
`{"adUnitId":123456,"adUnitType":"banner","host":"exchange.ortb.net","publisherId":"pub-abc"}`,
`{"adUnitId":123456,"adUnitType":"video","host":"ads.vdo.ai","publisherId":"pub-xyz"}`,
`{"adUnitId":123456,"adUnitType":"banner","host":"exchange.ortb.net","publisherId":"pub-abc","bidfloor":1.5}`,
`{"adUnitId":123456,"adUnitType":"banner","host":"exchange.ortb.net","publisherId":"pub-abc","custom1":"val1","custom2":"val2","custom3":"val3","custom4":"val4","custom5":"val5"}`,
`{"adUnitId":123456,"adUnitType":"video","host":"ads.vdo.ai","publisherId":"pub-xyz","bidfloor":2.0,"custom1":"c1"}`,
`{"adUnitId":"123456","adUnitType":"banner","host":"exchange.ortb.net","publisherId":"pub-abc"}`,
`{"adUnitId":"vdo-123456","adUnitType":"banner","host":"exchange.ortb.net","publisherId":"pub-abc"}`,
}
var invalidParams = []string{
``,
`null`,
`true`,
`5`,
`4.2`,
`[]`,
`{}`,
`{"adUnitId":"123456"}`,
`{"adUnitType":"banner"}`,
`{"adUnitId":123456,"adUnitType":"banner"}`,
`{"adUnitId":123456,"adUnitType":"video"}`,
`{"adUnitId":123456,"adUnitType":"banner","host":"exchange.ortb.net"}`,
`{"adUnitId":123456,"adUnitType":"banner","publisherId":"pub-abc"}`,
`{"adUnitId":"123456","adUnitType":"banner"}`,
`{"adUnitId":"123456","adUnitType":"banner","host":"exchange.ortb.net","publisherId":"pub-abc","bidfloor":"notanumber"}`,
}