[Identity] Refactoring the HTTP request mocking to be easier to understand in context #19824
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Checklists
Packages impacted by this PR:
Identity.
Issues associated with this PR:
Fixes #19420
Describe the problem that is addressed by this PR:
Identity tests rely on some functions that mock the internals of our HTTP clients to extract the outgoing requests and responses, so that we can mock the responses, and later match the network behavior based to our expectations. These functions are rather complex at the moment.
What are the possible designs available to address the problem
Refactoring in my mind means minimal efforts that slowly reduce technical debt over time.
With that in mind, I think the most immediate way to improve this design is to move it from a closure to a class.
Closures are not that common in our SDK, in comparison to classes, which are everywhere.
Classes also help identify the context from which the variable come better than closures (the
this.name
is easier to contextualize than justname
).My intuition tells me there are many more improvements I could make, but I don’t know how much time it will take me, so I am budgeting this PR to be the fastest approach that could yield a meaningful improvement rather than a thorough overwrite.