-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #306 from derbyjs/getValues
Add getValues method for fetching array of docs from collection
- Loading branch information
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const {expect} = require('../util'); | ||
const {RootModel} = require('../../lib'); | ||
|
||
describe('collections', () => { | ||
describe('getValues', () => { | ||
it('returns array of values from collection', () => { | ||
const model = new RootModel(); | ||
model.add('_test_docs', {name: 'foo'}); | ||
model.add('_test_docs', {name: 'bar'}); | ||
const values = model.getValues('_test_docs'); | ||
expect(values).to.be.instanceOf(Array); | ||
expect(values).to.have.lengthOf(2); | ||
['foo', 'bar'].forEach((value, index) => { | ||
expect(values[index]).to.have.property('name', value); | ||
}); | ||
}); | ||
|
||
it('return empty array when no values at subpath', () => { | ||
const model = new RootModel(); | ||
const values = model.getValues('_test_docs'); | ||
expect(values).to.be.instanceOf(Array); | ||
expect(values).to.have.lengthOf(0); | ||
}); | ||
|
||
it('throws error if non-object result at path', () => { | ||
const model = new RootModel(); | ||
const id = model.add('_colors', {rgb: 3}); | ||
expect( | ||
() => model.getValues(`_colors.${id}.rgb`) | ||
).to.throw(`Found non-object type for getValues('_colors.${id}.rgb')`); | ||
}); | ||
}); | ||
}); |