-
Notifications
You must be signed in to change notification settings - Fork 769
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
Reject request if stored auction or stored bid response not found #2691
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -590,6 +590,216 @@ func TestProcessStoredAuctionAndBidResponses(t *testing.T) { | |
|
||
} | ||
|
||
func TestProcessStoredResponsesNotFoundResponse(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it'd be nice to have one test case where we expect no errors with valid stored response information. What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, agree. It exists already: |
||
bidderMap := map[string]openrtb_ext.BidderName{"bidderA": "bidderA", "bidderB": "bidderB"} | ||
bidStoredResp1 := json.RawMessage(`[{"bid": [{"id": "bid_id1"],"seat": "bidderA"}]`) | ||
bidStoredResp2 := json.RawMessage(`[{"bid": [{"id": "bid_id2"],"seat": "bidderB"}]`) | ||
mockStoredResponses := map[string]json.RawMessage{ | ||
"1": bidStoredResp1, | ||
"2": bidStoredResp2, | ||
"3": nil, | ||
"4": nil, | ||
} | ||
fetcher := &mockStoredBidResponseFetcher{mockStoredResponses} | ||
|
||
testCases := []struct { | ||
description string | ||
requestJson []byte | ||
expectedErrors []error | ||
}{ | ||
{ | ||
description: "Stored bid response with nil data, one bidder one imp", | ||
requestJson: []byte(`{"imp": [ | ||
{ | ||
"id": "imp-id1", | ||
"ext": { | ||
"appnexus": { | ||
"placementId": 123 | ||
}, | ||
"prebid": { | ||
"storedbidresponse": [ | ||
{"bidder":"bidderB", "id": "3"} | ||
] | ||
} | ||
} | ||
} | ||
]}`), | ||
expectedErrors: []error{ | ||
errors.New("failed to fetch stored bid response for impId = imp-id1, bidder = bidderB and storedBidResponse id = 3"), | ||
}, | ||
}, | ||
{ | ||
description: "Stored bid response with nil data, one bidder, two imps, one with correct stored response", | ||
requestJson: []byte(`{"imp": [ | ||
{ | ||
"id": "imp-id1", | ||
"ext": { | ||
"appnexus": { | ||
"placementId": 123 | ||
}, | ||
"prebid": { | ||
"storedbidresponse": [ | ||
{"bidder":"bidderB", "id": "1"} | ||
] | ||
} | ||
} | ||
}, | ||
{ | ||
"id": "imp-id2", | ||
"ext": { | ||
"appnexus": { | ||
"placementId": 123 | ||
}, | ||
"prebid": { | ||
"storedbidresponse": [ | ||
{"bidder":"bidderB", "id": "3"} | ||
] | ||
} | ||
} | ||
} | ||
]}`), | ||
expectedErrors: []error{ | ||
errors.New("failed to fetch stored bid response for impId = imp-id2, bidder = bidderB and storedBidResponse id = 3"), | ||
}, | ||
}, | ||
{ | ||
description: "Stored bid response with nil data, one bidder, two imps, both with correct stored response", | ||
requestJson: []byte(`{"imp": [ | ||
{ | ||
"id": "imp-id1", | ||
"ext": { | ||
"appnexus": { | ||
"placementId": 123 | ||
}, | ||
"prebid": { | ||
"storedbidresponse": [ | ||
{"bidder":"bidderB", "id": "4"} | ||
] | ||
} | ||
} | ||
}, | ||
{ | ||
"id": "imp-id2", | ||
"ext": { | ||
"appnexus": { | ||
"placementId": 123 | ||
}, | ||
"prebid": { | ||
"storedbidresponse": [ | ||
{"bidder":"bidderB", "id": "3"} | ||
] | ||
} | ||
} | ||
} | ||
]}`), | ||
expectedErrors: []error{ | ||
errors.New("failed to fetch stored bid response for impId = imp-id1, bidder = bidderB and storedBidResponse id = 4"), | ||
errors.New("failed to fetch stored bid response for impId = imp-id2, bidder = bidderB and storedBidResponse id = 3"), | ||
}, | ||
}, | ||
{ | ||
description: "Stored auction response with nil data and one imp", | ||
requestJson: []byte(`{"imp": [ | ||
{ | ||
"id": "imp-id1", | ||
"ext": { | ||
"appnexus": { | ||
"placementId": 123 | ||
}, | ||
"prebid": { | ||
"storedauctionresponse": { | ||
"id": "4" | ||
} | ||
} | ||
} | ||
} | ||
]}`), | ||
expectedErrors: []error{ | ||
errors.New("failed to fetch stored auction response for impId = imp-id1 and storedAuctionResponse id = 4"), | ||
}, | ||
}, | ||
{ | ||
description: "Stored auction response with nil data, and two imps with nil responses", | ||
requestJson: []byte(`{"imp": [ | ||
{ | ||
"id": "imp-id1", | ||
"ext": { | ||
"appnexus": { | ||
"placementId": 123 | ||
}, | ||
"prebid": { | ||
"storedauctionresponse": { | ||
"id": "4" | ||
} | ||
} | ||
} | ||
}, | ||
{ | ||
"id": "imp-id2", | ||
"ext": { | ||
"appnexus": { | ||
"placementId": 123 | ||
}, | ||
"prebid": { | ||
"storedauctionresponse": { | ||
"id": "3" | ||
} | ||
} | ||
} | ||
} | ||
]}`), | ||
expectedErrors: []error{ | ||
errors.New("failed to fetch stored auction response for impId = imp-id1 and storedAuctionResponse id = 4"), | ||
errors.New("failed to fetch stored auction response for impId = imp-id2 and storedAuctionResponse id = 3"), | ||
}, | ||
}, | ||
{ | ||
description: "Stored auction response with nil data, two imps, one with nil responses", | ||
requestJson: []byte(`{"imp": [ | ||
{ | ||
"id": "imp-id1", | ||
"ext": { | ||
"appnexus": { | ||
"placementId": 123 | ||
}, | ||
"prebid": { | ||
"storedauctionresponse": { | ||
"id": "2" | ||
} | ||
} | ||
} | ||
}, | ||
{ | ||
"id": "imp-id2", | ||
"ext": { | ||
"appnexus": { | ||
"placementId": 123 | ||
}, | ||
"prebid": { | ||
"storedauctionresponse": { | ||
"id": "3" | ||
} | ||
} | ||
} | ||
} | ||
]}`), | ||
expectedErrors: []error{ | ||
errors.New("failed to fetch stored auction response for impId = imp-id2 and storedAuctionResponse id = 3"), | ||
}, | ||
}, | ||
} | ||
|
||
for _, test := range testCases { | ||
storedAuctionResponses, storedBidResponses, bidderImpReplaceImpId, errorList := ProcessStoredResponses(nil, test.requestJson, fetcher, bidderMap) | ||
for _, err := range test.expectedErrors { | ||
assert.Contains(t, errorList, err, "incorrect errors returned: %s", test.description) | ||
} | ||
assert.Nil(t, storedAuctionResponses, "storedAuctionResponses doesn't match: %s\n", test.description) | ||
assert.Nil(t, storedBidResponses, "storedBidResponses doesn't match: %s\n", test.description) | ||
assert.Nil(t, bidderImpReplaceImpId, "bidderImpReplaceImpId doesn't match: %s\n", test.description) | ||
} | ||
} | ||
|
||
func TestFlipMap(t *testing.T) { | ||
testCases := []struct { | ||
description string | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm trying to think of a way to shorten the variable names. I'm thinking you could remove the word bid from both of these variables and shorten the word response to be resp, so they'd change to
impBidderToStoredResp
andimpBidderToStoredRespId
. And we can leverage the name of the function to know that the variables passed in are stored bid responses. What do you think?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, modified parameters names. About functions names those are two different:
validateStoredBidResponses
andvalidateStoredAuctionResponses
. I'm open to rename it something that looks better.