-
Notifications
You must be signed in to change notification settings - Fork 760
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
Orbidder: bidfloor currency handling #2093
Changes from all commits
5d4ab1d
794f81d
000fef8
3aa28cb
9d789f7
cb063f1
87553de
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,10 @@ package orbidder | |
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"github.com/mxmCherry/openrtb/v15/openrtb2" | ||
"github.com/prebid/prebid-server/adapters" | ||
"github.com/stretchr/testify/mock" | ||
"testing" | ||
|
||
"github.com/prebid/prebid-server/adapters/adapterstest" | ||
|
@@ -22,6 +26,16 @@ func TestUnmarshalOrbidderExtImp(t *testing.T) { | |
}, impExt) | ||
} | ||
|
||
func TestPreprocessExtensions(t *testing.T) { | ||
for name, tc := range testCasesExtension { | ||
t.Run(name, func(t *testing.T) { | ||
imp := tc.imp | ||
err := preprocessExtensions(&imp) | ||
tc.assertError(t, err) | ||
}) | ||
} | ||
} | ||
|
||
func TestJsonSamples(t *testing.T) { | ||
bidder, buildErr := Builder(openrtb_ext.BidderOrbidder, config.Adapter{ | ||
Endpoint: "https://orbidder-test"}) | ||
|
@@ -32,3 +46,136 @@ func TestJsonSamples(t *testing.T) { | |
|
||
adapterstest.RunJSONBidderTest(t, "orbiddertest", bidder) | ||
} | ||
|
||
var testCasesCurrency = map[string]struct { | ||
imp openrtb2.Imp | ||
setMock func(m *mock.Mock) | ||
expectedImp openrtb2.Imp | ||
assertError func(t assert.TestingT, err error, msgAndArgs ...interface{}) bool | ||
}{ | ||
"EUR: no bidfloor, no currency": { | ||
imp: openrtb2.Imp{ | ||
BidFloor: 0, | ||
BidFloorCur: "", | ||
}, | ||
setMock: func(m *mock.Mock) {}, | ||
expectedImp: openrtb2.Imp{ | ||
BidFloor: 0, | ||
BidFloorCur: "EUR", | ||
}, | ||
assertError: assert.NoError, | ||
}, | ||
"EUR: bidfloor, no currency": { | ||
imp: openrtb2.Imp{ | ||
BidFloor: 1, | ||
BidFloorCur: "", | ||
}, | ||
setMock: func(m *mock.Mock) {}, | ||
expectedImp: openrtb2.Imp{ | ||
BidFloor: 1, | ||
BidFloorCur: "EUR", | ||
}, | ||
assertError: assert.NoError, | ||
}, | ||
"EUR: bidfloor and currency": { | ||
imp: openrtb2.Imp{ | ||
BidFloor: 1, | ||
BidFloorCur: "EUR", | ||
}, | ||
setMock: func(m *mock.Mock) {}, | ||
expectedImp: openrtb2.Imp{ | ||
BidFloor: 1, | ||
BidFloorCur: "EUR", | ||
}, | ||
assertError: assert.NoError, | ||
}, | ||
"USD: bidfloor with currency": { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please add another similar test case where the mock converter returns an error to make sure the error from the converter is properly propagated? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
imp: openrtb2.Imp{ | ||
BidFloor: 1, | ||
BidFloorCur: "USD", | ||
}, | ||
setMock: func(m *mock.Mock) { | ||
m.On("GetRate", "USD", "EUR").Return(2.5, nil) | ||
}, | ||
expectedImp: openrtb2.Imp{ | ||
BidFloor: 2.5, | ||
BidFloorCur: "EUR", | ||
}, | ||
assertError: assert.NoError, | ||
}, | ||
"USD: no bidfloor": { | ||
imp: openrtb2.Imp{ | ||
BidFloor: 0, | ||
BidFloorCur: "USD", | ||
}, | ||
setMock: func(m *mock.Mock) {}, | ||
expectedImp: openrtb2.Imp{ | ||
BidFloor: 0, | ||
BidFloorCur: "EUR", | ||
}, | ||
assertError: assert.NoError, | ||
}, | ||
"ABC: invalid currency code": { | ||
imp: openrtb2.Imp{ | ||
BidFloor: 1, | ||
BidFloorCur: "ABC", | ||
}, | ||
setMock: func(m *mock.Mock) { | ||
m.On("GetRate", "ABC", "EUR").Return(0.0, errors.New("currency conversion error")) | ||
}, | ||
expectedImp: openrtb2.Imp{ | ||
BidFloor: 1, | ||
BidFloorCur: "ABC", | ||
}, | ||
assertError: assert.Error, | ||
}, | ||
} | ||
|
||
var testCasesExtension = map[string]struct { | ||
imp openrtb2.Imp | ||
assertError func(t assert.TestingT, err error, msgAndArgs ...interface{}) bool | ||
}{ | ||
"Valid Orbidder Extension": { | ||
imp: openrtb2.Imp{ | ||
Ext: json.RawMessage(`{"bidder":{"accountId":"orbidder-test", "placementId":"center-banner", "bidfloor": 0.1}}`), | ||
}, | ||
assertError: assert.NoError, | ||
}, | ||
"Invalid Orbidder Extension": { | ||
imp: openrtb2.Imp{ | ||
Ext: json.RawMessage(`{"there's'":{"something":"strange", "in the":"neighbourhood", "who you gonna call?": 0.1}}`), | ||
}, | ||
assertError: assert.Error, | ||
}, | ||
} | ||
|
||
func TestPreprocessBidFloorCurrency(t *testing.T) { | ||
for name, tc := range testCasesCurrency { | ||
t.Run(name, func(t *testing.T) { | ||
imp := tc.imp | ||
mockConversions := &mockCurrencyConversion{} | ||
tc.setMock(&mockConversions.Mock) | ||
extraRequestInfo := adapters.ExtraRequestInfo{ | ||
CurrencyConversions: mockConversions, | ||
} | ||
err := preprocessBidFloorCurrency(&imp, &extraRequestInfo) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You need to call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for pointing this out to us. We added a call of |
||
assert.True(t, mockConversions.AssertExpectations(t)) | ||
tc.assertError(t, err) | ||
assert.Equal(t, tc.expectedImp, imp) | ||
}) | ||
} | ||
} | ||
|
||
type mockCurrencyConversion struct { | ||
mock.Mock | ||
} | ||
|
||
func (m *mockCurrencyConversion) GetRate(from string, to string) (float64, error) { | ||
args := m.Called(from, to) | ||
return args.Get(0).(float64), args.Error(1) | ||
} | ||
|
||
func (m *mockCurrencyConversion) GetRates() *map[string]map[string]float64 { | ||
args := m.Called() | ||
return args.Get(0).(*map[string]map[string]float64) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,7 @@ | |
} | ||
] | ||
}, | ||
"bidfloorcur": "EUR", | ||
"ext": { | ||
"bidder": { | ||
"accountId": "orbidder-test", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,7 @@ | |
} | ||
] | ||
}, | ||
"bidfloorcur": "EUR", | ||
"ext": { | ||
"bidder": { | ||
"accountId": "orbidder-test", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,7 @@ | |
} | ||
] | ||
}, | ||
"bidfloorcur": "EUR", | ||
"ext": { | ||
"bidder": { | ||
"accountId": "orbidder-test", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,7 @@ | |
} | ||
] | ||
}, | ||
"bidfloorcur": "EUR", | ||
"ext": { | ||
"bidder": { | ||
"accountId": "orbidder-test", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,7 @@ | |
} | ||
] | ||
}, | ||
"bidfloorcur": "EUR", | ||
"ext": { | ||
"bidder": { | ||
"accountId": "orbidder-test", | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,7 @@ | |
} | ||
] | ||
}, | ||
"bidfloorcur": "EUR", | ||
"ext": { | ||
"bidder": { | ||
"accountId": "orbidder-test", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,6 +57,7 @@ | |
} | ||
] | ||
}, | ||
"bidfloorcur": "EUR", | ||
"ext": { | ||
"bidder": { | ||
"accountId": "orbidder-test", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you just testing that unmarshalling
imp.ext
does not produce an error? Seems that you are throwing away the result.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you are right. We only checking for errors in unmarshalling
imp.ext
. In the past we had some problems with invalid Extensions send to our adapter, so we find this check useful. We added some testcases for the preprocessing.