bugfix and extend angular enterprise spec

This commit is contained in:
Rafael Schouten
2014-10-06 01:36:18 +11:00
parent 017d6b1273
commit c495e967cb

View File

@@ -5,10 +5,16 @@ describe "Enterprises service", ->
{id: 1, name: "test"}
]
enterprises = [
{id: 1, visible: true, is_distributor: true, is_primary_producer: false, producers: [{id: 2}], taxons: [{id: 1}]},
{id: 2, visible: true, is_distributor: false, is_primary_producer: true, hubs: [{id: 1}]},
{id: 3, visible: true, is_distributor: false, is_primary_producer: true, hubs: [{id: 1}]}
{id: 1, visible: true, enterprise_category: "hub", producers: [{id: 5}], taxons: [{id: 1}]},
{id: 2, visible: true, enterprise_category: "hub", producers: [{id: 6}]}
{id: 3, visible: true, enterprise_category: "hub_profile"}
{id: 4, visible: false, enterprise_category: "hub", producers: [{id: 7}]}
{id: 5, visible: true, enterprise_category: "producer_hub", hubs: [{id: 1}]},
{id: 6, visible: true, enterprise_category: "producer_shop", hubs: [{id: 2}]},
{id: 7, visible: true, enterprise_category: "producer", hubs: [{id: 2}]}
{id: 8, visible: false, enterprise_category: "producer", hubs: [{id: 2}]}
]
H1: 0
beforeEach ->
module 'Darkswarm'
module ($provide)->
@@ -31,8 +37,8 @@ describe "Enterprises service", ->
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]
expect(Enterprises.enterprises_by_id["1"].producers[0]).toBe enterprises[4]
expect(Enterprises.enterprises_by_id["5"].hubs[0]).toBe enterprises[0]
it "dereferences taxons", ->
expect(Enterprises.enterprises[0].taxons[0]).toBe taxons[0]
@@ -44,5 +50,26 @@ describe "Enterprises service", ->
Enterprises.enterprises[0].active = false
expect(Enterprises.hubs[0].active).toBe false
it "delegates producers array to Enterprises", ->
expect(Enterprises.producers[0]).toBe enterprises[1]
it "filters Enterprises.producers into a new array", ->
expect(Enterprises.producers[0]).toBe Enterprises.enterprises[4]
Enterprises.enterprises[4].active = false
expect(Enterprises.producers[0].active).toBe false
it "only includes visible enterprises in hubs array", ->
expect(Enterprises.hubs).toContain Enterprises.enterprises[0]
expect(Enterprises.hubs).not.toContain Enterprises.enterprises[3]
it "only includes visible enterprises in producers array", ->
expect(Enterprises.producers).toContain Enterprises.enterprises[4]
expect(Enterprises.producers).not.toContain Enterprises.enterprises[7]
it "includes hub, hub_profile, producer_hub and, producer_shop enterprises in hubs array", ->
expect(Enterprises.hubs).toContain Enterprises.enterprises[0]
expect(Enterprises.hubs).toContain Enterprises.enterprises[2]
expect(Enterprises.hubs).toContain Enterprises.enterprises[4]
expect(Enterprises.hubs).toContain Enterprises.enterprises[5]
it "includes producer_hub, producer_shop and producer enterprises in producers array", ->
expect(Enterprises.producers).toContain Enterprises.enterprises[4]
expect(Enterprises.producers).toContain Enterprises.enterprises[5]
expect(Enterprises.producers).toContain Enterprises.enterprises[6]