Moving Customers and CustomerResource services to admin.resource module

This commit is contained in:
Rob Harrington
2016-11-25 09:59:32 +11:00
parent dbbd52cace
commit 268c8dbcdd
5 changed files with 44 additions and 23 deletions

View File

@@ -62,28 +62,17 @@ describe "CustomersCtrl", ->
as = scope.findByCode('b')
expect(as).toDeepEqual []
describe "scope.add", ->
it "creates a new customer", ->
email = "customer@example.org"
newCustomer = {id: 6, email: email}
customers.unshift(newCustomer)
http.expectPOST('/admin/customers.json?email=' + email + '&enterprise_id=3').respond 200, newCustomer
scope.add(email)
http.flush()
expect(scope.customers).toDeepEqual customers
describe "scope.deleteCustomer", ->
beforeEach ->
spyOn(window, 'confirm').and.returnValue(true)
it "deletes a customer", ->
expect(scope.customers.length).toBe 2
expect(scope.customers.length).toBe 1
customer = scope.customers[0]
http.expectDELETE('/admin/customers/' + customer.id + '.json').respond 200
scope.deleteCustomer(customer)
http.flush()
expect(scope.customers.length).toBe 1
expect(scope.customers[0]).not.toDeepEqual customer
expect(scope.customers.length).toBe 0
describe "scope.findTags", ->
tags = [

View File

@@ -0,0 +1,23 @@
describe "Customers", ->
Customers = CurrentShop = customers = $httpBackend = null
beforeEach ->
module 'admin.customers'
jasmine.addMatchers
toDeepEqual: (util, customEqualityTesters) ->
compare: (actual, expected) ->
{ pass: angular.equals(actual, expected) }
inject ($q, _$httpBackend_, _Customers_, _CurrentShop_) ->
Customers = _Customers_
describe "scope.add", ->
it "creates a new customer", inject ($httpBackend, CurrentShop) ->
email = "customer@example.org"
newCustomer = {id: 6, email: email}
CurrentShop.shop = { id: 3 }
$httpBackend.expectPOST('/admin/customers.json?email=' + email + '&enterprise_id=3').respond 200, newCustomer
Customers.add(email)
$httpBackend.flush()
expect(Customers.all).toDeepEqual [newCustomer]