forked from prebid/prebid-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbidders_test.go
123 lines (113 loc) · 2.88 KB
/
bidders_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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package openrtb_ext
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/assert"
"github.com/xeipuuv/gojsonschema"
)
func TestBidderParamValidatorValidate(t *testing.T) {
testSchemaLoader := gojsonschema.NewStringLoader(`{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Test Params",
"description": "Test Description",
"type": "object",
"properties": {
"placementId": {
"type": "integer",
"description": "An ID which identifies this placement of the impression."
},
"optionalText": {
"type": "string",
"description": "Optional text for testing."
}
},
"required": ["placementId"]
}`)
testSchema, err := gojsonschema.NewSchema(testSchemaLoader)
if !assert.NoError(t, err) {
t.FailNow()
}
testBidderName := BidderName("foo")
testValidator := bidderParamValidator{
parsedSchemas: map[BidderName]*gojsonschema.Schema{
testBidderName: testSchema,
},
}
testCases := []struct {
description string
ext json.RawMessage
expectedError string
}{
{
description: "Valid",
ext: json.RawMessage(`{"placementId":123}`),
expectedError: "",
},
{
description: "Invalid - Wrong Type",
ext: json.RawMessage(`{"placementId":"stringInsteadOfInt"}`),
expectedError: "placementId: Invalid type. Expected: integer, given: string",
},
{
description: "Invalid - Empty Object",
ext: json.RawMessage(`{}`),
expectedError: "placementId: placementId is required",
},
{
description: "Malformed",
ext: json.RawMessage(`malformedJSON`),
expectedError: "invalid character 'm' looking for beginning of value",
},
}
for _, test := range testCases {
err := testValidator.Validate(testBidderName, test.ext)
if test.expectedError == "" {
assert.NoError(t, err, test.description)
} else {
assert.EqualError(t, err, test.expectedError, test.description)
}
}
}
func TestBidderParamValidatorSchema(t *testing.T) {
testValidator := bidderParamValidator{
schemaContents: map[BidderName]string{
BidderName("foo"): "foo content",
BidderName("bar"): "bar content",
},
}
result := testValidator.Schema(BidderName("bar"))
assert.Equal(t, "bar content", result)
}
func TestIsBidderNameReserved(t *testing.T) {
testCases := []struct {
bidder string
expected bool
}{
{"all", true},
{"aLl", true},
{"ALL", true},
{"context", true},
{"CONTEXT", true},
{"conTExt", true},
{"data", true},
{"DATA", true},
{"DaTa", true},
{"general", true},
{"gEnErAl", true},
{"GENERAL", true},
{"skadn", true},
{"skADN", true},
{"SKADN", true},
{"prebid", true},
{"PREbid", true},
{"PREBID", true},
{"bidder", true},
{"BIDDER", true},
{"BidDer", true},
{"notreserved", false},
}
for _, test := range testCases {
result := IsBidderNameReserved(test.bidder)
assert.Equal(t, test.expected, result, test.bidder)
}
}