Skip to content

Commit

Permalink
remove adapter level boolean flag
Browse files Browse the repository at this point in the history
  • Loading branch information
pm-nilesh-chate committed Jun 21, 2022
1 parent 64a4402 commit dd38f70
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 33 deletions.
3 changes: 1 addition & 2 deletions config/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ type AlternateBidderCodes struct {
}

type AdapterAlternateBidderCodes struct {
Enabled bool `mapstructure:"enabled" json:"enabled"`
AllowedBidderCodes []string `mapstructure:"allowedbiddercodes" json:"allowedbiddercodes"`
}

Expand All @@ -256,7 +255,7 @@ func (bidderCodes *AlternateBidderCodes) IsValidBidderCode(bidder, alternateBidd
return false, fmt.Errorf(ErrAlternateBidderNotDefined, bidder, alternateBidder)
}

if !adapterCfg.Enabled || len(adapterCfg.AllowedBidderCodes) == 0 {
if len(adapterCfg.AllowedBidderCodes) == 0 {
return false, fmt.Errorf("alternateBidderCodes disabled for %q, rejecting bids for %q", bidder, alternateBidder)
}

Expand Down
36 changes: 9 additions & 27 deletions config/accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -726,27 +726,27 @@ func TestAlternateBidderCodes_IsValidBidderCode(t *testing.T) {
wantErr error
}{
{
name: "Default alternateBidder is not set/blank",
name: "alternateBidder is not set/blank (default non-extra bid case)",
wantIsValid: true,
},
{
name: "alternateBidder, bidder are same",
name: "alternateBidder and bidder are same (default non-extra bid case with seat's alternateBidder explicitly set)",
args: args{
bidder: "pubmatic",
alternateBidder: "pubmatic",
},
wantIsValid: true,
},
{
name: "alternateBidder disabled at account level or alternateBidder config is not available",
name: "account.alternatebiddercodes config not defined (default, reject bid)",
args: args{
bidder: "pubmatic",
alternateBidder: "groupm",
},
wantIsValid: false,
},
{
name: "alternateBidder enabled at account level, adapter config is not available",
name: "account.alternatebiddercodes config enabled but adapter config not defined",
args: args{
bidder: "pubmatic",
alternateBidder: "groupm",
Expand All @@ -756,30 +756,30 @@ func TestAlternateBidderCodes_IsValidBidderCode(t *testing.T) {
wantErr: errors.New(`alternateBidderCodes not defined for adapter "pubmatic", rejecting bids for "groupm"`),
},
{
name: "alternateBidder enabled at account level, adapter config present, has alternateBidder disabled, or len(allowedBidderCodes)=0",
name: "account.alternatebiddercodes config enabled but adapter config is not available",
args: args{
bidder: "pubmatic",
alternateBidder: "groupm",
},
fields: fields{
Enabled: true,
Adapters: map[string]AdapterAlternateBidderCodes{
"pubmatic": {Enabled: false},
"appnexus": {},
},
},
wantIsValid: false,
wantErr: errors.New(`alternateBidderCodes disabled for "pubmatic", rejecting bids for "groupm"`),
wantErr: errors.New(`alternateBidderCodes not defined for adapter "pubmatic", rejecting bids for "groupm"`),
},
{
name: "alternateBidder enabled at account level, adapter config present, has alternateBidder enabled, allowedBidderCodes empty or not available",
name: "account.alternatebiddercodes config enabled but adapter config has allowedBidderCodes list empty or not defined",
args: args{
bidder: "pubmatic",
alternateBidder: "groupm",
},
fields: fields{
Enabled: true,
Adapters: map[string]AdapterAlternateBidderCodes{
"pubmatic": {Enabled: true},
"pubmatic": {},
},
},
wantIsValid: false,
Expand All @@ -795,7 +795,6 @@ func TestAlternateBidderCodes_IsValidBidderCode(t *testing.T) {
Enabled: true,
Adapters: map[string]AdapterAlternateBidderCodes{
"pubmatic": {
Enabled: true,
AllowedBidderCodes: []string{"*"},
},
},
Expand All @@ -812,7 +811,6 @@ func TestAlternateBidderCodes_IsValidBidderCode(t *testing.T) {
Enabled: true,
Adapters: map[string]AdapterAlternateBidderCodes{
"pubmatic": {
Enabled: true,
AllowedBidderCodes: []string{"groupm"},
},
},
Expand All @@ -829,29 +827,13 @@ func TestAlternateBidderCodes_IsValidBidderCode(t *testing.T) {
Enabled: true,
Adapters: map[string]AdapterAlternateBidderCodes{
"pubmatic": {
Enabled: true,
AllowedBidderCodes: []string{"xyz"},
},
},
},
wantIsValid: false,
wantErr: errors.New(`invalid biddercode "groupm" sent by adapter "pubmatic"`),
},
{
name: "alternateBidder enabled at account level, adapter config present but bidder is not defined in it",
args: args{
bidder: "pubmatic",
alternateBidder: "groupm",
},
fields: fields{
Enabled: true,
Adapters: map[string]AdapterAlternateBidderCodes{
"appnexus": {Enabled: false},
},
},
wantIsValid: false,
wantErr: errors.New(`alternateBidderCodes not defined for adapter "pubmatic", rejecting bids for "groupm"`),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
4 changes: 0 additions & 4 deletions exchange/bidder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2081,7 +2081,6 @@ func TestExtraBid(t *testing.T) {
Enabled: true,
Adapters: map[string]config.AdapterAlternateBidderCodes{
string(openrtb_ext.BidderPubmatic): {
Enabled: true,
AllowedBidderCodes: []string{"groupm"},
},
},
Expand Down Expand Up @@ -2185,7 +2184,6 @@ func TestExtraBidWithAlternateBidderCodeDisabled(t *testing.T) {
Enabled: true,
Adapters: map[string]config.AdapterAlternateBidderCodes{
string(openrtb_ext.BidderPubmatic): {
Enabled: true,
AllowedBidderCodes: []string{"groupm-allowed"},
},
},
Expand Down Expand Up @@ -2286,7 +2284,6 @@ func TestExtraBidWithBidAdjustments(t *testing.T) {
Enabled: true,
Adapters: map[string]config.AdapterAlternateBidderCodes{
string(openrtb_ext.BidderPubmatic): {
Enabled: true,
AllowedBidderCodes: []string{"groupm"},
},
},
Expand Down Expand Up @@ -2389,7 +2386,6 @@ func TestExtraBidWithBidAdjustmentsUsingAdapterCode(t *testing.T) {
Enabled: true,
Adapters: map[string]config.AdapterAlternateBidderCodes{
string(openrtb_ext.BidderPubmatic): {
Enabled: true,
AllowedBidderCodes: []string{"groupm"},
},
},
Expand Down

0 comments on commit dd38f70

Please sign in to comment.