Skip to content

Commit

Permalink
OTT-1360: As OpenWrap user, disable dynamic fetch if floors module di…
Browse files Browse the repository at this point in the history
…sabled from UI for all S2S profiles (#634)

* OTT-1360: As OpenWrap user, disable dynamic fetch if floors module disabled from UI for all S2S profiles
  • Loading branch information
pm-jaydeep-mohite authored Nov 6, 2023
1 parent ac44bb5 commit 2a2d2db
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 24 deletions.
24 changes: 9 additions & 15 deletions modules/pubmatic/openwrap/floors.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
)

func setFloorsExt(requestExt *models.RequestExt, configMap map[int]map[string]string) {

if configMap == nil || configMap[models.VersionLevelConfigID] == nil {
return
}
Expand All @@ -24,14 +23,6 @@ func setFloorsExt(requestExt *models.RequestExt, configMap map[int]map[string]st
if requestExt.Prebid.Floors.Enabled == nil {
requestExt.Prebid.Floors.Enabled = ptrutil.ToPtr(true)

enable, enabledExists := configMap[models.VersionLevelConfigID][models.FloorModuleEnabled]
if enabledExists && enable != "1" {
*requestExt.Prebid.Floors.Enabled = false
}
}

if !(*requestExt.Prebid.Floors.Enabled) {
return
}

if requestExt.Prebid.Floors.Enforcement == nil {
Expand All @@ -48,12 +39,15 @@ func setFloorsExt(requestExt *models.RequestExt, configMap map[int]map[string]st
}
}

url, urlExists := configMap[models.VersionLevelConfigID][models.PriceFloorURL]
if urlExists {
if requestExt.Prebid.Floors.Location == nil {
requestExt.Prebid.Floors.Location = new(openrtb_ext.PriceFloorEndpoint)
// Based on floorPriceModuleEnabled flag, dynamic fetch would be enabled/disabled
enableFlag, isFlagPresent := configMap[models.VersionLevelConfigID][models.FloorModuleEnabled]
if isFlagPresent && enableFlag == "1" {
url, urlExists := configMap[models.VersionLevelConfigID][models.PriceFloorURL]
if urlExists {
if requestExt.Prebid.Floors.Location == nil {
requestExt.Prebid.Floors.Location = new(openrtb_ext.PriceFloorEndpoint)
}
requestExt.Prebid.Floors.Location.URL = url
}
requestExt.Prebid.Floors.Location.URL = url
}

}
17 changes: 8 additions & 9 deletions modules/pubmatic/openwrap/floors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import (

"github.com/prebid/prebid-server/modules/pubmatic/openwrap/models"
"github.com/prebid/prebid-server/openrtb_ext"
"github.com/stretchr/testify/assert"
)

func Test_setFloorsExt(t *testing.T) {
func TestSetFloorsExt(t *testing.T) {
enable := true
disable := false

Expand All @@ -21,7 +22,7 @@ func Test_setFloorsExt(t *testing.T) {
want *models.RequestExt
}{
{
name: "JSON URL is present in db",
name: "Only JSON URL is present in db",
args: args{
requestExt: &models.RequestExt{},
configMap: map[int]map[string]string{
Expand All @@ -34,9 +35,6 @@ func Test_setFloorsExt(t *testing.T) {
ExtRequest: openrtb_ext.ExtRequest{
Prebid: openrtb_ext.ExtRequestPrebid{
Floors: &openrtb_ext.PriceFloorRules{
Location: &openrtb_ext.PriceFloorEndpoint{
URL: "http://test.com/floor",
},
Enabled: &enable,
Enforcement: &openrtb_ext.PriceFloorEnforcement{
EnforcePBS: &enable,
Expand All @@ -61,7 +59,10 @@ func Test_setFloorsExt(t *testing.T) {
ExtRequest: openrtb_ext.ExtRequest{
Prebid: openrtb_ext.ExtRequestPrebid{
Floors: &openrtb_ext.PriceFloorRules{
Enabled: &disable,
Enabled: &enable,
Enforcement: &openrtb_ext.PriceFloorEnforcement{
EnforcePBS: &enable,
},
},
},
},
Expand Down Expand Up @@ -213,9 +214,6 @@ func Test_setFloorsExt(t *testing.T) {
Prebid: openrtb_ext.ExtRequestPrebid{
Floors: &openrtb_ext.PriceFloorRules{
Enabled: &enable,
Location: &openrtb_ext.PriceFloorEndpoint{
URL: "http://test.com/floor",
},
Enforcement: &openrtb_ext.PriceFloorEnforcement{
EnforcePBS: &enable,
},
Expand Down Expand Up @@ -354,6 +352,7 @@ func Test_setFloorsExt(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
setFloorsExt(tt.args.requestExt, tt.args.configMap)
assert.Equal(t, tt.want, tt.args.requestExt)
})
}
}

0 comments on commit 2a2d2db

Please sign in to comment.