forked from prebid/prebid-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopenrtb_util_test.go
117 lines (114 loc) · 3.05 KB
/
openrtb_util_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
package adapters
import (
"encoding/json"
"github.com/mxmCherry/openrtb/v15/openrtb2"
"reflect"
"testing"
)
func TestExtractAdapterReqBidderParams(t *testing.T) {
type args struct {
bidRequest *openrtb2.BidRequest
}
tests := []struct {
name string
args args
want map[string]json.RawMessage
wantErr bool
}{
{
name: "extract bidder params from nil req",
args: args{
bidRequest: nil,
},
want: nil,
wantErr: true,
},
{
name: "extract bidder params from nil req.Ext",
args: args{
bidRequest: &openrtb2.BidRequest{Ext: json.RawMessage(`{"prebid":{}}`)},
},
want: nil,
wantErr: false,
},
{
name: "extract bidder params from req.Ext for input request in adapter code",
args: args{
bidRequest: &openrtb2.BidRequest{Ext: json.RawMessage(`{"prebid":{"bidderparams": {"profile": 1234, "version": 1}}}`)},
},
want: map[string]json.RawMessage{"profile": json.RawMessage(`1234`), "version": json.RawMessage(`1`)},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := ExtractAdapterReqBidderParams(tt.args.bidRequest)
if (err != nil) != tt.wantErr {
t.Errorf("ExtractReqExtBidderParams() error = %v, wantErr = %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("ExtractReqExtBidderParams() got = %v, want = %v", got, tt.want)
}
})
}
}
func TestExtractReqExtBidderParams(t *testing.T) {
type args struct {
request *openrtb2.BidRequest
}
tests := []struct {
name string
args args
want map[string]map[string]json.RawMessage
wantErr bool
}{
{
name: "extract bidder params from nil req",
args: args{
request: nil,
},
want: nil,
wantErr: true,
},
{
name: "extract bidder params from nil req.Ext.prebid",
args: args{
request: &openrtb2.BidRequest{Ext: json.RawMessage(`{"prebid":{}}`)},
},
want: nil,
wantErr: false,
},
{
name: "extract bidder params from nil req.Ext",
args: args{
request: &openrtb2.BidRequest{Ext: nil},
},
want: nil,
wantErr: false,
},
{
name: "extract bidder params from req.Ext for input request before adapter code",
args: args{
request: &openrtb2.BidRequest{Ext: json.RawMessage(`{"prebid":{"bidderparams": {"pubmatic": {"profile": 1234, "version": 1}, "appnexus": {"key1": 123, "key2": {"innerKey1":"innerValue1"} } }}}`)},
},
want: map[string]map[string]json.RawMessage{
"pubmatic": {"profile": json.RawMessage(`1234`), "version": json.RawMessage(`1`)},
"appnexus": {"key1": json.RawMessage(`123`), "key2": json.RawMessage(`{"innerKey1":"innerValue1"}`)},
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := ExtractReqExtBidderParams(tt.args.request)
if (err != nil) != tt.wantErr {
t.Errorf("ExtractReqExtBidderParams() error = %v, wantErr = %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("ExtractReqExtBidderParams() got = %v, want = %v", got, tt.want)
}
})
}
}