Skip to content

Commit

Permalink
UOE-11650: Add Builder for Compass Bidder (#989)
Browse files Browse the repository at this point in the history
  • Loading branch information
pm-saurabh-narkhede authored Dec 30, 2024
1 parent 15dd2c5 commit f6320a8
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 0 deletions.
19 changes: 19 additions & 0 deletions modules/pubmatic/openwrap/adapters/bidders.go
Original file line number Diff line number Diff line change
Expand Up @@ -730,3 +730,22 @@ func builderAidem(params BidderParameters) (json.RawMessage, error) {

return jsonStr.Bytes(), nil
}

func builderCompass(params BidderParameters) (json.RawMessage, error) {
jsonStr := bytes.Buffer{}
jsonStr.WriteByte('{')
oneOf := []string{"placementId", "endpointId"}
for _, param := range oneOf {
if key, ok := getString(params.FieldMap[param]); ok {
fmt.Fprintf(&jsonStr, `"%s":"%s"`, param, key)
break
}
}
// len=0 (no mandatory params present)
if jsonStr.Len() == 1 {
return nil, fmt.Errorf(errMandatoryParameterMissingFormat, params.AdapterName, oneOf)
}

jsonStr.WriteByte('}')
return jsonStr.Bytes(), nil
}
47 changes: 47 additions & 0 deletions modules/pubmatic/openwrap/adapters/bidders_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3119,3 +3119,50 @@ func Test_builderAidem(t *testing.T) {
})
}
}

func TestBuilderCompass(t *testing.T) {
type args struct {
params BidderParameters
}
tests := []struct {
name string
args args
want json.RawMessage
wantErr bool
}{
{
name: "Valid Scenerio (oneOf placementId or endpointId) is present-placementId",
args: args{params: BidderParameters{FieldMap: JSONObject{"placementId": "dbdsfh"}}},
want: json.RawMessage(`{"placementId": "dbdsfh"}`),
wantErr: false,
},
{
name: "Valid Scenerio (oneOf placementId or endpointId) is present-endpointId",
args: args{params: BidderParameters{FieldMap: JSONObject{"endpointId": "dbdsfh"}}},
want: json.RawMessage(`{"endpointId": "dbdsfh"}`),
wantErr: false,
},
{
name: "Valid Scenerio (oneOf placementId or endpointId), Both are present",
args: args{params: BidderParameters{FieldMap: JSONObject{"placementId": "sdhks", "endpointId": "sdjksd"}}},
want: json.RawMessage(`{"placementId": "sdhks"}`),
wantErr: false,
},
{
name: "Invalid Scenerio (None Of placementId or endpointId) is present",
args: args{params: BidderParameters{FieldMap: JSONObject{}}},
want: json.RawMessage(``),
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := builderCompass(tt.args.params)
if (err != nil) != tt.wantErr {
t.Errorf("builderCompass() error = %v, wantErr %v", err, tt.wantErr)
return
}
AssertJSON(t, tt.want, got)
})
}
}
1 change: 1 addition & 0 deletions modules/pubmatic/openwrap/adapters/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func initBidderBuilderFactory() {
string(openrtb_ext.BidderKargo): builderKargo,
string(openrtb_ext.BidderPGAMSsp): builderPGAMSSP,
string(openrtb_ext.BidderAidem): builderAidem,
string(openrtb_ext.BidderCompass): builderCompass,
}
}

Expand Down
15 changes: 15 additions & 0 deletions modules/pubmatic/openwrap/adapters/tests/s2s_bidders.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,20 @@
"siteId":"abcdefg"
}
}
},
{
"name": "compass_json_OneOf - placementId/endpointId",
"args" : {
"adapterName": "compass",
"requestJSON": {
"placementId": "123456",
"endpointId": "abcdefg"
}
},
"want": {
"expectedJSON": {
"placementId": "123456"
}
}
}
]

0 comments on commit f6320a8

Please sign in to comment.