Skip to content

Instantly share code, notes, and snippets.

@lawrencejones
Created October 4, 2014 17:07
Show Gist options
  • Save lawrencejones/8a6f25fbb544413123ea to your computer and use it in GitHub Desktop.
Save lawrencejones/8a6f25fbb544413123ea to your computer and use it in GitHub Desktop.
{ User } = require('sesquis/app/models/user')
{ StripeConnection } = require('sesquis/app/etc/stripe_connection')
{ CARDS } = require('sesquis/spec/seeds/stripe/stripe')
describe 'Stripe', ->
resetAndExposeUser = ->
before resetDatabase
# Fetch a user and make them available on the context
before ->
User.findOne(email: '[email protected]').exec().then (@user) =>
@user.should.be.ok
it 'should successfully connect', ->
StripeConnection.checkConnection()
describe 'initialising user', ->
do resetAndExposeUser
it 'should assign a stripe.id', ->
@user.initStripe().then =>
@user.stripe.id.should.match /^cus_/
describe 'a fresh user', ->
do resetAndExposeUser
context 'before ever interacting with stripe', ->
it 'should have 0 cards', ->
@user.getCards().should.eventually
.have.property 'length', 0
it 'should have no stripe.id', ->
should.not.exist @user.stripe.id
context 'when adding a card', ->
describe 'the method', ->
it 'should not error', ->
@user.addCard {
card: CARDS['VISA_SUCCESS']
}
context 'after adding a card', ->
context 'the user', ->
it 'should have an assigned stripe.id', ->
@user.stripe.id.should.match /^cus_/
it 'should have 1 card', ->
@user.getCards().should.eventually
.have.property 'length', 1
context 'when removing a card', ->
before ->
@user.getCards().then ([ firstCard ]) =>
@cardId = firstCard.id
@cardId.should.be.ok
describe 'the method', ->
it 'should not error', ->
@user.removeCard(@cardId)
context 'after removing the card', ->
it 'should have 0 cards', ->
@user.getCards().then (cards) ->
cards.length.should.equal 0
it 'should still have a stripe.id', ->
@user.stripe.id.should.be.ok
@user.stripe.id.should.match /^cus_/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment