Skip to content

Commit

Permalink
Floors: Update FloorsSchemaVersion data type from string to int (#3592)
Browse files Browse the repository at this point in the history
  • Loading branch information
pm-jaydeep-mohite committed Apr 2, 2024
1 parent 9070008 commit 47c9434
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 12 deletions.
8 changes: 4 additions & 4 deletions floors/floors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func TestEnrichWithPriceFloors(t *testing.T) {
expFloorVal float64
expFloorCur string
expPriceFlrLoc string
expSchemaVersion string
expSchemaVersion int
}{
{
name: "Floors disabled in account config",
Expand Down Expand Up @@ -178,15 +178,15 @@ func TestEnrichWithPriceFloors(t *testing.T) {
Publisher: &openrtb2.Publisher{Domain: "www.website.com"},
},
Imp: []openrtb2.Imp{{ID: "1234", Banner: &openrtb2.Banner{Format: []openrtb2.Format{{W: 300, H: 250}}}}},
Ext: json.RawMessage(`{"prebid":{"floors":{"floormin":11,"floormincur":"USD","data":{"currency":"USD","floorsschemaversion":"2","modelgroups":[{"modelweight":50,"modelversion":"version2","schema":{"fields":["mediaType","size","domain"],"delimiter":"|"},"values":{"*|*|*":11.01,"*|*|www.website1.com":17.01},"default":21},{"modelweight":50,"modelversion":"version11","skiprate":110,"schema":{"fields":["mediaType","size","domain"],"delimiter":"|"},"values":{"*|300x250|*":11.01,"*|300x250|www.website1.com":100.01},"default":21}]},"enforcement":{"enforcepbs":true,"floordeals":true},"enabled":true}}}`),
Ext: json.RawMessage(`{"prebid":{"floors":{"floormin":11,"floormincur":"USD","data":{"currency":"USD","floorsschemaversion":2,"modelgroups":[{"modelweight":50,"modelversion":"version2","schema":{"fields":["mediaType","size","domain"],"delimiter":"|"},"values":{"*|*|*":11.01,"*|*|www.website1.com":17.01},"default":21},{"modelweight":50,"modelversion":"version11","skiprate":110,"schema":{"fields":["mediaType","size","domain"],"delimiter":"|"},"values":{"*|300x250|*":11.01,"*|300x250|www.website1.com":100.01},"default":21}]},"enforcement":{"enforcepbs":true,"floordeals":true},"enabled":true}}}`),
},
},
account: testAccountConfig,
err: "Invalid Floor Model = 'version11' due to SkipRate = '110' is out of range (1-100)",
expFloorVal: 11.01,
expFloorCur: "USD",
expPriceFlrLoc: openrtb_ext.RequestLocation,
expSchemaVersion: "2",
expSchemaVersion: 2,
},
{
name: "Rule selection with Site object, banner|300x600|www.website.com",
Expand Down Expand Up @@ -385,7 +385,7 @@ func TestEnrichWithPriceFloors(t *testing.T) {
assert.Equal(t, *requestExt.GetPrebid().Floors.Skipped, tc.Skipped, tc.name)
} else {
assert.Equal(t, requestExt.GetPrebid().Floors.PriceFloorLocation, tc.expPriceFlrLoc, tc.name)
if tc.expSchemaVersion != "" {
if tc.expSchemaVersion != 0 {
assert.Equal(t, requestExt.GetPrebid().Floors.Data.FloorsSchemaVersion, tc.expSchemaVersion, tc.name)
}
}
Expand Down
2 changes: 1 addition & 1 deletion floors/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func validateFloorRulesAndLowerValidRuleKey(schema openrtb_ext.PriceFloorSchema,

// validateFloorParams validates SchemaVersion, SkipRate and FloorMin
func validateFloorParams(extFloorRules *openrtb_ext.PriceFloorRules) error {
if extFloorRules.Data != nil && len(extFloorRules.Data.FloorsSchemaVersion) > 0 && extFloorRules.Data.FloorsSchemaVersion != "2" {
if extFloorRules.Data != nil && extFloorRules.Data.FloorsSchemaVersion != 0 && extFloorRules.Data.FloorsSchemaVersion != 2 {
return fmt.Errorf("Invalid FloorsSchemaVersion = '%v', supported version 2", extFloorRules.Data.FloorsSchemaVersion)
}

Expand Down
47 changes: 43 additions & 4 deletions floors/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,59 @@ func TestValidateFloorParams(t *testing.T) {
Err: errors.New("Invalid FloorMin = '-10', value should be >= 0"),
},
{
name: "Invalid FloorSchemaVersion ",
name: "Invalid FloorSchemaVersion 2",
floorExt: &openrtb_ext.PriceFloorRules{Data: &openrtb_ext.PriceFloorData{
FloorsSchemaVersion: "1",
FloorsSchemaVersion: 1,
ModelGroups: []openrtb_ext.PriceFloorModelGroup{{
ModelVersion: "Version 1",

Schema: openrtb_ext.PriceFloorSchema{Fields: []string{"mediaType", "size", "domain"}, Delimiter: "|"},
Schema: openrtb_ext.PriceFloorSchema{Fields: []string{"mediaType", "size", "domain"}, Delimiter: "|"},
Values: map[string]float64{
"banner|300x250|www.website.com": 1.01,
"banner|300x600|*": 4.01,
}, Default: 0.01},
}}},
Err: errors.New("Invalid FloorsSchemaVersion = '1', supported version 2"),
},
{
name: "Invalid FloorSchemaVersion -2",
floorExt: &openrtb_ext.PriceFloorRules{Data: &openrtb_ext.PriceFloorData{
FloorsSchemaVersion: -2,
ModelGroups: []openrtb_ext.PriceFloorModelGroup{{
ModelVersion: "Version 1",
Schema: openrtb_ext.PriceFloorSchema{Fields: []string{"mediaType", "size", "domain"}, Delimiter: "|"},
Values: map[string]float64{
"banner|300x250|www.website.com": 1.01,
"banner|300x600|*": 4.01,
}, Default: 0.01},
}}},
Err: errors.New("Invalid FloorsSchemaVersion = '-2', supported version 2"),
},
{
name: "Valid FloorSchemaVersion 0",
floorExt: &openrtb_ext.PriceFloorRules{Data: &openrtb_ext.PriceFloorData{
FloorsSchemaVersion: 0,
ModelGroups: []openrtb_ext.PriceFloorModelGroup{{
ModelVersion: "Version 1",
Schema: openrtb_ext.PriceFloorSchema{Fields: []string{"mediaType", "size", "domain"}, Delimiter: "|"},
Values: map[string]float64{
"banner|300x250|www.website.com": 1.01,
"banner|300x600|*": 4.01,
}, Default: 0.01},
}}},
},
{
name: "Valid FloorSchemaVersion 2",
floorExt: &openrtb_ext.PriceFloorRules{Data: &openrtb_ext.PriceFloorData{
FloorsSchemaVersion: 2,
ModelGroups: []openrtb_ext.PriceFloorModelGroup{{
ModelVersion: "Version 1",
Schema: openrtb_ext.PriceFloorSchema{Fields: []string{"mediaType", "size", "domain"}, Delimiter: "|"},
Values: map[string]float64{
"banner|300x250|www.website.com": 1.01,
"banner|300x600|*": 4.01,
}, Default: 0.01},
}}},
},
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion openrtb_ext/floors.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ type PriceFloorEndpoint struct {
type PriceFloorData struct {
Currency string `json:"currency,omitempty"`
SkipRate int `json:"skiprate,omitempty"`
FloorsSchemaVersion string `json:"floorsschemaversion,omitempty"`
FloorsSchemaVersion int `json:"floorsschemaversion,omitempty"`
ModelTimestamp int `json:"modeltimestamp,omitempty"`
ModelGroups []PriceFloorModelGroup `json:"modelgroups,omitempty"`
FloorProvider string `json:"floorprovider,omitempty"`
Expand Down
4 changes: 2 additions & 2 deletions openrtb_ext/floors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ func TestFloorRulesDeepCopy(t *testing.T) {
Data: &PriceFloorData{
Currency: "INR",
SkipRate: 0,
FloorsSchemaVersion: "2",
FloorsSchemaVersion: 2,
ModelTimestamp: 123,
ModelGroups: []PriceFloorModelGroup{
{
Expand Down Expand Up @@ -370,7 +370,7 @@ func TestFloorRulesDeepCopy(t *testing.T) {
Data: &PriceFloorData{
Currency: "INR",
SkipRate: 0,
FloorsSchemaVersion: "2",
FloorsSchemaVersion: 2,
ModelTimestamp: 123,
ModelGroups: []PriceFloorModelGroup{
{
Expand Down

0 comments on commit 47c9434

Please sign in to comment.