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

UOE-11650: Add Builder for Compass Bidder #989

Merged
merged 1 commit into from
Dec 30, 2024
Merged
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
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"
}
}
}
]
Loading