Add distributor filter to BOM

This commit is contained in:
Rob H
2014-01-18 12:48:52 +08:00
parent e2d9e9c4eb
commit 79631ebb8e
4 changed files with 75 additions and 22 deletions

View File

@@ -12,13 +12,15 @@ describe "AdminOrderMgmtCtrl", ->
)
describe "loading data upon initialisation", ->
it "gets a list of suppliers and then calls fetchOrders", ->
it "gets a list of suppliers and a list of distributors and then calls fetchOrders", ->
httpBackend.expectGET("/api/users/authorise_api?token=api_key").respond success: "Use of API Authorised"
httpBackend.expectGET("/api/enterprises/managed?template=bulk_index&q[is_primary_producer_eq]=true").respond "list of suppliers"
httpBackend.expectGET("/api/enterprises/managed?template=bulk_index&q[is_distributor_eq]=true").respond "list of distributors"
spyOn(scope, "fetchOrders").andReturn "nothing"
scope.initialise "api_key"
httpBackend.flush()
expect(scope.suppliers).toEqual "list of suppliers"
expect(scope.distributors).toEqual "list of distributors"
expect(scope.fetchOrders.calls.length).toEqual 1
expect(scope.spree_api_key_ok).toEqual true
@@ -37,15 +39,19 @@ describe "AdminOrderMgmtCtrl", ->
describe "resetting orders", ->
beforeEach ->
spyOn(scope, "matchDistributor").andReturn "nothing"
spyOn(scope, "resetLineItems").andReturn "nothing"
scope.resetOrders "list of orders"
scope.resetOrders [ "order1", "order2", "order3" ]
it "sets the value of $scope.orders to the data received", ->
expect(scope.orders).toEqual "list of orders"
expect(scope.orders).toEqual [ "order1", "order2", "order3" ]
it "makes a call to $scope.resetLineItems", ->
expect(scope.resetLineItems).toHaveBeenCalled()
it "calls matchDistributor for each line item", ->
expect(scope.matchDistributor.calls.length).toEqual 3
describe "resetting line items", ->
order1 = order2 = order3 = null
@@ -73,26 +79,52 @@ describe "AdminOrderMgmtCtrl", ->
describe "matching supplier", ->
it "changes the supplier of the line_item to the one which matches it from the suppliers list", ->
s1_s =
supplier1_list =
id: 1
name: "S1"
s2_s =
supplier2_list =
id: 2
name: "S2"
s1_l =
supplier1_line_item =
id: 1
name: "S1"
expect(s1_s is s1_l).not.toEqual true
expect(supplier1_list is supplier1_line_item).not.toEqual true
scope.suppliers = [
s1_s
s2_s
supplier1_list
supplier2_list
]
line_item =
id: 10
supplier: s1_l
supplier: supplier1_line_item
scope.matchSupplier line_item
expect(line_item.supplier is s1_s).toEqual true
expect(line_item.supplier is supplier1_list).toEqual true
describe "matching distributor", ->
it "changes the distributor of the order to the one which matches it from the distributors list", ->
distributor1_list =
id: 1
name: "D1"
distributor2_list =
id: 2
name: "D2"
distributor1_order =
id: 1
name: "D1"
expect(distributor1_list is distributor1_order).not.toEqual true
scope.distributors = [
distributor1_list
distributor2_list
]
order =
id: 10
distributor: distributor1_order
scope.matchDistributor order
expect(order.distributor is distributor1_list).toEqual true