mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
Building params for adding new customer in the dialog directive, rather than generic Customers service
This commit is contained in:
@@ -12,7 +12,10 @@ angular.module("admin.customers").directive 'newCustomerDialog', ($compile, $tem
|
||||
scope.submitted = true
|
||||
scope.errors = []
|
||||
if scope.new_customer_form.$valid
|
||||
Customers.add(scope.email).$promise.then (data) ->
|
||||
params =
|
||||
enterprise_id: CurrentShop.shop.id
|
||||
email: scope.email
|
||||
Customers.add(params).$promise.then (data) ->
|
||||
if data.id
|
||||
scope.email = ""
|
||||
scope.submitted = false
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
angular.module("admin.resources").factory "Customers", ($q, InfoDialog, RequestMonitor, CustomerResource, CurrentShop) ->
|
||||
angular.module("admin.resources").factory "Customers", ($q, InfoDialog, RequestMonitor, CustomerResource) ->
|
||||
new class Customers
|
||||
all: []
|
||||
byID: {}
|
||||
pristineByID: {}
|
||||
|
||||
add: (email) ->
|
||||
params =
|
||||
enterprise_id: CurrentShop.shop.id
|
||||
email: email
|
||||
add: (params) ->
|
||||
CustomerResource.create params, (customer) =>
|
||||
if customer.id
|
||||
@all.unshift customer
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
describe "Customers", ->
|
||||
Customers = CurrentShop = customers = $httpBackend = null
|
||||
Customers = customers = $httpBackend = null
|
||||
|
||||
beforeEach ->
|
||||
module 'admin.customers'
|
||||
@@ -9,15 +9,14 @@ describe "Customers", ->
|
||||
compare: (actual, expected) ->
|
||||
{ pass: angular.equals(actual, expected) }
|
||||
|
||||
inject ($q, _$httpBackend_, _Customers_, _CurrentShop_) ->
|
||||
inject ($q, _$httpBackend_, _Customers_) ->
|
||||
Customers = _Customers_
|
||||
|
||||
describe "scope.add", ->
|
||||
it "creates a new customer", inject ($httpBackend, CurrentShop) ->
|
||||
it "creates a new customer", inject ($httpBackend) ->
|
||||
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)
|
||||
Customers.add(email: email, enterprise_id: 3)
|
||||
$httpBackend.flush()
|
||||
expect(Customers.all).toDeepEqual [newCustomer]
|
||||
|
||||
Reference in New Issue
Block a user