Refactoring the RABL injection and the Hubs/Producers/Enterprises services

This commit is contained in:
Will Marshall
2014-06-18 15:40:02 +10:00
parent c8384f1a71
commit a2965696da
14 changed files with 103 additions and 15 deletions

View File

@@ -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"]

View 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

View File

@@ -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]