Skip to content

Commit

Permalink
Fix strategy when no active subscription detected
Browse files Browse the repository at this point in the history
  • Loading branch information
UncleGoogle committed Jan 17, 2022
1 parent 53a315a commit 2f52488
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/active_month_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
class ActiveMonthInfoByUser(t.NamedTuple):
machine_name: str
'''
Treats two bussines cases as True: owning active month content AND not owning yet, but having the payment scheduled
Treats two bussines cases the same way:
having active month content AND not owning yet, but having payment scheduled
https://support.humblebundle.com/hc/en-us/articles/217300487-Humble-Choice-Early-Unlock-Games
'''
is_or_will_be_owned: bool
Expand All @@ -24,12 +25,11 @@ class _CantFetchActiveMonthInfo(Exception):


class ActiveMonthResolver():

def __init__(self, has_active_subscription: bool) -> None:
if has_active_subscription:
fetch_strategy = _get_ami_from_subscriber_fallbacking_to_marketing
else:
fetch_strategy = _get_ami_from_subscriber
fetch_strategy = _get_ami_from_marketing
self._fetch_strategy: ActiveMonthInfoFetchStrategy = fetch_strategy

async def resolve(self, api: AuthorizedHumbleAPI) -> ActiveMonthInfoByUser:
Expand Down
6 changes: 5 additions & 1 deletion tests/common/test_subscriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from conftest import aiter
import pytest

from webservice import WebpackParseError


pytestmark = pytest.mark.asyncio

Expand Down Expand Up @@ -49,6 +51,7 @@ async def test_get_subscriptions_never_subscribed(plugin, api_mock):
""")
api_mock.get_user_subscription_state.return_value = subscription_state
api_mock.get_subscription_products_with_gamekeys = MagicMock(return_value=aiter([]))
api_mock.get_subscriber_hub_data.side_effect = WebpackParseError()

res = await plugin.get_subscriptions()

Expand Down Expand Up @@ -136,8 +139,8 @@ async def test_get_subscriptions_past_subscriber(api_mock, plugin):
"""
Testcase: Currently no subscription but user was subscriber in the past
Expected: owned months and additionally not owned active month
Note: I didn't check how exactly real subscription state json looks like in that case
"""
# TODO: check how real subscription state json looks like in that case
subscription_state = json.loads("""
{
"canResubscribe": true,
Expand All @@ -154,6 +157,7 @@ async def test_get_subscriptions_past_subscriber(api_mock, plugin):
]
api_mock.get_user_subscription_state.return_value = subscription_state
api_mock.get_subscription_products_with_gamekeys = MagicMock(return_value=aiter(content_choice_options))
api_mock.get_subscriber_hub_data.side_effect = WebpackParseError()

res = await plugin.get_subscriptions()

Expand Down

0 comments on commit 2f52488

Please sign in to comment.