Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
test: Update webhooks processing test with voucher to check for Order
Browse files Browse the repository at this point in the history
  • Loading branch information
julianajlk committed May 10, 2024
1 parent fc8dee5 commit 58cd341
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions ecommerce/extensions/payment/tests/processors/test_webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
Applicator = get_class('offer.applicator', 'Applicator')
BillingAddress = get_model('order', 'BillingAddress')
Country = get_model('address', 'Country')
Order = get_model('order', 'Order')
OrderNumberGenerator = get_class('order.utils', 'OrderNumberGenerator')


Expand Down Expand Up @@ -145,10 +146,16 @@ def test_issue_credit_error(self):
"""
self.skipTest('Webhooks payments processor does not yet support issuing credit.')

@mock.patch('ecommerce.extensions.checkout.mixins.EdxOrderPlacementMixin.create_order')
@mock.patch('ecommerce.extensions.checkout.mixins.EdxOrderPlacementMixin.handle_post_order')
@mock.patch('stripe.PaymentIntent.retrieve')
@mock.patch('ecommerce.extensions.payment.processors.webhooks.track_segment_event')
def test_handle_webhooks_payment(self, mock_track, mock_retrieve, mock_handle_post_order):
def test_handle_webhooks_payment(
self,
mock_track,
mock_retrieve,
mock_handle_post_order,
mock_create_order):
"""
Verify a payment received via Stripe webhooks is processed, an order is created and fulfilled.
"""
Expand Down Expand Up @@ -181,13 +188,13 @@ def test_handle_webhooks_payment(self, mock_track, mock_retrieve, mock_handle_po
mock_track.assert_called_once_with(
self.basket.site, self.basket.owner, 'Payment Processor Response', properties
)
mock_create_order.assert_called_once()
mock_handle_post_order.assert_called_once()

@mock.patch('ecommerce.extensions.checkout.mixins.EdxOrderPlacementMixin.create_order')
@mock.patch('ecommerce.extensions.checkout.mixins.EdxOrderPlacementMixin.handle_post_order')
@mock.patch('stripe.PaymentIntent.retrieve')
@mock.patch('ecommerce.extensions.payment.processors.webhooks.track_segment_event')
def test_handle_webhooks_payment_with_voucher(self, mock_track, mock_retrieve, mock_handle_post_order, mock_create_order):
def test_handle_webhooks_payment_with_voucher(self, mock_track, mock_retrieve, mock_handle_post_order):
"""
Verify a payment received via Stripe webhooks is processed, an order is created and fulfilled with a coupon.
"""
Expand Down Expand Up @@ -231,6 +238,7 @@ def test_handle_webhooks_payment_with_voucher(self, mock_track, mock_retrieve, m
mock_track.assert_called_once_with(
basket.site, basket.owner, 'Payment Processor Response', properties
)
mock_create_order.assert_called_once()
mock_handle_post_order.assert_called_once()
assert basket.total_incl_tax != basket.total_excl_tax_excl_discounts
order = Order.objects.get(number=basket.order_number)
assert order.total_incl_tax == basket.total_incl_tax
assert basket.total_incl_tax != basket.total_incl_tax_excl_discounts

0 comments on commit 58cd341

Please sign in to comment.