-
Notifications
You must be signed in to change notification settings - Fork 748
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
Fix Currency Converter Doesn't Output CUR #1154
Changes from all commits
d3f5c06
a099405
69425e6
5915a78
e2116e2
a82cc58
158bc22
c57b31a
e8e6cee
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 |
---|---|---|
|
@@ -314,51 +314,145 @@ func TestGetBidCacheInfo(t *testing.T) { | |
assert.Equal(t, expCacheURL, cacheURL, "[TestGetBidCacheInfo] cacheId field in ext should equal \"%s\" \n", expCacheURL) | ||
} | ||
|
||
func buildBidResponseParams(bidderName openrtb_ext.BidderName, bidRequest *openrtb.BidRequest) ([]openrtb_ext.BidderName, map[openrtb_ext.BidderName]*pbsOrtbSeatBid, json.RawMessage, map[openrtb_ext.BidderName]*seatResponseExtra) { | ||
//liveAdapters []openrtb_ext.BidderName, | ||
liveAdapters := []openrtb_ext.BidderName{bidderName} | ||
func TestBidResponseCurrency(t *testing.T) { | ||
// Init objects | ||
cfg := &config.Configuration{Adapters: make(map[string]config.Adapter, 1)} | ||
cfg.Adapters["appnexus"] = config.Adapter{Endpoint: "http://ib.adnxs.com"} | ||
|
||
//adapterBids map[openrtb_ext.BidderName]*pbsOrtbSeatBid, | ||
adapterBids := map[openrtb_ext.BidderName]*pbsOrtbSeatBid{ | ||
bidderName: { | ||
bids: []*pbsOrtbBid{ | ||
{ | ||
bid: &openrtb.Bid{ | ||
ID: "some-imp-id", | ||
Price: 9.517803, | ||
W: 300, | ||
H: 250, | ||
}, | ||
bidType: openrtb_ext.BidTypeBanner, | ||
bidTargets: map[string]string{ | ||
"pricegranularity": "med", | ||
"includewinners": "true", | ||
"includebidderkeys": "false", | ||
}, | ||
}, | ||
}, | ||
currency: "USD", | ||
//ext: bidRequest.Ext, | ||
}, | ||
handlerNoBidServer := func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(204) } | ||
server := httptest.NewServer(http.HandlerFunc(handlerNoBidServer)) | ||
defer server.Close() | ||
|
||
e := NewExchange(server.Client(), nil, cfg, pbsmetrics.NewMetrics(metrics.NewRegistry(), openrtb_ext.BidderList(), config.DisabledMetrics{}), adapters.ParseBidderInfos(cfg.Adapters, "../static/bidder-info", openrtb_ext.BidderList()), gdpr.AlwaysAllow{}, currencies.NewRateConverterDefault()).(*exchange) | ||
|
||
liveAdapters := make([]openrtb_ext.BidderName, 1) | ||
liveAdapters[0] = "appnexus" | ||
|
||
bidRequest := &openrtb.BidRequest{ | ||
ID: "some-request-id", | ||
Imp: []openrtb.Imp{{ | ||
ID: "some-impression-id", | ||
Banner: &openrtb.Banner{Format: []openrtb.Format{{W: 300, H: 250}, {W: 300, H: 600}}}, | ||
Ext: json.RawMessage(`{"appnexus": {"placementId": 10433394}}`), | ||
}}, | ||
Site: &openrtb.Site{Page: "prebid.org", Ext: json.RawMessage(`{"amp":0}`)}, | ||
Device: &openrtb.Device{UA: "curl/7.54.0", IP: "::1"}, | ||
AT: 1, | ||
TMax: 500, | ||
Ext: json.RawMessage(`{"id": "some-request-id","site": {"page": "prebid.org"},"imp": [{"id": "some-impression-id","banner": {"format": [{"w": 300,"h": 250},{"w": 300,"h": 600}]},"ext": {"appnexus": {"placementId": 10433394}}}],"tmax": 500}`), | ||
} | ||
|
||
//resolvedRequest json.RawMessage | ||
resolvedRequest := json.RawMessage(`{"id": "some-request-id","site": {"page": "prebid.org"},"imp": [{"id": "some-impression-id","banner": {"format": [{"w": 300,"h": 250},{"w": 300,"h": 600}]},"ext": {"appnexus": {"placementId": 1}}}],"tmax": 500}`) | ||
|
||
//adapterExtra map[openrtb_ext.BidderName]*seatResponseExtra, | ||
adapterExtra := map[openrtb_ext.BidderName]*seatResponseExtra{ | ||
bidderName: { | ||
ResponseTimeMillis: 5, | ||
Errors: []openrtb_ext.ExtBidderError{ | ||
"appnexus": {ResponseTimeMillis: 5}, | ||
} | ||
|
||
var errList []error | ||
|
||
sampleBid := &openrtb.Bid{ | ||
ID: "some-imp-id", | ||
Price: 9.517803, | ||
W: 300, | ||
H: 250, | ||
Ext: nil, | ||
} | ||
aPbsOrtbBidArr := []*pbsOrtbBid{{bid: sampleBid, bidType: openrtb_ext.BidTypeBanner}} | ||
sampleSeatBid := []openrtb.SeatBid{ | ||
{ | ||
Seat: "appnexus", | ||
Bid: []openrtb.Bid{ | ||
{ | ||
Code: 999, | ||
Message: "Post ib.adnxs.com/openrtb2?query1&query2: unsupported protocol scheme \"\"", | ||
ID: "some-imp-id", | ||
Price: 9.517803, | ||
W: 300, | ||
H: 250, | ||
Ext: json.RawMessage(`{"prebid":{"type":"banner"}}`), | ||
}, | ||
}, | ||
}, | ||
} | ||
emptySeatBid := []openrtb.SeatBid{} | ||
|
||
// Test cases | ||
type aTest struct { | ||
description string | ||
adapterBids map[openrtb_ext.BidderName]*pbsOrtbSeatBid | ||
expectedBidResponse *openrtb.BidResponse | ||
} | ||
testCases := []aTest{ | ||
{ | ||
description: "1) Adapter to bids map comes with a non-empty currency field and non-empty bid array", | ||
adapterBids: map[openrtb_ext.BidderName]*pbsOrtbSeatBid{ | ||
openrtb_ext.BidderName("appnexus"): { | ||
bids: aPbsOrtbBidArr, | ||
currency: "USD", | ||
}, | ||
}, | ||
expectedBidResponse: &openrtb.BidResponse{ | ||
ID: "some-request-id", | ||
SeatBid: sampleSeatBid, | ||
Cur: "USD", | ||
Ext: json.RawMessage(`{"responsetimemillis":{"appnexus":5},"tmaxrequest":500} | ||
`), | ||
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. Consider moving these terminal `')' pairs to the end of the line. Might look cleaner. 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. If instead of:
I put everything in a single line:
Tht test faisl because we are missing a line break:
I googled this issue and apparently JSON should recognize the common line break escape sequence
Have you come accross this before? 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. Ah, ok. The response must include a line break at the end. Got it. That's fine. Please just resolve the merge conflict and we'll be good here. |
||
}, | ||
}, | ||
{ | ||
description: "2) Adapter to bids map comes with a non-empty currency field but an empty bid array", | ||
adapterBids: map[openrtb_ext.BidderName]*pbsOrtbSeatBid{ | ||
openrtb_ext.BidderName("appnexus"): { | ||
bids: nil, | ||
currency: "USD", | ||
}, | ||
}, | ||
expectedBidResponse: &openrtb.BidResponse{ | ||
ID: "some-request-id", | ||
SeatBid: emptySeatBid, | ||
Cur: "", | ||
Ext: json.RawMessage(`{"responsetimemillis":{"appnexus":5},"tmaxrequest":500} | ||
`), | ||
}, | ||
}, | ||
{ | ||
description: "3) Adapter to bids map comes with an empty currency string and a non-empty bid array", | ||
adapterBids: map[openrtb_ext.BidderName]*pbsOrtbSeatBid{ | ||
openrtb_ext.BidderName("appnexus"): { | ||
bids: aPbsOrtbBidArr, | ||
currency: "", | ||
}, | ||
}, | ||
expectedBidResponse: &openrtb.BidResponse{ | ||
ID: "some-request-id", | ||
SeatBid: sampleSeatBid, | ||
Cur: "", | ||
Ext: json.RawMessage(`{"responsetimemillis":{"appnexus":5},"tmaxrequest":500} | ||
`), | ||
}, | ||
}, | ||
{ | ||
description: "4) Adapter to bids map comes with an empty currency string and an empty bid array", | ||
adapterBids: map[openrtb_ext.BidderName]*pbsOrtbSeatBid{ | ||
openrtb_ext.BidderName("appnexus"): { | ||
bids: nil, | ||
currency: "", | ||
}, | ||
}, | ||
expectedBidResponse: &openrtb.BidResponse{ | ||
ID: "some-request-id", | ||
SeatBid: emptySeatBid, | ||
Cur: "", | ||
Ext: json.RawMessage(`{"responsetimemillis":{"appnexus":5},"tmaxrequest":500} | ||
`), | ||
}, | ||
}, | ||
} | ||
|
||
return liveAdapters, adapterBids, resolvedRequest, adapterExtra | ||
// Run tests | ||
for i := range testCases { | ||
actualBidResp, err := e.buildBidResponse(context.Background(), liveAdapters, testCases[i].adapterBids, bidRequest, resolvedRequest, adapterExtra, nil, errList) | ||
assert.NoError(t, err, fmt.Sprintf("[TEST_FAILED] e.buildBidResponse resturns error in test: %s Error message: %s \n", testCases[i].description, err)) | ||
assert.Equalf(t, testCases[i].expectedBidResponse, actualBidResp, fmt.Sprintf("[TEST_FAILED] Objects must be equal for test: %s \n Expected: >>%s<< \n Actual: >>%s<< ", testCases[i].description, testCases[i].expectedBidResponse.Ext, actualBidResp.Ext)) | ||
} | ||
} | ||
|
||
// TestRaceIntegration runs an integration test using all the sample params from | ||
|
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.
Same deal, with
banner-content4
, etc...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.
Done