GraphQL: Writing Tests For Our Stripe Subscription Resolvers
We’ve implemented resolvers that let users upgrade their account from Basic to Premium, using Stripe Subscriptions.
Now it’s time to write some tests.
For now, we’ll start by testing the success case. Basically, if the client sends a valid Stripe token, and the user is logged in, our API should return the User object from the upgradeToPremium
resolver, with the role
set to PREMIUM
.
The test looks something like this:
We’re doing a lot of things that take time in this test:
Log in
Create a customer in Stripe
Subscribe the customer in Stripe
Because a lot of this takes time over the network, our test runs for a long time, about 4 seconds actually. I should investigate how to cut this time down, but for now we have a problem that Mocha fails any test that takes longer than 2 seconds to complete.
For now, we can disable the timeout by tacking the .timeout(0)
onto the end of our it()
call.