Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Activate user who fired trial on trial expiration #101

Merged
merged 3 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions database/models/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class Owner(CodecovBaseModel):
trial_start_date = Column(types.DateTime, server_default=FetchedValue())
trial_end_date = Column(types.DateTime, server_default=FetchedValue())
trial_status = Column(types.Text, server_default=FetchedValue())
trial_fired_by = Column(types.Integer, server_default=FetchedValue())
Copy link
Contributor

Choose a reason for hiding this comment

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

is this column already in the database?

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess this value is set from the API side when the trial is activated?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes yes

plan = Column(types.Text, server_default=FetchedValue())
plan_user_count = Column(types.SmallInteger, server_default=FetchedValue())
pretrial_users_count = Column(types.SmallInteger, server_default=FetchedValue())
Expand Down
1 change: 1 addition & 0 deletions database/tests/factories/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class Meta:
trial_start_date = datetime.now()
trial_end_date = datetime.now()
trial_status = enums.TrialStatus.NOT_STARTED.value
trial_fired_by = None

oauth_token = factory.LazyAttribute(
lambda o: encrypt_oauth_token(o.unencrypted_oauth_token)
Expand Down
14 changes: 14 additions & 0 deletions tasks/tests/unit/test_trial_expiration.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,17 @@ async def test_trial_expiration_task_without_pretrial_users_count(
assert owner.plan_user_count == 1
assert owner.stripe_subscription_id == None
assert owner.trial_status == TrialStatus.EXPIRED.value

@pytest.mark.asyncio
async def test_trial_expiration_task_with_trial_fired_by(self, dbsession, mocker):
owner = OwnerFactory.create(trial_fired_by=9)
dbsession.add(owner)
dbsession.flush()

task = TrialExpirationTask()
assert await task.run_async(dbsession, owner.ownerid) == {"successful": True}

assert owner.plan == BillingPlan.users_basic.value
assert owner.plan_activated_users == [9]
assert owner.stripe_subscription_id == None
assert owner.trial_status == TrialStatus.EXPIRED.value
4 changes: 3 additions & 1 deletion tasks/trial_expiration.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ async def run_async(self, db_session, ownerid, *args, **kwargs):
"Expiring owner's trial and setting back to basic plan", extra=log_extra
)
owner.plan = BillingPlan.users_basic.value
owner.plan_activated_users = None
owner.plan_activated_users = (
[owner.trial_fired_by] if owner.trial_fired_by else None
)
owner.plan_user_count = owner.pretrial_users_count or 1
owner.stripe_subscription_id = None
owner.trial_status = TrialStatus.EXPIRED.value
Expand Down