tests: Test the case where Customer exists but stripe_customer_id is None.

This commit is contained in:
Vishnu KS 2020-03-12 16:09:10 +05:30 committed by Tim Abbott
parent 388384e894
commit 96eb1bcd9d
1 changed files with 17 additions and 7 deletions

View File

@ -1138,16 +1138,26 @@ class BillingHelpersTest(ZulipTestCase):
returned = update_or_create_stripe_customer(user, stripe_token='token')
mocked1.assert_called()
self.assertEqual(returned, 'returned')
# Customer exists, replace payment source
customer = Customer.objects.create(realm=get_realm('zulip'), stripe_customer_id='cus_12345')
with patch('corporate.lib.stripe.do_replace_payment_source') as mocked2:
returned_customer = update_or_create_stripe_customer(self.example_user('hamlet'), 'token')
customer = Customer.objects.create(realm=get_realm('zulip'))
# Customer exists but stripe_customer_id is None
with patch('corporate.lib.stripe.do_create_stripe_customer', return_value='returned') as mocked2:
returned = update_or_create_stripe_customer(user, stripe_token='token')
mocked2.assert_called()
self.assertEqual(returned_customer, customer)
# Customer exists, do nothing
self.assertEqual(returned, 'returned')
customer.stripe_customer_id = 'cus_12345'
customer.save()
# Customer exists, replace payment source
with patch('corporate.lib.stripe.do_replace_payment_source') as mocked3:
returned_customer = update_or_create_stripe_customer(self.example_user('hamlet'), 'token')
mocked3.assert_called()
self.assertEqual(returned_customer, customer)
# Customer exists, do nothing
with patch('corporate.lib.stripe.do_replace_payment_source') as mocked4:
returned_customer = update_or_create_stripe_customer(self.example_user('hamlet'), None)
mocked3.assert_not_called()
mocked4.assert_not_called()
self.assertEqual(returned_customer, customer)
def test_get_customer_by_realm(self) -> None: