Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AdbreakId support for smaato bidder #986

Open
wants to merge 3 commits into
base: ci
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions modules/pubmatic/openwrap/adapters/bidders.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,19 +380,23 @@ 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 {
return nil, fmt.Errorf(errMandatoryParameterMissingFormat, params.AdapterName, "publisherId")
} else {
fmt.Fprintf(&jsonStr, `"publisherId":"%s",`, publisherID)
fields = append(fields, fmt.Sprintf(`"publisherId":"%s"`, publisherID))
}

if adspaceID, ok := getString(params.FieldMap["adspaceId"]); !ok {
return nil, fmt.Errorf(errMandatoryParameterMissingFormat, params.AdapterName, "adspaceId")
} else {
fmt.Fprintf(&jsonStr, `"adspaceId":"%s"`, adspaceID)
Comment on lines -390 to -393
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Pubmatic-Supriya-Patil : I think we should stick to any of rule here. It means, ensure either adspaceid or adbreakid is present , instead o removing the validation

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API will handle this validation while uploading mapping so no need to have same logic here

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

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

jsonStr.WriteString(strings.Join(fields, ","))
jsonStr.WriteByte('}')
return jsonStr.Bytes(), nil
}
Expand Down
64 changes: 62 additions & 2 deletions modules/pubmatic/openwrap/adapters/bidders_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2029,7 +2029,7 @@ func TestPrepareBidParamJSONForPartnerSmaato(t *testing.T) {
adapterName: string(openrtb_ext.BidderSmaato),
bidderCode: string(openrtb_ext.BidderSmaato),
},
want: nil,
want: json.RawMessage(`{"publisherId": "1234"}`),
},
{
name: "publisherId & adspaceId both are missing",
Expand All @@ -2045,7 +2045,7 @@ func TestPrepareBidParamJSONForPartnerSmaato(t *testing.T) {
want: nil,
},
{
name: "All params are present",
name: "publisherId_adspaceId_both_are_present",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Pubmatic-Supriya-Patil : What is the change in this test case?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously all params means publisher Id and adspace Id. now we added adbreakId as new field so just renamed test case name accordingly.

args: args{

width: nil,
Expand All @@ -2060,6 +2060,66 @@ func TestPrepareBidParamJSONForPartnerSmaato(t *testing.T) {
},
want: json.RawMessage(`{"publisherId": "1234","adspaceId": "3456"}`),
},
{
name: "All_params_are_present",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Pubmatic-Supriya-Patil : why have we introduced new test case. The test case with this name was present before, as per last review comment

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new test case is for publisherId, adspaceId and adbreakId. Previous one was only for publisherId and adspaceId

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"}`),
},
{
name: "publisherId_and_adbreakId_present",
args: args{
width: nil,
height: nil,
fieldMap: map[string]interface{}{
"publisherId": "1234",
"adbreakId": "7899",
},
slotKey: "",
adapterName: string(openrtb_ext.BidderSmaato),
bidderCode: string(openrtb_ext.BidderSmaato),
},
want: json.RawMessage(`{"publisherId": "1234","adbreakId": "7899"}`),
},
{
name: "adspaceId_and_adbreakId_present",
args: args{
width: nil,
height: nil,
fieldMap: map[string]interface{}{
"adspaceId": "1234",
"adbreakId": "7899",
},
slotKey: "",
adapterName: string(openrtb_ext.BidderSmaato),
bidderCode: string(openrtb_ext.BidderSmaato),
},
want: nil,
},
{
name: "adbreakId_present",
args: args{
width: nil,
height: nil,
fieldMap: map[string]interface{}{
"adbreakId": "7899",
},
slotKey: "",
adapterName: string(openrtb_ext.BidderSmaato),
bidderCode: string(openrtb_ext.BidderSmaato),
},
want: nil,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
Loading