#practicat-unittest-checkoutevent
1 messages · Page 1 of 1 (latest)
@remote tapir Can you give a bit more context? What is your code doing exactly?
I'm developing a platform for electronic billing, when a business creates an account, they have to configure the api key in their settings and then when they want invoices to be paid by customers they send them a url, I have a webhook for the event checkout session completed to make sure that customers have paid their invoices, and I update the invoice status when the event checkout session completed is triggered. That works well but now I'm doing a unit test and I have an issue when I want to post a checkout object in the url of the webhook.
Sorry for my English I'm from Latin America and it's not my main language :c
all good, your English is great!
What I need to understand is what your code does exactly and why you pass a fake API key
when I do it to the checkout session completed event it fails and returns that the api key is invalid
you said this. I think it's because your code must call the Retrieve Checkout Session API?
I created a fixture of account settings, my api key credentials there are fake, they look like this "sk_test_aaaaAAAA". All tests of other events pass (charge.succeeded, invoice.updated, invoice.voided, invoice.payment_failed), but when the test of the checkout session completed is triggered it fails with invalid api key. I don't know why, I'm just a mortal intern :c
all good, what exact code/systems are you using? How is your unit test written?
practicat-unittest-checkoutevent
Yes, it calls it
Can you give me real information about your exact code, the kind of config you use for unit tests, etc.?
I assume you have a mock somewhere
Most of them are done like this, here is an example for the invoice.payment_failed event
@mock.patch.object(StripeApiClient, "construct_event") def test_webhook_changes_payment_transaction_status_to_declined_when_last_payment_attempt_fails(self, construct_event_mock): construct_event_mock.return_value = self.charge_object response = self.admin_client.post( self.url, data=json.dumps(self.charge_object), content_type="application/json", HTTP_STRIPE_SIGNATURE="AAAAAAAAA", ) tx = PaymentGatewayTransaction.objects.get(id=1) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(tx.status, PaymentGatewayTransaction.STATUS_DECLINED)
okay so inside self.admin_client.post( you must have something that "mocks" specific URLs like /v1/charges/ch_123 or /v1/invoices/in_123 from our API and you need to go and add Checkout's URLs like /v1/checkout/sessions/cs_test_123
Okok, I'll see thank you 🙂