Skip to content
This repository was archived by the owner on Dec 22, 2022. It is now read-only.

Commit 1c0ea7a

Browse files
authored
openx adapter: forward bid response currency in openx adapter if set (prebid#1211)
it was always set to the default USD before
1 parent 4b6cf61 commit 1c0ea7a

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

adapters/openx/openx.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,11 @@ func (a *OpenxAdapter) MakeBids(internalRequest *openrtb.BidRequest, externalReq
169169

170170
bidResponse := adapters.NewBidderResponseWithBidsCapacity(5)
171171

172+
// overrride default currency
173+
if bidResp.Cur != "" {
174+
bidResponse.Currency = bidResp.Cur
175+
}
176+
172177
for _, sb := range bidResp.SeatBid {
173178
for i := range sb.Bid {
174179
bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{

adapters/openx/openx_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,48 @@
11
package openx
22

33
import (
4+
"encoding/json"
45
"testing"
56

7+
"github.com/mxmCherry/openrtb"
8+
"github.com/prebid/prebid-server/adapters"
69
"github.com/prebid/prebid-server/adapters/adapterstest"
10+
"github.com/stretchr/testify/assert"
711
)
812

913
func TestJsonSamples(t *testing.T) {
1014
adapterstest.RunJSONBidderTest(t, "openxtest", NewOpenxBidder("http://rtb.openx.net/prebid"))
1115
}
16+
17+
func TestResponseWithCurrencies(t *testing.T) {
18+
assertCurrencyInBidResponse(t, "USD", nil)
19+
20+
currency := "USD"
21+
assertCurrencyInBidResponse(t, "USD", &currency)
22+
23+
currency = "EUR"
24+
assertCurrencyInBidResponse(t, "EUR", &currency)
25+
}
26+
27+
func assertCurrencyInBidResponse(t *testing.T, expectedCurrency string, currency *string) {
28+
29+
bidder := NewOpenxBidder("http://rtb.openx.net/prebid")
30+
prebidRequest := &openrtb.BidRequest{
31+
Imp: []openrtb.Imp{},
32+
}
33+
mockedBidResponse := &openrtb.BidResponse{}
34+
if currency != nil {
35+
mockedBidResponse.Cur = *currency
36+
}
37+
body, _ := json.Marshal(mockedBidResponse)
38+
responseData := &adapters.ResponseData{
39+
StatusCode: 200,
40+
Body: body,
41+
}
42+
bidResponse, errs := bidder.MakeBids(prebidRequest, nil, responseData)
43+
44+
if errs != nil {
45+
t.Fatalf("Failed to make bids %v", errs)
46+
}
47+
assert.Equal(t, expectedCurrency, bidResponse.Currency)
48+
}

0 commit comments

Comments
 (0)