mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-26 20:56:48 +00:00
This little bit of "translation" between what we might receive as input and what ActiveMerchant requires is important, but currently the responsibility for this job is spread all over the code base. It can now just live in the CreditCard model (in one place) and doesn't need to be duplicated anywhere else (like several different places in frontend Javascript!)
55 lines
2.0 KiB
CoffeeScript
55 lines
2.0 KiB
CoffeeScript
describe 'StripeElements Service', ->
|
|
$httpBackend = $q = $rootScope = StripeElements = null
|
|
StripeMock = { createToken: null }
|
|
CardMock = { some: "card" }
|
|
|
|
beforeEach ->
|
|
module 'Darkswarm'
|
|
module ($provide) ->
|
|
$provide.value "railsFlash", null
|
|
null
|
|
|
|
inject (_StripeElements_, _$httpBackend_, _$q_, _$rootScope_) ->
|
|
$httpBackend = _$httpBackend_
|
|
StripeElements = _StripeElements_
|
|
$q = _$q_
|
|
$rootScope = _$rootScope_
|
|
|
|
describe "requestToken", ->
|
|
secrets = {}
|
|
submit = null
|
|
response = null
|
|
|
|
beforeEach inject ($window) ->
|
|
StripeElements.stripe = StripeMock
|
|
StripeElements.card = CardMock
|
|
|
|
describe "with satifactory data", ->
|
|
beforeEach ->
|
|
submit = jasmine.createSpy()
|
|
response = { token: { id: "token", card: { brand: 'MasterCard', last4: "5678", exp_month: 10, exp_year: 2099 } } }
|
|
StripeMock.createToken = => $q.when(response)
|
|
|
|
it "saves the response data to secrets, and submits the form", ->
|
|
StripeElements.requestToken(secrets, submit)
|
|
$rootScope.$digest() # required for #then to by called
|
|
expect(secrets.token).toEqual "token"
|
|
expect(secrets.cc_type).toEqual "MasterCard"
|
|
expect(submit).toHaveBeenCalled()
|
|
|
|
describe "with unsatifactory data", ->
|
|
beforeEach ->
|
|
submit = jasmine.createSpy()
|
|
response = { token: {id: "token" }, error: { message: 'There was a problem' } }
|
|
StripeMock.createToken = => $q.when(response)
|
|
|
|
it "doesn't submit the form, shows an error message instead", inject (Loading, RailsFlashLoader) ->
|
|
spyOn(Loading, "clear")
|
|
spyOn(RailsFlashLoader, "loadFlash")
|
|
spyOn(Bugsnag, "notify")
|
|
StripeElements.requestToken(secrets, submit).then (data) ->
|
|
expect(submit).not.toHaveBeenCalled()
|
|
expect(Loading.clear).toHaveBeenCalled()
|
|
expect(RailsFlashLoader.loadFlash).toHaveBeenCalledWith({error: "Error: There was a problem"})
|
|
expect(Bugsnag.notify).toHaveBeenCalled()
|