Currently, the tests make actual Stripe subscriptions and attempt to change the subscriptions in order to cover all of the behavior that the webhook endpoint supports. This is impossible, however, because some changes require time to elapse before the subscription will change state. It also dramatically slows down the execution of all of the tests when calls to Stripe are added in.
It would be better to pass Stripe to the subscription webhook handler as a parameter or to mock Stripe using a library that allows overriding require(). Either of these approaches would allow the tests to use prebuilt requests from the Stripe API as test data, instead of relying on the state of actual test subscriptions.
Currently, the tests make actual Stripe subscriptions and attempt to change the subscriptions in order to cover all of the behavior that the webhook endpoint supports. This is impossible, however, because some changes require time to elapse before the subscription will change state. It also dramatically slows down the execution of all of the tests when calls to Stripe are added in.
It would be better to pass Stripe to the subscription webhook handler as a parameter or to mock Stripe using a library that allows overriding
require()
. Either of these approaches would allow the tests to use prebuilt requests from the Stripe API as test data, instead of relying on the state of actual test subscriptions.