Add monetization app with RevenueCat webhooks alongside Stripe.
Rename finance → monetization (keep finance_* tables via app label), add RevenueCat webhook + ledger upserts so store IAP syncs subscriptions and billing history like Stripe. Companion to chat_web_app#100 / #68.
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
"""Tests for finance Invoice / Payment models and admin registration."""
|
||||
|
||||
from django.contrib import admin
|
||||
from django.test import TestCase
|
||||
|
||||
from chat_backend.tests.factories import make_company, make_user
|
||||
from monetization.models import Invoice, Payment
|
||||
|
||||
|
||||
class InvoicePaymentModelTestCase(TestCase):
|
||||
def setUp(self):
|
||||
self.company = make_company()
|
||||
self.user = make_user(company=self.company)
|
||||
|
||||
def test_create_invoice_and_payment(self):
|
||||
invoice = Invoice.objects.create(
|
||||
user=self.user,
|
||||
company=self.company,
|
||||
status=Invoice.Status.OPEN,
|
||||
amount_due=1000,
|
||||
currency="usd",
|
||||
stripe_checkout_session_id="cs_test_1",
|
||||
)
|
||||
payment = Payment.objects.create(
|
||||
user=self.user,
|
||||
company=self.company,
|
||||
invoice=invoice,
|
||||
amount=1000,
|
||||
currency="usd",
|
||||
status=Payment.Status.PENDING,
|
||||
stripe_payment_intent_id="pi_test_1",
|
||||
)
|
||||
self.assertEqual(invoice.provider, Invoice.Provider.STRIPE)
|
||||
self.assertEqual(payment.invoice_id, invoice.pk)
|
||||
self.assertEqual(Invoice.objects.count(), 1)
|
||||
self.assertEqual(Payment.objects.count(), 1)
|
||||
|
||||
def test_mark_payment_succeeded(self):
|
||||
payment = Payment.objects.create(
|
||||
user=self.user,
|
||||
amount=1000,
|
||||
stripe_payment_intent_id="pi_test_2",
|
||||
)
|
||||
payment.mark_succeeded()
|
||||
payment.refresh_from_db()
|
||||
self.assertEqual(payment.status, Payment.Status.SUCCEEDED)
|
||||
self.assertIsNotNone(payment.paid_at)
|
||||
|
||||
def test_unique_stripe_checkout_session_id(self):
|
||||
Invoice.objects.create(
|
||||
user=self.user,
|
||||
stripe_checkout_session_id="cs_unique",
|
||||
amount_due=1000,
|
||||
)
|
||||
with self.assertRaises(Exception):
|
||||
Invoice.objects.create(
|
||||
user=self.user,
|
||||
stripe_checkout_session_id="cs_unique",
|
||||
amount_due=1000,
|
||||
)
|
||||
|
||||
|
||||
class FinanceAdminRegistrationTestCase(TestCase):
|
||||
def test_invoice_and_payment_registered(self):
|
||||
self.assertIn(Invoice, admin.site._registry)
|
||||
self.assertIn(Payment, admin.site._registry)
|
||||
Reference in New Issue
Block a user