mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-08 03:20:12 +08:00
refactor: add Pagination class
This commit is contained in:
1 parent
19cd10ab7b
commit
68db16419d
9 files changed
+99
-89
No files matched your search
@@ -0,0 +1,37 @@
|
||||
import mongoose from 'mongoose'
|
||||
import { Desc } from '../src/models/pagination.js'
|
||||
|
||||
describe('Pagination', () => {
|
||||
it('should return correct limit', async () => {
|
||||
const pagination = new Desc(10)
|
||||
|
||||
expect(pagination.limit()).toMatchObject({ $limit: 10 })
|
||||
})
|
||||
|
||||
it('should return correct order', async () => {
|
||||
const pagination = new Desc(10)
|
||||
|
||||
expect(pagination.order('_id')).toMatchObject({ $sort: { _id: -1 } })
|
||||
expect(pagination.order('time')).toMatchObject({ $sort: { time: -1 } })
|
||||
})
|
||||
|
||||
it('should return correct match stage for empty nextKey', async () => {
|
||||
const pagination = new Desc(10)
|
||||
|
||||
expect(pagination.matchStage('_id')).toMatchObject({ $match: {} })
|
||||
})
|
||||
|
||||
it('should return correct match stage for empty nextKey', async () => {
|
||||
const nextKeyStr = '656c7fea28a4c087bfcefe12'
|
||||
const pagination = new Desc(10, nextKeyStr)
|
||||
const nextKey = new mongoose.Types.ObjectId(nextKeyStr)
|
||||
|
||||
expect(pagination.matchStage('_id')).toMatchObject({
|
||||
$match: {
|
||||
_id: {
|
||||
$lt: nextKey,
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user