• Design
  • Shotty
  • Blog
  • Reading
  • Photos
Menu

Jacob Ruiz

Product Designer
  • Design
  • Shotty
  • Blog
  • Reading
  • Photos
graphql-notes@2x.png

GraphQL: Writing Tests For Our Stripe Subscription Resolvers

July 2, 2019

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.

← GraphQL: Writing Tests for Canceling a Stripe Subscription Summer - Joe Hisaishi →
shotty-skinny2x.jpg

Shotty - Faster Access To Your Screenshots on Mac

Shotty is an award-winning Mac app I created to give you instant access to all your recent screenshots, right from the menu bar. You can even add annotations on-the-fly. Stop wasting time digging through Finder for your screenshots. I promise it’ll change your workflow forever (just read the App Store reviews!).



Most popular

information-architecture

Information Architecture: The Most Important Part of Design You're Probably Overlooking

Follow @JacobRuizDesign