Skip to content

Commit

Permalink
What should happen if subscription exists, but payment starts much later
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiask committed Feb 22, 2019
1 parent bcc90f9 commit b8142b9
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/testapp/test_subscriptions.py
@@ -1,6 +1,7 @@
from datetime import date, timedelta

from django.contrib.auth.models import User
from django.db.models import Q
from django.test import Client, TestCase
from django.utils import timezone
from django.utils.translation import deactivate_all
Expand Down Expand Up @@ -545,3 +546,31 @@ def test_banktransfer_failed(self):
self.assertEqual(subscription.paid_until, date(2017, 12, 31))

self.assertEqual(payment.lineitems.count(), 0)

def test_create_subscription_start_paying_later(self):
subscription = Subscription.objects.ensure(
user=self.user,
code="test1",
title="Test subscription 1",
periodicity="monthly",
amount=60,
starts_on=date(2018, 1, 1),
)
today = date(2019, 1, 15)
subscription.create_periods(until=today)
self.assertEqual(subscription.paid_until, date(2017, 12, 31))

SubscriptionPeriod.objects.create_line_items()

payment = Payment.objects.create_pending(user=self.user)
self.assertEqual(payment.amount, 780)
payment.cancel_pending()

LineItem.objects.filter(
id__in=subscription.periods.filter(
~Q(id__in=subscription.periods.paid()), Q(ends_on__lt=today)
).values("line_item")
).update(amount=0)

payment = Payment.objects.create_pending(user=self.user)
self.assertEqual(payment.amount, 60)

0 comments on commit b8142b9

Please sign in to comment.