|
1 | 1 | import { assert } from 'vitest' |
2 | 2 | import { disablePagination } from './disable-pagination.hook.js' |
| 3 | +import type { HookContext } from '@feathersjs/feathers' |
3 | 4 |
|
4 | | -let hookBefore: any |
5 | | - |
6 | | -describe('services disablePagination', () => { |
7 | | - beforeEach(() => { |
8 | | - hookBefore = { |
| 5 | +describe('hook - disablePagination', () => { |
| 6 | + it('disables on $limit = -1', () => { |
| 7 | + const result: any = disablePagination()({ |
9 | 8 | type: 'before', |
10 | 9 | method: 'find', |
11 | 10 | params: { query: { id: 1, $limit: -1 } }, |
12 | | - } |
| 11 | + } as HookContext) |
| 12 | + assert.deepEqual(result.params, { paginate: false, query: { id: 1 } }) |
13 | 13 | }) |
14 | 14 |
|
15 | | - it('disables on $limit = -1', () => { |
16 | | - hookBefore.params.query.$limit = -1 |
17 | | - |
18 | | - const result: any = disablePagination()(hookBefore) |
| 15 | + it('disables on $limit = "-1"', () => { |
| 16 | + const result: any = disablePagination()({ |
| 17 | + type: 'before', |
| 18 | + method: 'find', |
| 19 | + params: { query: { id: 1, $limit: '-1' } }, |
| 20 | + } as HookContext) |
19 | 21 | assert.deepEqual(result.params, { paginate: false, query: { id: 1 } }) |
20 | 22 | }) |
21 | 23 |
|
22 | | - it('disables on $limit = "-1"', () => { |
23 | | - hookBefore.params.query.$limit = '-1' |
| 24 | + it('disables on $limit = -1 in around', () => { |
| 25 | + const result: any = disablePagination()({ |
| 26 | + type: 'around', |
| 27 | + method: 'find', |
| 28 | + params: { query: { id: 1, $limit: -1 } }, |
| 29 | + } as HookContext) |
| 30 | + assert.deepEqual(result.params, { paginate: false, query: { id: 1 } }) |
| 31 | + }) |
24 | 32 |
|
25 | | - const result: any = disablePagination()(hookBefore) |
| 33 | + it('disables on $limit = "-1" in around', () => { |
| 34 | + const result: any = disablePagination()({ |
| 35 | + type: 'around', |
| 36 | + method: 'find', |
| 37 | + params: { query: { id: 1, $limit: '-1' } }, |
| 38 | + } as HookContext) |
26 | 39 | assert.deepEqual(result.params, { paginate: false, query: { id: 1 } }) |
27 | 40 | }) |
28 | 41 |
|
29 | 42 | it('throws if after hook', () => { |
30 | | - hookBefore.type = 'after' |
31 | | - |
32 | 43 | assert.throws(() => { |
33 | | - disablePagination()(hookBefore) |
| 44 | + disablePagination()({ |
| 45 | + type: 'after', |
| 46 | + method: 'find', |
| 47 | + params: { query: { id: 1, $limit: -1 } }, |
| 48 | + } as HookContext) |
34 | 49 | }) |
35 | 50 | }) |
36 | 51 |
|
37 | 52 | it('throws if not find', () => { |
38 | | - hookBefore.method = 'get' |
39 | | - |
40 | 53 | assert.throws(() => { |
41 | | - disablePagination()(hookBefore) |
| 54 | + disablePagination()({ |
| 55 | + type: 'before', |
| 56 | + method: 'get', |
| 57 | + params: { query: { id: 1, $limit: -1 } }, |
| 58 | + } as HookContext) |
42 | 59 | }) |
43 | 60 | }) |
44 | 61 | }) |
0 commit comments