Added _limit param. Example usage: _start=2&_limit=3 alternative to _start=2&_end=5.

This commit is contained in:
Binali Rustamov
2015-04-28 15:16:14 +06:00
parent 23b0faf892
commit 34b95e2bac
4 changed files with 104 additions and 53 deletions

View File

@ -1,5 +1,5 @@
var assert = require('assert')
var utils = require('../src/utils')
var utils = require('../src/utils')
describe('utils', function() {
@ -20,8 +20,8 @@ describe('utils', function() {
}
var expected = [
{ name: 'comments', id: 2 },
{ name: 'comments', id: 3 }
{name: 'comments', id: 2},
{name: 'comments', id: 3}
]
assert.deepEqual(utils.getRemovable(db), expected)
@ -46,4 +46,28 @@ describe('utils', function() {
})
})
describe('limitArray', function() {
it('should return limited array', function() {
var testArray = [
{id: 2, postId: 2},
{id: 3, postId: 4},
{id: 4, postId: 6},
{id: 5, postId: 8},
{id: 6, postId: 9},
{id: 7, postId: 10},
{id: 8, postId: 11},
{id: 9, postId: 12},
{id: 10, postId: 13},
{id: 11, postId: 14},
{id: 12, postId: 15},
{id: 13, postId: 16},
{id: 14, postId: 17},
{id: 15, postId: 18},
{id: 16, postId: 19}
]
assert.deepEqual(utils.limitArray(testArray, 3, 3), testArray.slice(3, 6))
assert.deepEqual(utils.limitArray(testArray, 5, 3), testArray.slice(5, 8))
})
})
})