Skip to content

Commit

Permalink
feat(aduptech): check target currency in Builder
Browse files Browse the repository at this point in the history
  • Loading branch information
danygielow committed Jan 28, 2025
1 parent 37adf42 commit 09f4c2c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
11 changes: 9 additions & 2 deletions adapters/aduptech/aduptech.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import (
"github.com/prebid/openrtb/v20/openrtb2"
"github.com/prebid/prebid-server/v3/adapters"
"github.com/prebid/prebid-server/v3/config"
"github.com/prebid/prebid-server/v3/currency"
prebidcurrency "github.com/prebid/prebid-server/v3/currency"
"github.com/prebid/prebid-server/v3/errortypes"
"github.com/prebid/prebid-server/v3/openrtb_ext"
"github.com/prebid/prebid-server/v3/util/jsonutil"
"golang.org/x/text/currency"
)

type adapter struct {
Expand All @@ -34,6 +35,12 @@ func Builder(bidderName openrtb_ext.BidderName, config config.Adapter, server co
return nil, errors.New("invalid extra info: TargetCurrency is empty, pls check")
}

parsedCurrency, err := currency.ParseISO(extraInfo.TargetCurrency)
if err != nil {
return nil, fmt.Errorf("invalid extra info: invalid TargetCurrency %s, pls check", extraInfo.TargetCurrency)
}
extraInfo.TargetCurrency = parsedCurrency.String()

bidder := &adapter{
endpoint: config.Endpoint,
extraInfo: extraInfo,
Expand Down Expand Up @@ -81,7 +88,7 @@ func (a *adapter) convertCurrency(value float64, cur string, reqInfo *adapters.E
convertedValue, err := reqInfo.ConvertCurrency(value, cur, a.extraInfo.TargetCurrency)

if err != nil {
var convErr currency.ConversionNotFoundError
var convErr prebidcurrency.ConversionNotFoundError
if !errors.As(err, &convErr) {
return 0, err
}
Expand Down
17 changes: 17 additions & 0 deletions adapters/aduptech/aduptech_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,20 @@ func TestInvalidExtraAdapterInfo(t *testing.T) {

assert.EqualError(t, buildErr, "invalid extra info: TargetCurrency is empty, pls check")
}

func TestInvalidTargetCurrency(t *testing.T) {
_, buildErr := Builder(
openrtb_ext.BidderAdUpTech,
config.Adapter{
Endpoint: "https://example.com/rtb/bid",
ExtraAdapterInfo: `{"target_currency": "INVALID"}`,
},
config.Server{
ExternalUrl: "http://hosturl.com",
GvlID: 1,
DataCenter: "2",
},
)

assert.EqualError(t, buildErr, "invalid extra info: invalid TargetCurrency INVALID, pls check")
}

0 comments on commit 09f4c2c

Please sign in to comment.