Skip to content

Commit

Permalink
fix: add offset to baseRepository getByFilter
Browse files Browse the repository at this point in the history
  • Loading branch information
Kpoke committed Nov 8, 2021
1 parent 43afb86 commit 561f463
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions server/repositories/BaseRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class BaseRepository {
* support: and / or
* options:
* limit: number
* offset: number
*/
async getByFilter(filter, options) {
const whereBuilder = function (object, builder) {
Expand Down Expand Up @@ -72,6 +73,9 @@ class BaseRepository {
if (options && options.limit) {
promise = promise.limit(options && options.limit);
}
if (options && options.offset) {
promise = promise.offset(options && options.offset);
}
const result = await promise;
expect(result).a(expect.any(Array));
return result;
Expand Down
19 changes: 19 additions & 0 deletions server/repositories/BaseRepository.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,25 @@ describe('BaseRepository', () => {
expect(result[0]).property('id').eq(1);
});

it('getByFilter with offset', async () => {
tracker.uninstall();
tracker.install();
tracker.on('query', (query) => {
expect(query.sql).match(/select.*testTable.*offset.*/);
query.response([{ id: 1 }]);
});
const result = await baseRepository.getByFilter(
{
name: 'testName',
},
{
offset: 1,
},
);
expect(result).lengthOf(1);
expect(result[0]).property('id').eq(1);
});

describe("'and' 'or' phrase", () => {
it('{and: [{c:1}, {b:2}]}', async () => {
tracker.uninstall();
Expand Down

0 comments on commit 561f463

Please sign in to comment.