Skip to content

Commit

Permalink
UOE-11749: incorporating review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
pm-viral-vala committed Jan 7, 2025
1 parent fcfc666 commit cb5bfb7
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 33 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ require (
git.pubmatic.com/PubMatic/go-netacuity-client v0.0.0-20240104092757-5d6f15e25fe3
git.pubmatic.com/vastunwrap v0.0.0-00010101000000-000000000000
github.com/PubMatic-OpenWrap/fastxml v0.0.0-20241125102315-0d8f851a6e52
github.com/beevik/etree/110 v0.0.0-00010101000000-000000000000
github.com/diegoholiveira/jsonlogic/v3 v3.5.3
github.com/go-sql-driver/mysql v1.7.1
github.com/golang/mock v1.6.0
Expand Down Expand Up @@ -89,6 +88,7 @@ require (
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect
github.com/yudai/pp v2.0.1+incompatible // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/sys v0.18.0 // indirect
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ github.com/yudai/gojsondiff v1.0.0/go.mod h1:AY32+k2cwILAkW1fbgxQ5mUmMiZFgLIV+FB
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 h1:BHyfKlQyqbsFN5p3IfnEUduWvb9is428/nNb5L3U01M=
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82/go.mod h1:lgjkn3NuSvDfVJdfcVVdX+jpBxNmX4rDAzaS45IcYoM=
github.com/yudai/pp v2.0.1+incompatible h1:Q4//iY4pNF6yPLZIigmvcl7k/bPgrcTPIFIcmawg5bI=
github.com/yudai/pp v2.0.1+incompatible/go.mod h1:PuxR/8QJ7cyCkFp/aUDS+JY727OFEZkTdatxwunjIkc=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down
12 changes: 5 additions & 7 deletions modules/pubmatic/openwrap/adapters/bidders.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,23 +380,21 @@ func builderBeachfront(params BidderParameters) (json.RawMessage, error) {
func builderSmaato(params BidderParameters) (json.RawMessage, error) {
jsonStr := bytes.Buffer{}
jsonStr.WriteByte('{')
var fields []string

if publisherID, ok := getString(params.FieldMap["publisherId"]); !ok {
publisherID, ok := getString(params.FieldMap["publisherId"])
if !ok {
return nil, fmt.Errorf(errMandatoryParameterMissingFormat, params.AdapterName, "publisherId")
} else {
fields = append(fields, fmt.Sprintf(`"publisherId":"%s"`, publisherID))
}
fmt.Fprintf(&jsonStr, `"publisherId":"%s"`, publisherID)

if adspaceID, ok := getString(params.FieldMap["adspaceId"]); ok {
fields = append(fields, fmt.Sprintf(`"adspaceId":"%s"`, adspaceID))
fmt.Fprintf(&jsonStr, `,"adspaceId":"%s"`, adspaceID)
}

if adbreakID, ok := getString(params.FieldMap["adbreakId"]); ok {
fields = append(fields, fmt.Sprintf(`"adbreakId":"%s"`, adbreakID))
fmt.Fprintf(&jsonStr, `,"adbreakId":"%s"`, adbreakID)
}

jsonStr.WriteString(strings.Join(fields, ","))
jsonStr.WriteByte('}')
return jsonStr.Bytes(), nil
}
Expand Down
53 changes: 28 additions & 25 deletions modules/pubmatic/openwrap/adapters/bidders_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2001,6 +2001,19 @@ func TestPrepareBidParamJSONForPartnerSmaato(t *testing.T) {
args args
want json.RawMessage
}{
{
name: "all_missing",
args: args{
reqID: "",
width: nil,
height: nil,
fieldMap: map[string]interface{}{},
slotKey: "",
adapterName: string(openrtb_ext.BidderSmaato),
bidderCode: string(openrtb_ext.BidderSmaato),
},
want: nil,
},
{
name: "publisherId missing",
args: args{
Expand All @@ -2009,6 +2022,7 @@ func TestPrepareBidParamJSONForPartnerSmaato(t *testing.T) {
height: nil,
fieldMap: map[string]interface{}{
"adspaceId": "1234",
"adbreakId": "4567",
},
slotKey: "",
adapterName: string(openrtb_ext.BidderSmaato),
Expand All @@ -2032,64 +2046,51 @@ func TestPrepareBidParamJSONForPartnerSmaato(t *testing.T) {
want: json.RawMessage(`{"publisherId": "1234"}`),
},
{
name: "publisherId & adspaceId both are missing",
args: args{
reqID: "",
width: nil,
height: nil,
fieldMap: map[string]interface{}{},
slotKey: "",
adapterName: string(openrtb_ext.BidderSmaato),
bidderCode: string(openrtb_ext.BidderSmaato),
},
want: nil,
},
{
name: "publisherId_adspaceId_both_are_present",
name: "adbreakId missing",
args: args{

width: nil,
height: nil,
fieldMap: map[string]interface{}{
"publisherId": "1234",
"adspaceId": "3456",
},
slotKey: "",
adapterName: string(openrtb_ext.BidderSmaato),
bidderCode: string(openrtb_ext.BidderSmaato),
},
want: json.RawMessage(`{"publisherId": "1234","adspaceId": "3456"}`),
want: json.RawMessage(`{"publisherId": "1234"}`),
},
{
name: "All_params_are_present",
name: "publisherId_adspaceId__present",
args: args{

width: nil,
height: nil,
fieldMap: map[string]interface{}{
"publisherId": "1234",
"adspaceId": "3456",
"adbreakId": "7899",
},
slotKey: "",
adapterName: string(openrtb_ext.BidderSmaato),
bidderCode: string(openrtb_ext.BidderSmaato),
},
want: json.RawMessage(`{"publisherId": "1234","adspaceId": "3456","adbreakId": "7899"}`),
want: json.RawMessage(`{"publisherId": "1234","adspaceId": "3456"}`),
},
{
name: "publisherId_and_adbreakId_present",
name: "publisherId_adbreakId__present",
args: args{

width: nil,
height: nil,
fieldMap: map[string]interface{}{
"publisherId": "1234",
"adbreakId": "7899",
"adbreakId": "3456",
},
slotKey: "",
adapterName: string(openrtb_ext.BidderSmaato),
bidderCode: string(openrtb_ext.BidderSmaato),
},
want: json.RawMessage(`{"publisherId": "1234","adbreakId": "7899"}`),
want: json.RawMessage(`{"publisherId": "1234","adbreakId": "3456"}`),
},
{
name: "adspaceId_and_adbreakId_present",
Expand All @@ -2107,18 +2108,20 @@ func TestPrepareBidParamJSONForPartnerSmaato(t *testing.T) {
want: nil,
},
{
name: "adbreakId_present",
name: "all_params_are_present",
args: args{
width: nil,
height: nil,
fieldMap: map[string]interface{}{
"adbreakId": "7899",
"publisherId": "1234",
"adspaceId": "3456",
"adbreakId": "7899",
},
slotKey: "",
adapterName: string(openrtb_ext.BidderSmaato),
bidderCode: string(openrtb_ext.BidderSmaato),
},
want: nil,
want: json.RawMessage(`{"publisherId": "1234","adspaceId": "3456","adbreakId": "7899"}`),
},
}
for _, tt := range tests {
Expand Down

0 comments on commit cb5bfb7

Please sign in to comment.