Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
name: Tests
on:
push:
branches: [main]
pull_request:

permissions:
contents: read

jobs:
test:
name: Tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: true

- name: Install node v22
uses: actions/setup-node@v7
with:
node-version: 22

- name: Install modules
run: yarn install

- name: Run tests
run: yarn test
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
},
"devDependencies": {
"@nestjs/cli": "9.5.0",
"@types/jest": "^29.5.14",
"@types/node": "^18.15.11",
"@types/passport-http": "^0.3.9",
"@types/password": "^0.1.0",
Expand All @@ -80,7 +81,9 @@
"eslint": "^8.36.0",
"eslint-plugin-import": "^2.27.5",
"husky": "^8.0.3",
"jest": "^29.7.0",
"lint-staged": "^13.2.0",
"ts-jest": "^29.2.5",
"ts-node": "^10.9.1",
"typescript": "^4.9.5"
},
Expand Down
25 changes: 25 additions & 0 deletions src/services/mongo/pagination.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import Pagination from './pagination';

describe('Pagination', () => {
it('returns everything on an unlimited endpoint when no page size is asked for', () => {
expect(new Pagination({}).getKey()).toBe('O:undefined-T:undefined-S:undefined');
});

it('caps a limited endpoint at 100 rows by default', () => {
expect(new Pagination({}, true).getKey()).toBe('O:undefined-T:100-S:undefined');
});

it('honours a requested page size up to 1000', () => {
expect(new Pagination({pageSize: 250}, true).getKey()).toContain('T:250');
expect(new Pagination({pageSize: 5000}, true).getKey()).toContain('T:1000');
});

it('skips whole pages of the requested size', () => {
expect(new Pagination({pageSize: 20, page: 3}).getKey()).toContain('T:20-S:40');
});

it('sorts ascending unless told otherwise', () => {
expect(new Pagination({sortBy: 'kills'}).getKey()).toContain('O:{"kills":"ASC"}');
expect(new Pagination({sortBy: 'kills', order: 'desc'}).getKey()).toContain('O:{"kills":"DESC"}');
});
});
Loading
Loading