forked from prebid/prebid-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
info_test.go
144 lines (131 loc) · 4.84 KB
/
info_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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package adapters_test
import (
"errors"
"testing"
"github.com/mxmCherry/openrtb"
"github.com/prebid/prebid-server/adapters"
"github.com/prebid/prebid-server/openrtb_ext"
"github.com/stretchr/testify/assert"
)
func TestAppNotSupported(t *testing.T) {
bidder := &mockBidder{}
info := adapters.BidderInfo{
Capabilities: &adapters.CapabilitiesInfo{
Site: &adapters.PlatformInfo{
MediaTypes: []openrtb_ext.BidType{openrtb_ext.BidTypeBanner},
},
},
}
constrained := adapters.EnforceBidderInfo(bidder, info)
bids, errs := constrained.MakeRequests(&openrtb.BidRequest{
App: &openrtb.App{},
})
if !assert.Len(t, errs, 1) {
return
}
assert.EqualError(t, errs[0], "this bidder does not support app requests")
assert.IsType(t, &adapters.BadInputError{}, errs[0])
assert.Len(t, bids, 0)
}
func TestSiteNotSupported(t *testing.T) {
bidder := &mockBidder{}
info := adapters.BidderInfo{
Capabilities: &adapters.CapabilitiesInfo{
App: &adapters.PlatformInfo{
MediaTypes: []openrtb_ext.BidType{openrtb_ext.BidTypeBanner},
},
},
}
constrained := adapters.EnforceBidderInfo(bidder, info)
bids, errs := constrained.MakeRequests(&openrtb.BidRequest{
Site: &openrtb.Site{},
})
if !assert.Len(t, errs, 1) {
return
}
assert.EqualError(t, errs[0], "this bidder does not support site requests")
assert.IsType(t, &adapters.BadInputError{}, errs[0])
assert.Len(t, bids, 0)
}
func TestImpFiltering(t *testing.T) {
bidder := &mockBidder{}
info := adapters.BidderInfo{
Capabilities: &adapters.CapabilitiesInfo{
Site: &adapters.PlatformInfo{
MediaTypes: []openrtb_ext.BidType{openrtb_ext.BidTypeVideo},
},
App: &adapters.PlatformInfo{
MediaTypes: []openrtb_ext.BidType{openrtb_ext.BidTypeBanner},
},
},
}
constrained := adapters.EnforceBidderInfo(bidder, info)
_, errs := constrained.MakeRequests(&openrtb.BidRequest{
Imp: []openrtb.Imp{
{
ID: "imp-1",
Video: &openrtb.Video{},
},
{
Native: &openrtb.Native{},
},
{
ID: "imp-2",
Video: &openrtb.Video{},
Native: &openrtb.Native{},
},
{
Banner: &openrtb.Banner{},
},
},
Site: &openrtb.Site{},
})
if !assert.Len(t, errs, 6) {
return
}
assert.EqualError(t, errs[0], "request.imp[1] uses native, but this bidder doesn't support it")
assert.EqualError(t, errs[1], "request.imp[2] uses native, but this bidder doesn't support it")
assert.EqualError(t, errs[2], "request.imp[3] uses banner, but this bidder doesn't support it")
assert.EqualError(t, errs[3], "request.imp[1] has no supported MediaTypes. It will be ignored")
assert.EqualError(t, errs[4], "request.imp[3] has no supported MediaTypes. It will be ignored")
assert.EqualError(t, errs[5], "mock MakeRequests error")
assert.IsType(t, &adapters.BadInputError{}, errs[0])
assert.IsType(t, &adapters.BadInputError{}, errs[1])
assert.IsType(t, &adapters.BadInputError{}, errs[2])
assert.IsType(t, &adapters.BadInputError{}, errs[3])
assert.IsType(t, &adapters.BadInputError{}, errs[4])
req := bidder.gotRequest
if !assert.Len(t, req.Imp, 2) {
return
}
assert.Equal(t, "imp-1", req.Imp[0].ID)
assert.Equal(t, "imp-2", req.Imp[1].ID)
assert.Nil(t, req.Imp[1].Native)
}
type mockBidder struct {
gotRequest *openrtb.BidRequest
}
func (m *mockBidder) MakeRequests(request *openrtb.BidRequest) ([]*adapters.RequestData, []error) {
m.gotRequest = request
return nil, []error{errors.New("mock MakeRequests error")}
}
func (m *mockBidder) MakeBids(internalRequest *openrtb.BidRequest, externalRequest *adapters.RequestData, response *adapters.ResponseData) (*adapters.BidderResponse, []error) {
return nil, []error{errors.New("mock MakeBids error")}
}
func TestParsing(t *testing.T) {
mockBidderName := openrtb_ext.BidderName("someBidder")
infos := adapters.ParseBidderInfos("./adapterstest/bidder-info", []openrtb_ext.BidderName{mockBidderName})
if infos[string(mockBidderName)].Maintainer.Email != "[email protected]" {
t.Errorf("Bad maintainer email. Got %s", infos[string(mockBidderName)].Maintainer.Email)
}
assert.Equal(t, true, infos.HasAppSupport(mockBidderName))
assert.Equal(t, true, infos.HasSiteSupport(mockBidderName))
assert.Equal(t, true, infos.SupportsAppMediaType(mockBidderName, openrtb_ext.BidTypeBanner))
assert.Equal(t, false, infos.SupportsAppMediaType(mockBidderName, openrtb_ext.BidTypeVideo))
assert.Equal(t, false, infos.SupportsAppMediaType(mockBidderName, openrtb_ext.BidTypeAudio))
assert.Equal(t, true, infos.SupportsAppMediaType(mockBidderName, openrtb_ext.BidTypeNative))
assert.Equal(t, true, infos.SupportsWebMediaType(mockBidderName, openrtb_ext.BidTypeBanner))
assert.Equal(t, true, infos.SupportsWebMediaType(mockBidderName, openrtb_ext.BidTypeVideo))
assert.Equal(t, false, infos.SupportsWebMediaType(mockBidderName, openrtb_ext.BidTypeAudio))
assert.Equal(t, true, infos.SupportsWebMediaType(mockBidderName, openrtb_ext.BidTypeNative))
}