msgraph-sdk-java-core icon indicating copy to clipboard operation
msgraph-sdk-java-core copied to clipboard

BatchRequestContent's addBatchRequestStep randomize id, which makes it impossible to mock for testing

Open dejan-kosak opened this issue 1 year ago • 3 comments

Hi! I have problem testing my code because of implementation detail of BatchRequestContent.

Method addBatchRequestStep, which is adding RequestInformation into BatchRequestContent, internally generates new UUID. That id is returned from addBatchRequestStep method for furter reference.

All is fine, until you have to mock batch response for testing. That response will contain id which is predefined and unable to match with the one that is generated by the code in runtime.

Greetings!

dejan-kosak avatar Sep 18 '24 13:09 dejan-kosak

Hi @dejan-kosak Thanks for reaching out. Would you mind sharing a code sample of how you're mocking the batch response. I'm thinking it should be possible to build a Response using the returned request IDs but would be curious to see your implementation.

Ndiritu avatar Sep 19 '24 07:09 Ndiritu

Hi, thanks for quick response.

The thing is that I have a testing tool which is based on wiremock with static resource files, mocking the responses from msgraph.

As ids are provided (randomized) by the code without having an option to set id on my own, I cannot match it with my sample responses.

dejan-kosak avatar Sep 19 '24 13:09 dejan-kosak

It would be beneficial if there would be possibility to set id for RequestInformation, which could be later used in addBatchRequestStep to provide id. Randomization of id could still be in place if not provided.

dejan-kosak avatar Sep 23 '24 13:09 dejan-kosak

Hi @dejan-kosak Sorry for the delayed repsonse.

This should be possible using addBatchRequestStep with a BatchRequestStep object

requestContent.addBatchRequestStep(new BatchRequestStep("id", BaseGraphRequestAdapter.<Request>convertToNativeRequest(requestInformation)));

We need to add a constructor overload to BatchRequestStep that accepts RequestInformation. Would you be willing to submit a PR for this?

Ndiritu avatar Nov 24 '24 18:11 Ndiritu

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.