mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-23 01:03:21 +00:00
Indexer accepts arbitrary key to index by. Fix bug: Return an object instead of an array.
This commit is contained in:
@@ -11,3 +11,12 @@ describe "indexer", ->
|
||||
objects = [{id: 1, name: 'one'}, {id: 2, name: 'two'}]
|
||||
index = Indexer.index objects
|
||||
expect(index).toEqual({1: {id: 1, name: 'one'}, 2: {id: 2, name: 'two'}})
|
||||
|
||||
it "indexes an array of objects by another field", ->
|
||||
objects = [{widget_id: 1, name: 'one'}, {widget_id: 2, name: 'two'}]
|
||||
index = Indexer.index objects, 'widget_id'
|
||||
expect(index).toEqual({1: {widget_id: 1, name: 'one'}, 2: {widget_id: 2, name: 'two'}})
|
||||
|
||||
it "returns an object, not an array", ->
|
||||
index = Indexer.index []
|
||||
expect(index.constructor).not.toEqual(Array)
|
||||
|
||||
Reference in New Issue
Block a user