Skip to content

Commit 8202caf

Browse files
author
zhoubing01
committed
add params_test.go and optimize code
1 parent 0164a55 commit 8202caf

File tree

2 files changed

+67
-2
lines changed

2 files changed

+67
-2
lines changed

adapters/iqiyi/iqiyi.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,9 @@ func (a *adapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapters.E
7979
for i := range requestCopy.Imp {
8080
imp := &requestCopy.Imp[i]
8181
if imp.Banner != nil {
82-
bannerCopy := *imp.Banner
83-
if (bannerCopy.W == nil || bannerCopy.H == nil || *bannerCopy.W == minBannerSize || *bannerCopy.H == minBannerSize) && len(bannerCopy.Format) > defaultBannerFormatIndex {
82+
banner := imp.Banner
83+
if (banner.W == nil || banner.H == nil || *banner.W == minBannerSize || *banner.H == minBannerSize) && len(banner.Format) > defaultBannerFormatIndex {
84+
bannerCopy := *banner
8485
first := bannerCopy.Format[defaultBannerFormatIndex]
8586
bannerCopy.W = &first.W
8687
bannerCopy.H = &first.H

adapters/iqiyi/params_test.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package iqiyi
2+
3+
import (
4+
"encoding/json"
5+
"testing"
6+
7+
"github.com/prebid/prebid-server/v3/openrtb_ext"
8+
)
9+
10+
func TestValidParams(t *testing.T) {
11+
validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params")
12+
if err != nil {
13+
t.Fatalf("Failed to fetch the json-schemas. %v", err)
14+
}
15+
16+
for _, validParam := range validParams {
17+
if err := validator.Validate(openrtb_ext.BidderIqiyi, json.RawMessage(validParam)); err != nil {
18+
t.Errorf("Schema rejected iqiyi params: %s \n Error: %s", validParam, err)
19+
}
20+
}
21+
}
22+
23+
func TestInvalidParams(t *testing.T) {
24+
validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params")
25+
if err != nil {
26+
t.Fatalf("Failed to fetch the json-schemas. %v", err)
27+
}
28+
29+
for _, invalidParam := range invalidParams {
30+
if err := validator.Validate(openrtb_ext.BidderIqiyi, json.RawMessage(invalidParam)); err == nil {
31+
t.Errorf("Schema allowed unexpected params: %s", invalidParam)
32+
}
33+
}
34+
}
35+
36+
var validParams = []string{
37+
`{"accountid":"123"}`,
38+
`{"accountid":"test-account-id"}`,
39+
`{"accountid":"a"}`,
40+
`{"accountid":"account-id-with-dashes"}`,
41+
`{"accountid":"account_id_with_underscores"}`,
42+
`{"accountid":"AccountID123"}`,
43+
}
44+
45+
var invalidParams = []string{
46+
``,
47+
`null`,
48+
`true`,
49+
`false`,
50+
`5`,
51+
`4.2`,
52+
`[]`,
53+
`{}`,
54+
`{"accountid":""}`,
55+
`{"accountid":123}`,
56+
`{"accountid":null}`,
57+
`{"accountid":true}`,
58+
`{"accountid":[]}`,
59+
`{"accountid":{}}`,
60+
`{"accountId":"123"}`,
61+
`{"AccountID":"123"}`,
62+
`{"account_id":"123"}`,
63+
}
64+

0 commit comments

Comments
 (0)