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

Reject request if stored auction or stored bid response not found #2691

Merged
merged 3 commits into from
Apr 18, 2023

Conversation

VeronikaSolovei9
Copy link
Contributor

Fix for #2487

Copy link
Contributor

@AlexBVolcy AlexBVolcy left a comment

Choose a reason for hiding this comment

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

Looks good, just left a couple of comments

@@ -590,6 +590,216 @@ func TestProcessStoredAuctionAndBidResponses(t *testing.T) {

}

func TestProcessStoredResponsesNotFoundResponse(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, agree. It exists already: TestProcessStoredAuctionAndBidResponses. Before this change we didn't throw an error and this functionality is covered. With this change valid cases are still valid and this specific test was added to cover error cases only.

return errs
}

func validateStoredBidResponses(impBidderToStoredBidResponse ImpBidderStoredResp, impBidderToStoredBidResponseId ImpBiddersWithBidResponseIDs) []error {
Copy link
Contributor

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 and impBidderToStoredRespId. And we can leverage the name of the function to know that the variables passed in are stored bid responses. What do you think?

Copy link
Contributor Author

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 and validateStoredAuctionResponses. I'm open to rename it something that looks better.

Copy link
Contributor

@guscarreon guscarreon left a comment

Choose a reason for hiding this comment

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

As discussed offline, we could check the lengths of the json.RawMessage elements in the buildStoredResponsesMaps function so we don't have to traverse impIdToStoredResp and impBidderToStoredBidResponse again downstream inside functions validateStoredAuctionResponses and validateStoredBidResponses. WIth this change, we gould get rid of said funtions entirely

204 - func buildStoredResponsesMaps(storedResponses StoredResponseIdToStoredResponse, impBidderToStoredBidResponseId ImpBiddersWithBidResponseIDs, impIdToRespId ImpsWithAuctionResponseIDs) (ImpsWithBidResponses, ImpBidderStoredResp) {
    + func buildStoredResponsesMaps(storedResponses StoredResponseIdToStoredResponse, impBidderToStoredBidResponseId ImpBiddersWithBidResponseIDs, impIdToRespId ImpsWithAuctionResponseIDs) (ImpsWithBidResponses, ImpBidderStoredResp, []error) {
205       //imp id to stored resp body
206       impIdToStoredResp := ImpsWithBidResponses{}
207       //stored bid responses: imp id to bidder to stored response body
208       impBidderToStoredBidResponse := ImpBidderStoredResp{}
    +     var errs []error
209
210       for impId, respId := range impIdToRespId {
    +         // This is equivalent to the `len(data) == 0` check inside `validateStoredAuctionResponses`
    +         // we can append to an error array here and get rid of `validateStoredAuctionResponses` entirely
    +         if len(storedResponses[respId]) == 0 {
    +             errs = append(errs, fmt.Errorf("failed to fetch stored auction response for impId = %s and storedAuctionResponse id = %s", impId, respId))
    +         }
211           impIdToStoredResp[impId] = storedResponses[respId]
212       }
213
214       for impId, bidderStoredResp := range impBidderToStoredBidResponseId {
215           bidderStoredResponses := StoredResponseIdToStoredResponse{}
216           for bidderName, id := range bidderStoredResp {
    +             // Same thing here: this check is equivalent to the `len(data) == 0` inside `validateStoredBidResponses`
    +             if len(storedResponses[id]) == 0 {
    +                 errs = append(errs, fmt.Errorf("failed to fetch stored auction response for impId = %s and storedAuctionResponse id = %s", impId, respId))
    +             }
217               bidderStoredResponses[bidderName] = storedResponses[id]
218           }
219           impBidderToStoredBidResponse[impId] = bidderStoredResponses
220       }
221 -     return impIdToStoredResp, impBidderToStoredBidResponse
    +     return impIdToStoredResp, impBidderToStoredBidResponse, errs
222   }
stored_responses/stored_responses.go

@VeronikaSolovei9
Copy link
Contributor Author

@guscarreon Good point Gus, I refactored functions as discussed. Looks cleaner now. Please re-review

Copy link
Contributor

@AlexBVolcy AlexBVolcy left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@guscarreon guscarreon left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants