Extracted CurrentUserProvider protocol to simplify dependency injection#1462
Merged
Conversation
…tion A lot of our classes depended on the mutable `IdentityManager`, when in reality they only needed a read-only `currentAppUserID`. This PR changes the requirement, with the following advantages: - Ensure all these classes (`AttributionPoster`, `PurchasesOrchestrator`, `TrialOrIntroPriceEligibiltyChecker`, `BeginRefundRequestHelper`, `ManageSubscriptionsHelper`) cannot logIn / logOut, only read the current user - Simplify tests by only requiring a smaller type - Simplifying instantiation of these types outside the normal `Purchases` initialization. I've also created `MockCurrentUserProvider`, but changed the existing `MockIdentityManager` so that calls to `logIn`/`logOut` just fail. These aren't mocked, and they wouldn't have an impact on the mocked readable values, so calling them is most likely unexpected and should make the test fail.
aboedo
approved these changes
Apr 8, 2022
| do { | ||
| customerInfo = try await self.customerInfoManager.customerInfo( | ||
| appUserID: self.identityManager.currentAppUserID | ||
| appUserID: self.currentUserProvider.currentAppUserID |
Member
There was a problem hiding this comment.
I ❤️ this. Ensuring misuse of an API, even by us, is just fantastic :chefskiss:
NachoSoto
added a commit
that referenced
this pull request
Jun 19, 2022
NachoSoto
added a commit
that referenced
this pull request
Jun 21, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
A lot of our classes depended on the mutable
IdentityManager, when in reality they only needed a read-onlycurrentAppUserID.This PR changes the requirement, with the following advantages:
AttributionPoster,PurchasesOrchestrator,TrialOrIntroPriceEligibiltyChecker,BeginRefundRequestHelper,ManageSubscriptionsHelper) cannot logIn / logOut, only read the current userPurchasesinitialization.I've also created
MockCurrentUserProvider, but changed the existingMockIdentityManagerso that calls tologIn/logOutjust fail. These aren't mocked, and they wouldn't have an impact on the mocked readable values, so calling them is most likely unexpected and should make the test fail.