mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Add filter for enterprises within a radius
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
Darkswarm.filter 'distanceWithinKm', ->
|
||||
(enterprises, range) ->
|
||||
enterprises ||= []
|
||||
enterprises.filter (enterprise) ->
|
||||
enterprise.distance / 1000 <= range
|
||||
@@ -0,0 +1,17 @@
|
||||
describe "filtering enterprises to those within a certain radius", ->
|
||||
filter = null
|
||||
enterprises = [
|
||||
{distance: 25000}
|
||||
{distance: 75000}
|
||||
]
|
||||
|
||||
beforeEach ->
|
||||
module 'Darkswarm'
|
||||
inject ($filter) ->
|
||||
filter = $filter('distanceWithinKm')
|
||||
|
||||
it "filters to those enterprises within a distance", ->
|
||||
expect(filter(enterprises, 50)).toEqual [enterprises[0]]
|
||||
|
||||
it "returns empty array when enterprises array is null", ->
|
||||
expect(filter(null, 50)).toEqual []
|
||||
Reference in New Issue
Block a user