Hey folks,
Have not been able to write integration test for your integrated Stripe in your NodeJS app? Or perhapse you've used things like mock-stripe and ain't particularly satisfied with the amount of freedom.
So today is your lucky day since I've created this simple app in NodeJS which I am testing Stripe with Jest. Bear in mind that here we are literally mocking the whole communication with Stripe therefore you need to still have some sort of IDK E2E tests or other integration tests where you do not mock the stripe-node communication with the real Stripe API.
Use a different env variable than NODE_ENV
You can do that of course by adding a new env variable which let you know when you should not mock it. If I where in that situation I would have probably do something about it where I am creating the stripe config. Or instantiating Stripe instance. Here you can see an implementation of it, there I am actually mocking it when I wanna mock it (in the payment-service integration tests) and also send a request to the actual Stripe api (in the integration tests written for the reservation-service).
Link to the simple implementation
But for now let me share the repo's link: https://github.com/kasir-barati/docker/tree/docker-compose/docker-compose-files/mockserver-integration-test
Read the README.md
to learn how you should spin it up. BTW I truly like to hear from you and also if this was helpful in anyway consider giving my repo and this post a star and heart respectively.
Before I forget it I wanna also share this infographic I made from MockServer and how it works.
Just one more thing. I am not sure about proxying the requests back grom MockServer to Stripe. But if you have done it already do not hesitate to share it here or in my GH repo.