-
Notifications
You must be signed in to change notification settings - Fork 121
/
bidrequest_test.go
88 lines (82 loc) · 2.54 KB
/
bidrequest_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
package openrtb_test
import (
"errors"
"reflect"
"testing"
. "github.com/bsm/openrtb/v3"
)
func TestBidRequest(t *testing.T) {
var subject *BidRequest
if err := fixture("breq.banner", &subject); err != nil {
t.Fatalf("expected no error, got %v", err)
}
privacyPolicy := 1
exp := &BidRequest{
ID: "1234534625254",
Impressions: []Impression{
{
ID: "1",
Secure: 1,
Banner: &Banner{Width: 300, Height: 250, Position: AdPositionAboveFold, BlockedAttrs: []CreativeAttribute{CreativeAttributeUserInitiated}},
},
},
Site: &Site{
Inventory: Inventory{
ID: "234563",
Name: "Site ABCD",
Domain: "siteabcd.com",
Categories: []ContentCategory{ContentCategoryAutoParts, ContentCategoryAutoRepair},
Publisher: &Publisher{ID: "pub12345", Name: "Publisher A"},
PrivacyPolicy: &privacyPolicy,
Content: &Content{
Keywords: "keyword a,keyword b,keyword c",
},
},
Page: "http://siteabcd.com/page.htm",
Referrer: "http://referringsite.com/referringpage.htm",
},
Device: &Device{
UA: "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.16) Gecko/20110319 Firefox/3.6.16",
IP: "64.124.253.1",
OS: "OS X",
JS: 1,
FlashVersion: "10.1",
},
User: &User{
ID: "45asdf987656789adfad4678rew656789",
BuyerUID: "5df678asd8987656asdf78987654",
},
Test: 1,
AuctionType: 2,
TimeMax: 120,
BlockedAdvDomains: []string{"company1.com", "company2.com"},
}
if got := subject; !reflect.DeepEqual(exp, got) {
t.Errorf("expected %+v, got %+v", exp, got)
}
}
func TestBidRequest_complex(t *testing.T) {
for _, kind := range []string{"exp", "video", "native"} {
var subject *BidRequest
if err := fixture("breq."+kind, &subject); err != nil {
t.Fatalf("expected no error, got %v", err)
}
if err := subject.Validate(); err != nil {
t.Fatalf("expected no error, got %v", err)
}
}
}
func TestBidRequest_Validate(t *testing.T) {
subject := &BidRequest{}
if exp, got := ErrInvalidReqNoID, subject.Validate(); !errors.Is(exp, got) {
t.Fatalf("expected %v, got %v", exp, got)
}
subject = &BidRequest{ID: "RID"}
if exp, got := ErrInvalidReqNoImps, subject.Validate(); !errors.Is(exp, got) {
t.Fatalf("expected %v, got %v", exp, got)
}
subject = &BidRequest{ID: "A", Impressions: []Impression{{ID: "1"}}, Site: &Site{}, App: &App{}}
if exp, got := ErrInvalidReqMultiInv, subject.Validate(); !errors.Is(exp, got) {
t.Fatalf("expected %v, got %v", exp, got)
}
}