Skip to content

Commit

Permalink
Add test case for currency.
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinGumGum committed Sep 18, 2024
1 parent f481c0d commit 30c7c78
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions adapters/gumgum/gumgum_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package gumgum

import (
"encoding/json"
"testing"

"github.com/prebid/openrtb/v20/openrtb2"
"github.com/prebid/prebid-server/v2/adapters"
"github.com/prebid/prebid-server/v2/adapters/adapterstest"
"github.com/prebid/prebid-server/v2/config"
"github.com/prebid/prebid-server/v2/openrtb_ext"
"github.com/stretchr/testify/assert"
)

func TestJsonSamples(t *testing.T) {
Expand All @@ -18,3 +22,59 @@ func TestJsonSamples(t *testing.T) {

adapterstest.RunJSONBidderTest(t, "gumgumtest", bidder)
}

func TestResponseWithCurrencies(t *testing.T) {
// Test for USD currency
assertCurrencyInBidResponse(t, "USD", "USD")

// Test for EUR currency
assertCurrencyInBidResponse(t, "EUR", "EUR")
}

func assertCurrencyInBidResponse(t *testing.T, expectedCurrency string, currency string) {
// Create a GumGum bidder
bidder, buildErr := Builder(openrtb_ext.BidderGumGum, config.Adapter{
Endpoint: "https://g2.gumgum.com/providers/prbds2s/bid"}, config.Server{
ExternalUrl: "http://hosturl.com",
GvlID: 1,
DataCenter: "2",
})

if buildErr != nil {
t.Fatalf("Builder returned unexpected error %v", buildErr)
}

// Create a mock BidRequest
prebidRequest := &openrtb2.BidRequest{
Imp: []openrtb2.Imp{},
}

// Create a mock BidResponse with or without currency
mockedBidResponse := &openrtb2.BidResponse{}
if currency != "" {
mockedBidResponse.Cur = currency
}

// Marshal the mock bid response to JSON
body, err := json.Marshal(mockedBidResponse)
if err != nil {
t.Fatalf("Failed to marshal mock bid response: %v", err)
}

// Create a mock ResponseData
responseData := &adapters.ResponseData{
StatusCode: 200,
Body: body,
}

// Call MakeBids
bidResponse, errs := bidder.MakeBids(prebidRequest, nil, responseData)

// Assert no errors
if len(errs) != 0 {
t.Fatalf("Failed to make bids %v", errs)
}

// Assert that the currency is correctly set
assert.Equal(t, expectedCurrency, bidResponse.Currency, "Expected currency to be set to "+expectedCurrency)
}

0 comments on commit 30c7c78

Please sign in to comment.