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

Fix #1722 -- Add more tests for fundraising webhook #1761

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

ontowhee
Copy link
Contributor

@ontowhee ontowhee commented Nov 21, 2024

Fix for #1722

Added test for checkout_session_completed. The test fails when reverting the change in e995213.

A new file is added in test_data. It was generated by calling calling stripe.Customer.list().data[0], stripe.PaymentIntent.list().data[0], etc.

  • session_completed.json

@bmispelon @alexgmin

@ontowhee ontowhee marked this pull request as draft November 21, 2024 21:26
customer.return_value = self.stripe_data("customer")
payment_intent.return_value = self.stripe_data("payment_intent")
event = self.stripe_data("session_completed")
WebhookHandler(event).handle()
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the reason behind not using self.post_event() like the other tests and calling the class directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've updated this to call self.post_event()!

event = self.stripe_data("session_completed")
WebhookHandler(event).handle()
customer.assert_called_once()
payment_intent.assert_called_once()
Copy link
Contributor

Choose a reason for hiding this comment

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

Thinks that should also be tested:

  • That the email is sent. There's an example above, self.assertEqual(len(mail.outbox), 1)
  • That the response of the handler is the correct one, It should be a 204.
  • What happens if the DjangoHero instance doesn't exist (this should probably be a different test (or could be a new PR to add this to every event test since right now they don't check this case))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It now checks that the email is sent, and the status code is 204.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For the case where DjangoHero does not exist, I added a test that modifies the existing DjangoHero's stripe_customer_id, and then check that count for DjangoHero is increased to 2. Is that the right approach?

@ontowhee ontowhee requested a review from alexgmin November 30, 2024 07:17
@ontowhee ontowhee marked this pull request as ready for review December 3, 2024 14:36
self.hero.stripe_customer_id = ""
self.hero.save()
response = self.post_event(self.stripe_data("session_completed"))

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we check here too that the mail is sent?

self.assertEqual(DjangoHero.objects.count(), 1)

def test_checkout_session_completed_new_hero(self):
self.hero.stripe_customer_id = ""
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering if there's a better way to do this. Either by deleting the Hero in this test before the event or by not hardcoding the stripe customer id in the setUp.
This approach works, tho.
@bmispelon Any suggestions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants