Skip to content

Extracted CurrentUserProvider protocol to simplify dependency injection#1462

Merged
NachoSoto merged 1 commit into
mainfrom
current-user-provider
Apr 8, 2022
Merged

Extracted CurrentUserProvider protocol to simplify dependency injection#1462
NachoSoto merged 1 commit into
mainfrom
current-user-provider

Conversation

@NachoSoto

Copy link
Copy Markdown
Contributor

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.

…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.
do {
customerInfo = try await self.customerInfoManager.customerInfo(
appUserID: self.identityManager.currentAppUserID
appUserID: self.currentUserProvider.currentAppUserID

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I ❤️ this. Ensuring misuse of an API, even by us, is just fantastic :chefskiss:

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.

2 participants