Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allowed $0.00 price bids if there are deals #1910

Merged
merged 2 commits into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions exchange/bidder_validate_bids.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,11 @@ func validateBid(bid *pbsOrtbBid) (bool, error) {
if bid.bid.ImpID == "" {
return false, fmt.Errorf("Bid \"%s\" missing required field 'impid'", bid.bid.ID)
}
if bid.bid.Price <= 0.0 {
return false, fmt.Errorf("Bid \"%s\" does not contain a positive 'price'", bid.bid.ID)
if bid.bid.Price < 0.0 {
return false, fmt.Errorf("Bid \"%s\" does not contain a positive (or zero if there is a deal) 'price'", bid.bid.ID)
}
if bid.bid.Price <= 0.0 && bid.bid.DealID == "" {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be able to have 'bid.bid.Price == 0.0 && bid.bid.DealID', I don't think it is possible for both 'x < 0.0' and 'x == 0.0' to be false yet 'x <= 0.0' be true.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah that makes sense. Will update!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just updated!

return false, fmt.Errorf("Bid \"%s\" does not contain a zero or positive 'price' and there is no deal set for this bid", bid.bid.ID)
}
if bid.bid.CrID == "" {
return false, fmt.Errorf("Bid \"%s\" missing creative ID", bid.bid.ID)
Expand Down
44 changes: 40 additions & 4 deletions exchange/bidder_validate_bids_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,20 @@ func TestAllValidBids(t *testing.T) {
CrID: "789",
},
},
{
bid: &openrtb2.Bid{
ID: "zeroPriceBid",
ImpID: "444",
Price: 0.00,
CrID: "555",
DealID: "777",
},
},
},
},
})
seatBid, errs := bidder.requestBid(context.Background(), &openrtb2.BidRequest{}, openrtb_ext.BidderAppnexus, 1.0, currency.NewConstantRates(), &adapters.ExtraRequestInfo{}, true, false)
assert.Len(t, seatBid.bids, 3)
assert.Len(t, seatBid.bids, 4)
assert.Len(t, errs, 0)
}

Expand Down Expand Up @@ -79,13 +88,22 @@ func TestAllBadBids(t *testing.T) {
CrID: "blah",
},
},
{
bid: &openrtb2.Bid{
ID: "zeroPriceBidNoDeal",
ImpID: "444",
Price: 0.00,
CrID: "555",
DealID: "",
},
},
{},
},
},
})
seatBid, errs := bidder.requestBid(context.Background(), &openrtb2.BidRequest{}, openrtb_ext.BidderAppnexus, 1.0, currency.NewConstantRates(), &adapters.ExtraRequestInfo{}, true, false)
assert.Len(t, seatBid.bids, 0)
assert.Len(t, errs, 5)
assert.Len(t, errs, 6)
}

func TestMixedBids(t *testing.T) {
Expand Down Expand Up @@ -122,13 +140,31 @@ func TestMixedBids(t *testing.T) {
CrID: "blah",
},
},
{
bid: &openrtb2.Bid{
ID: "zeroPriceBid",
ImpID: "444",
Price: 0.00,
CrID: "555",
DealID: "777",
},
},
{
bid: &openrtb2.Bid{
ID: "zeroPriceBidNoDeal",
ImpID: "444",
Price: 0.00,
CrID: "555",
DealID: "",
},
},
{},
},
},
})
seatBid, errs := bidder.requestBid(context.Background(), &openrtb2.BidRequest{}, openrtb_ext.BidderAppnexus, 1.0, currency.NewConstantRates(), &adapters.ExtraRequestInfo{}, true, false)
assert.Len(t, seatBid.bids, 2)
assert.Len(t, errs, 3)
assert.Len(t, seatBid.bids, 3)
assert.Len(t, errs, 4)
}

func TestCurrencyBids(t *testing.T) {
Expand Down