|
1 | 1 | package openx
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "encoding/json" |
4 | 5 | "testing"
|
5 | 6 |
|
| 7 | + "github.com/mxmCherry/openrtb" |
| 8 | + "github.com/prebid/prebid-server/adapters" |
6 | 9 | "github.com/prebid/prebid-server/adapters/adapterstest"
|
| 10 | + "github.com/stretchr/testify/assert" |
7 | 11 | )
|
8 | 12 |
|
9 | 13 | func TestJsonSamples(t *testing.T) {
|
10 | 14 | adapterstest.RunJSONBidderTest(t, "openxtest", NewOpenxBidder("http://rtb.openx.net/prebid"))
|
11 | 15 | }
|
| 16 | + |
| 17 | +func TestResponseWithCurrencies(t *testing.T) { |
| 18 | + assertCurrencyInBidResponse(t, "USD", nil) |
| 19 | + |
| 20 | + currency := "USD" |
| 21 | + assertCurrencyInBidResponse(t, "USD", ¤cy) |
| 22 | + |
| 23 | + currency = "EUR" |
| 24 | + assertCurrencyInBidResponse(t, "EUR", ¤cy) |
| 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