mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-03 22:06:07 +00:00
Refactoring the RABL injection and the Hubs/Producers/Enterprises services
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
describe "Enterprises service", ->
|
||||
Enterprises = null
|
||||
enterprises = [
|
||||
{id: 1, type: "hub"},
|
||||
{id: 2, type: "producer"}
|
||||
]
|
||||
beforeEach ->
|
||||
module 'Darkswarm'
|
||||
angular.module('Darkswarm').value('enterprises', enterprises)
|
||||
|
||||
inject ($injector)->
|
||||
Enterprises = $injector.get("Enterprises")
|
||||
|
||||
it "stores enterprises as id/object pairs", ->
|
||||
expect(Enterprises.enterprises_by_id["1"]).toBe enterprises[0]
|
||||
expect(Enterprises.enterprises_by_id["2"]).toBe enterprises[1]
|
||||
|
||||
it "stores enterprises as an array", ->
|
||||
expect(Enterprises.enterprises).toBe enterprises
|
||||
|
||||
it "puts the same objects in enterprises and enterprises_by_id", ->
|
||||
expect(Enterprises.enterprises[0]).toBe Enterprises.enterprises_by_id["1"]
|
||||
39
spec/javascripts/unit/darkswarm/services/hubs_spec.js.coffee
Normal file
39
spec/javascripts/unit/darkswarm/services/hubs_spec.js.coffee
Normal file
@@ -0,0 +1,39 @@
|
||||
describe "Hubs service", ->
|
||||
Hubs = null
|
||||
Enterprises = null
|
||||
hubs = [
|
||||
{
|
||||
id: 2
|
||||
active: false
|
||||
orders_close_at: new Date()
|
||||
type: "hub"
|
||||
}
|
||||
{
|
||||
id: 3
|
||||
active: false
|
||||
orders_close_at: new Date()
|
||||
type: "hub"
|
||||
}
|
||||
{
|
||||
id: 1
|
||||
active: true
|
||||
orders_close_at: new Date()
|
||||
type: "hub"
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
beforeEach ->
|
||||
module 'Darkswarm'
|
||||
angular.module('Darkswarm').value('enterprises', hubs)
|
||||
inject ($injector)->
|
||||
Enterprises = $injector.get("Enterprises")
|
||||
Hubs = $injector.get("Hubs")
|
||||
|
||||
it "filters Enterprise.hubs into a new array", ->
|
||||
expect(Hubs.hubs[0]).toBe Enterprises.enterprises[2]
|
||||
# Because the $filter is a new sorted array
|
||||
# We check to see the objects in both arrays are still the same
|
||||
Enterprises.enterprises[2].active = false
|
||||
expect(Hubs.hubs[0].active).toBe false
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
describe "Producers service", ->
|
||||
Producers = null
|
||||
Enterprises = null
|
||||
enterprises = [
|
||||
{type: "producer"}
|
||||
]
|
||||
|
||||
beforeEach ->
|
||||
module 'Darkswarm'
|
||||
angular.module('Darkswarm').value('enterprises', enterprises)
|
||||
inject ($injector)->
|
||||
Producers = $injector.get("Producers")
|
||||
|
||||
it "delegates producers array to Enterprises", ->
|
||||
expect(Producers.producers[0]).toBe enterprises[0]
|
||||
Reference in New Issue
Block a user