Add basic view allowing customers to authorise shop use of their credit cards

This commit is contained in:
Rob Harrington
2018-04-27 17:42:34 +10:00
parent ffa8a8c7d6
commit 6457a17fde
12 changed files with 181 additions and 4 deletions

View File

@@ -0,0 +1,39 @@
describe 'Customer', ->
describe "update", ->
$httpBackend = null
customer = null
response = { id: 3, code: '1234' }
RailsFlashLoaderMock = jasmine.createSpyObj('RailsFlashLoader', ['loadFlash'])
beforeEach ->
module 'Darkswarm'
module ($provide) ->
$provide.value 'RailsFlashLoader', RailsFlashLoaderMock
null
inject (_$httpBackend_, Customer)->
customer = new Customer(id: 3)
$httpBackend = _$httpBackend_
it "nests the params inside 'customer'", ->
$httpBackend
.expectPUT('/api/customers/3.json', { customer: { id: 3 } })
.respond 200, response
customer.update()
$httpBackend.flush()
describe "when the request succeeds", ->
it "shows a success flash", ->
$httpBackend.expectPUT('/api/customers/3.json').respond 200, response
customer.update()
$httpBackend.flush()
expect(RailsFlashLoaderMock.loadFlash)
.toHaveBeenCalledWith({success: jasmine.any(String)})
describe "when the request fails", ->
it "shows a error flash", ->
$httpBackend.expectPUT('/api/customers/3.json').respond 400, { error: 'Some error' }
customer.update()
$httpBackend.flush()
expect(RailsFlashLoaderMock.loadFlash)
.toHaveBeenCalledWith({error: 'Some error'})

View File

@@ -0,0 +1,24 @@
describe 'Customers', ->
describe "index", ->
$httpBackend = null
Customers = null
customerList = ['somecustomer']
beforeEach ->
module 'Darkswarm'
module ($provide) ->
$provide.value 'RailsFlashLoader', null
null
inject (_$httpBackend_, _Customers_)->
Customers = _Customers_
$httpBackend = _$httpBackend_
it "asks for customers and returns @all, promises to populate via @load", ->
spyOn(Customers,'load').and.callThrough()
$httpBackend.expectGET('/api/customers.json').respond 200, customerList
result = Customers.index()
$httpBackend.flush()
expect(Customers.load).toHaveBeenCalled()
expect(result).toEqual customerList
expect(Customers.all).toEqual customerList

View File

@@ -0,0 +1,27 @@
describe 'Shops', ->
describe "initialisation", ->
Shops = null
shops = ['some shop']
beforeEach ->
module 'Darkswarm'
describe "when the injector does not have a value for 'shops'", ->
beforeEach ->
inject (_Shops_) ->
Shops = _Shops_
it "does nothing, leaves @all empty", ->
expect(Shops.all).toEqual []
describe "when the injector has a value for 'shops'", ->
beforeEach ->
module ($provide) ->
$provide.value 'shops', shops
null
inject (_Shops_) ->
Shops = _Shops_
it "loads injected shops array into @all", ->
expect(Shops.all).toEqual shops