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

Commit

Permalink
openx adapter: forward bid response currency in openx adapter if set (p…
Browse files Browse the repository at this point in the history
…rebid#1211)

it was always set to the default USD before
  • Loading branch information
SyntaxNode authored Mar 4, 2020
1 parent 4b6cf61 commit 1c0ea7a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
5 changes: 5 additions & 0 deletions adapters/openx/openx.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ func (a *OpenxAdapter) MakeBids(internalRequest *openrtb.BidRequest, externalReq

bidResponse := adapters.NewBidderResponseWithBidsCapacity(5)

// overrride default currency
if bidResp.Cur != "" {
bidResponse.Currency = bidResp.Cur
}

for _, sb := range bidResp.SeatBid {
for i := range sb.Bid {
bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{
Expand Down
37 changes: 37 additions & 0 deletions adapters/openx/openx_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,48 @@
package openx

import (
"encoding/json"
"testing"

"github.com/mxmCherry/openrtb"
"github.com/prebid/prebid-server/adapters"
"github.com/prebid/prebid-server/adapters/adapterstest"
"github.com/stretchr/testify/assert"
)

func TestJsonSamples(t *testing.T) {
adapterstest.RunJSONBidderTest(t, "openxtest", NewOpenxBidder("http://rtb.openx.net/prebid"))
}

func TestResponseWithCurrencies(t *testing.T) {
assertCurrencyInBidResponse(t, "USD", nil)

currency := "USD"
assertCurrencyInBidResponse(t, "USD", &currency)

currency = "EUR"
assertCurrencyInBidResponse(t, "EUR", &currency)
}

func assertCurrencyInBidResponse(t *testing.T, expectedCurrency string, currency *string) {

bidder := NewOpenxBidder("http://rtb.openx.net/prebid")
prebidRequest := &openrtb.BidRequest{
Imp: []openrtb.Imp{},
}
mockedBidResponse := &openrtb.BidResponse{}
if currency != nil {
mockedBidResponse.Cur = *currency
}
body, _ := json.Marshal(mockedBidResponse)
responseData := &adapters.ResponseData{
StatusCode: 200,
Body: body,
}
bidResponse, errs := bidder.MakeBids(prebidRequest, nil, responseData)

if errs != nil {
t.Fatalf("Failed to make bids %v", errs)
}
assert.Equal(t, expectedCurrency, bidResponse.Currency)
}

0 comments on commit 1c0ea7a

Please sign in to comment.