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

Updated price granularity unmarshal to accept empty values and ranges #1230

Merged
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
7 changes: 4 additions & 3 deletions openrtb_ext/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,11 @@ func (pg *PriceGranularity) UnmarshalJSON(b []byte) error {
}
prevMax = gr.Max
}
} else {
return errors.New("Price granularity error: empty granularity definition supplied")
*pg = PriceGranularity(pgraw)
return nil
}
*pg = PriceGranularity(pgraw)
// Default to medium if no ranges are specified
*pg = priceGranularityMed
return nil
}

Expand Down
13 changes: 12 additions & 1 deletion openrtb_ext/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,22 @@ var validGranularityTests []granularityTestData = []granularityTestData{
},
},
},
{
json: []byte(`{}`),
target: priceGranularityMed,
},
{
json: []byte(`{"precision": 2}`),
target: priceGranularityMed,
},
{
json: []byte(`{"precision": 2, "ranges":[]}`),
target: priceGranularityMed,
},
}

func TestGranularityUnmarshalBad(t *testing.T) {
tests := [][]byte{
[]byte(`{}`),
[]byte(`[]`),
[]byte(`{"precision": -1, "ranges": [{"max":20, "increment":0.5}]}`),
[]byte(`{"ranges":[{"max":20, "increment": -1}]}`),
Expand Down