Enterprises can calculate their distances from a location via geocode lookup

This commit is contained in:
Rohan Mitchell
2015-07-02 11:43:07 +10:00
parent 80bb6c36e3
commit 9fb7c47c73
5 changed files with 94 additions and 12 deletions

View File

@@ -1,6 +1,18 @@
describe "Enterprises service", ->
Enterprises = null
CurrentHubMock = {}
Geo =
OK: 'ok'
succeed: true
geocode: (query, callback) ->
if @succeed
results = [{geometry: {location: "location"}}]
callback(results, @OK)
else
callback(results, 'Oops')
distanceBetween: (locatable, location) ->
123
taxons = [
{id: 1, name: "test"}
]
@@ -19,6 +31,7 @@ describe "Enterprises service", ->
module 'Darkswarm'
module ($provide)->
$provide.value "CurrentHub", CurrentHubMock
$provide.value "Geo", Geo
null
angular.module('Darkswarm').value('enterprises', enterprises)
angular.module('Darkswarm').value('taxons', taxons)
@@ -73,3 +86,45 @@ describe "Enterprises service", ->
expect(Enterprises.producers).toContain Enterprises.enterprises[4]
expect(Enterprises.producers).toContain Enterprises.enterprises[5]
expect(Enterprises.producers).toContain Enterprises.enterprises[6]
describe "updating distance of enterprises from a location", ->
it "calculates the distance when a query is provided", ->
spyOn(Enterprises, "calculateDistance")
Enterprises.updateDistance "asdf"
expect(Enterprises.calculateDistance).toHaveBeenCalledWith("asdf")
it "resets the distance when query is blank", ->
spyOn(Enterprises, "resetDistance")
Enterprises.updateDistance ""
expect(Enterprises.resetDistance).toHaveBeenCalled()
describe "calculating the distance of enterprises from a location", ->
beforeEach ->
spyOn(Enterprises, "setDistanceFrom")
it "calculates distance for all enterprises when geocoding succeeds", ->
Geo.succeed = true
Enterprises.calculateDistance('query')
expect(Enterprises.setDistanceFrom).toHaveBeenCalledWith("location")
it "resets distance when geocoding fails", ->
Geo.succeed = false
spyOn(Enterprises, "resetDistance")
Enterprises.calculateDistance('query')
expect(Enterprises.setDistanceFrom).not.toHaveBeenCalled()
expect(Enterprises.resetDistance).toHaveBeenCalled()
describe "setting the distance of each enterprise from a central location", ->
it "sets the distances", ->
Enterprises.setDistanceFrom 'location'
for e in Enterprises.enterprises
expect(e.distance).toEqual 123
describe "resetting the distance measurement of all enterprises", ->
beforeEach ->
e.distance = 123 for e in Enterprises.enterprises
it "resets the distance", ->
Enterprises.resetDistance()
for e in Enterprises.enterprises
expect(e.distance).toBeNull()

View File

@@ -1,7 +1,8 @@
describe "Groups service", ->
Groups = null
Enterprises = null
CurrentHubMock = {}
CurrentHubMock = {}
Geo = {}
groups = [{
id: 1
name: "Test Group"
@@ -17,17 +18,18 @@ describe "Groups service", ->
beforeEach ->
module 'Darkswarm'
angular.module('Darkswarm').value('groups', groups)
angular.module('Darkswarm').value('enterprises', enterprises)
angular.module('Darkswarm').value('groups', groups)
angular.module('Darkswarm').value('enterprises', enterprises)
module ($provide)->
$provide.value "CurrentHub", CurrentHubMock
$provide.value "CurrentHub", CurrentHubMock
$provide.value "Geo", Geo
null
inject (_Groups_, _Enterprises_)->
Groups = _Groups_
Enterprises = _Enterprises_
Groups = _Groups_
Enterprises = _Enterprises_
it "dereferences group enterprises", ->
expect(Groups.groups[0].enterprises[0]).toBe enterprises[0]
it "dereferences enterprise groups", ->
expect(Enterprises.enterprises[0].groups[0]).toBe groups[0]

View File

@@ -1,6 +1,7 @@
describe "Hubs service", ->
OfnMap = null
CurrentHubMock = {}
CurrentHubMock = {}
Geo = {}
enterprises = [
{
id: 2
@@ -13,12 +14,13 @@ describe "Hubs service", ->
beforeEach ->
module 'Darkswarm'
angular.module('Darkswarm').value('enterprises', enterprises)
angular.module('Darkswarm').value('enterprises', enterprises)
module ($provide)->
$provide.value "CurrentHub", CurrentHubMock
$provide.value "CurrentHub", CurrentHubMock
$provide.value "Geo", Geo
null
inject ($injector)->
OfnMap = $injector.get("OfnMap")
OfnMap = $injector.get("OfnMap")
it "builds MapMarkers from enterprises", ->
expect(OfnMap.enterprises[0].id).toBe enterprises[0].id

View File

@@ -10,6 +10,7 @@ describe 'Products service', ->
productWithImage = null
properties = null
taxons = null
Geo = {}
beforeEach ->
product =
@@ -40,6 +41,7 @@ describe 'Products service', ->
$provide.value "currentOrder", currentOrder
$provide.value "taxons", taxons
$provide.value "properties", properties
$provide.value "Geo", Geo
null
inject ($injector, _$httpBackend_)->