mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-07 19:10:12 +08:00
refactor: move analytics into services directory
This commit is contained in:
1 parent
e43cbe26ce
commit
740cbcecb4
31 files changed
+6
-5
No files matched your search
@@ -0,0 +1,48 @@
|
||||
import mongoose from 'mongoose'
|
||||
import Pagination, { ASC, DESC } from '../src/models/pagination.js'
|
||||
|
||||
describe('Pagination', () => {
|
||||
it('should failed when not provide order', () => {
|
||||
expect(new Pagination('').getOrder()).toBe(DESC)
|
||||
expect(() => new Pagination('Hahaha')).toThrow()
|
||||
})
|
||||
it('should return correct limit', () => {
|
||||
const pagination = new Pagination(DESC, 10)
|
||||
|
||||
expect(pagination.limit()).toMatchObject({ $limit: 10 })
|
||||
})
|
||||
|
||||
it('desc should return correct order', async () => {
|
||||
const pagination = new Pagination(DESC, 10)
|
||||
|
||||
expect(pagination.sort('_id')).toMatchObject({ $sort: { _id: -1 } })
|
||||
expect(pagination.sort('time')).toMatchObject({ $sort: { time: -1 } })
|
||||
})
|
||||
|
||||
it('asc should return correct order', async () => {
|
||||
const pagination = new Pagination(ASC, 10)
|
||||
|
||||
expect(pagination.sort('_id')).toMatchObject({ $sort: { _id: 1 } })
|
||||
expect(pagination.sort('time')).toMatchObject({ $sort: { time: 1 } })
|
||||
})
|
||||
|
||||
it('should return correct match stage for empty nextKey', async () => {
|
||||
const pagination = new Pagination(DESC, 10)
|
||||
|
||||
expect(pagination.match('_id')).toMatchObject({ $match: {} })
|
||||
})
|
||||
|
||||
it('should return correct match stage for empty nextKey', async () => {
|
||||
const nextKeyStr = '656c7fea28a4c087bfcefe12'
|
||||
const pagination = new Pagination(DESC, 10, nextKeyStr)
|
||||
const nextKey = new mongoose.Types.ObjectId(nextKeyStr)
|
||||
|
||||
expect(pagination.match('_id')).toMatchObject({
|
||||
$match: {
|
||||
_id: {
|
||||
$lt: nextKey,
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user