Flag enterprises whose name matches a query

This commit is contained in:
Rohan Mitchell
2015-07-02 12:08:10 +10:00
parent befcc37456
commit d0d9e9e367
2 changed files with 30 additions and 9 deletions

View File

@@ -17,14 +17,14 @@ describe "Enterprises service", ->
{id: 1, name: "test"}
]
enterprises = [
{id: 1, visible: true, category: "hub", producers: [{id: 5}], taxons: [{id: 1}]},
{id: 2, visible: true, category: "hub", producers: [{id: 6}]}
{id: 3, visible: true, category: "hub_profile"}
{id: 4, visible: false, category: "hub", producers: [{id: 7}]}
{id: 5, visible: true, category: "producer_hub", hubs: [{id: 1}]},
{id: 6, visible: true, category: "producer_shop", hubs: [{id: 2}]},
{id: 7, visible: true, category: "producer", hubs: [{id: 2}]}
{id: 8, visible: false, category: "producer", hubs: [{id: 2}]}
{id: 1, visible: true, name: 'a', category: "hub", producers: [{id: 5}], taxons: [{id: 1}]},
{id: 2, visible: true, name: 'b', category: "hub", producers: [{id: 6}]}
{id: 3, visible: true, name: 'c', category: "hub_profile"}
{id: 4, visible: false,name: 'd', category: "hub", producers: [{id: 7}]}
{id: 5, visible: true, name: 'e', category: "producer_hub", hubs: [{id: 1}]},
{id: 6, visible: true, name: 'f', category: "producer_shop", hubs: [{id: 2}]},
{id: 7, visible: true, name: 'g', category: "producer", hubs: [{id: 2}]}
{id: 8, visible: false,name: 'h', category: "producer", hubs: [{id: 2}]}
]
H1: 0
beforeEach ->
@@ -87,6 +87,20 @@ describe "Enterprises service", ->
expect(Enterprises.producers).toContain Enterprises.enterprises[5]
expect(Enterprises.producers).toContain Enterprises.enterprises[6]
describe "flagging enterprises with names matching a query", ->
it "flags enterprises when a query is provided", ->
Enterprises.flagMatching 'c'
expect(e.matches_name_query).toBe true for e in enterprises when e.name == 'c'
expect(e.matches_name_query).toBe false for e in enterprises when e.name != 'c'
it "clears flags when query is null", ->
Enterprises.flagMatching null
expect(e.matches_name_query).toBe false for e in enterprises
it "clears flags when query is blank", ->
Enterprises.flagMatching ''
expect(e.matches_name_query).toBe false for e in enterprises
describe "updating distance of enterprises from a location", ->
it "calculates the distance when a query is provided", ->
spyOn(Enterprises, "calculateDistance")