Files
openfoodnetwork/spec/javascripts/unit/darkswarm/services/enterprise_spec.js.coffee
2014-07-04 13:51:22 +10:00

39 lines
1.3 KiB
CoffeeScript

describe "Enterprises service", ->
Enterprises = null
CurrentHubMock = {}
taxons = [
{id: 1, name: "test"}
]
enterprises = [
{id: 1, type: "hub", producers: [{id: 2}], taxons: [{id: 1}]},
{id: 2, type: "producer", hubs: [{id: 1}]},
{id: 3, type: "producer", hubs: [{id: 1}]}
]
beforeEach ->
module 'Darkswarm'
module ($provide)->
$provide.value "CurrentHub", CurrentHubMock
null
angular.module('Darkswarm').value('enterprises', enterprises)
angular.module('Darkswarm').value('taxons', taxons)
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"]
it "dereferences references to other enterprises", ->
expect(Enterprises.enterprises_by_id["1"].producers[0]).toBe enterprises[1]
expect(Enterprises.enterprises_by_id["3"].hubs[0]).toBe enterprises[0]
it "dereferences taxons", ->
expect(Enterprises.enterprises[0].taxons[0]).toBe taxons[0]