mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-13 04:00:21 +00:00
Adding customers controller, service and resource
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
describe "CustomersCtrl", ->
|
||||
ctrl = null
|
||||
scope = null
|
||||
Customers = null
|
||||
|
||||
beforeEach ->
|
||||
shops = "list of shops"
|
||||
|
||||
module('admin.customers')
|
||||
inject ($controller, $rootScope, _Customers_) ->
|
||||
scope = $rootScope
|
||||
Customers = _Customers_
|
||||
ctrl = $controller 'customersCtrl', {$scope: scope, Customers: Customers, shops: shops}
|
||||
|
||||
describe "initialise()", ->
|
||||
beforeEach ->
|
||||
spyOn(Customers, "index").andReturn "list of customers"
|
||||
scope.shop = {id: 1}
|
||||
scope.initialise()
|
||||
|
||||
it "calls Customers#index with the correct params", ->
|
||||
expect(Customers.index).toHaveBeenCalledWith({enterprise_id: 1})
|
||||
|
||||
it "resets $scope.customers with the result of Customers#index", ->
|
||||
expect(scope.customers).toEqual "list of customers"
|
||||
@@ -0,0 +1,31 @@
|
||||
describe "Customers service", ->
|
||||
Customers = CustomerResource = customers = $httpBackend = null
|
||||
|
||||
beforeEach ->
|
||||
module 'admin.customers'
|
||||
|
||||
inject ($q, _$httpBackend_, _Customers_, _CustomerResource_) ->
|
||||
Customers = _Customers_
|
||||
CustomerResource = _CustomerResource_
|
||||
$httpBackend = _$httpBackend_
|
||||
$httpBackend.expectGET('/admin/customers.json?enterprise_id=2').respond 200, [{ id: 5, email: 'someone@email.com'}]
|
||||
|
||||
describe "#index", ->
|
||||
result = null
|
||||
|
||||
beforeEach ->
|
||||
expect(Customers.loaded).toBe false
|
||||
result = Customers.index(enterprise_id: 2)
|
||||
$httpBackend.flush()
|
||||
|
||||
it "stores returned data in @customers, with ids as keys", ->
|
||||
# This is super weird and freaking annoying. I think resource results have extra
|
||||
# properties ($then, $promise) that cause them to not be equal to the reponse object
|
||||
# provided to the expectGET clause above.
|
||||
expect(Customers.customers).toEqual { 5: new CustomerResource({ id: 5, email: 'someone@email.com'}) }
|
||||
|
||||
it "returns @customers", ->
|
||||
expect(result).toEqual Customers.customers
|
||||
|
||||
it "sets @loaded to true", ->
|
||||
expect(Customers.loaded).toBe true
|
||||
Reference in New Issue
Block a user