Skip to content

Commit

Permalink
feat(limit): default to 25 docs #32
Browse files Browse the repository at this point in the history
  • Loading branch information
TillaTheHun0 committed Aug 17, 2023
1 parent 3135ec5 commit 48634d3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { HyperErr } from 'https://raw.githubusercontent.com/hyper63/hyper/hyper-utils%40v0.1.0/packages/utils/hyper-err.js'
import { isHyperErr } from './deps.ts'
import { assert, assertEquals } from './dev_deps.ts'
import { assert, assertEquals, assertObjectMatch } from './dev_deps.ts'

import { mapSort, mongoErrToHyperErr, queryOptions, toBulkOperations } from './utils.ts'
import { assertObjectMatch } from 'https://deno.land/[email protected]/testing/asserts.ts'

Deno.test('utils', async (t) => {
await t.step('toBulkOperations', async (t) => {
Expand Down Expand Up @@ -50,19 +49,24 @@ Deno.test('utils', async (t) => {
assertEquals(res, { limit: 123 })
})

await t.step('should default the limit to 25', () => {
const res = queryOptions({})
assertEquals(res, { limit: 25 })
})

await t.step('should map fields to projection', () => {
const res = queryOptions({ fields: ['_id', 'foo', 'bar'] })
assertEquals(res, { projection: { foo: 1, bar: 1, _id: 1 } })
assertObjectMatch(res, { projection: { foo: 1, bar: 1, _id: 1 } })
})

await t.step('should disclude _id in projection by default', () => {
const res = queryOptions({ fields: ['foo', 'bar'] })
assertEquals(res, { projection: { foo: 1, bar: 1, _id: 0 } })
assertObjectMatch(res, { projection: { foo: 1, bar: 1, _id: 0 } })
})

await t.step('should map hyper sort to mongo sort', () => {
const res = queryOptions({ sort: ['_id', 'bar'] })
assertEquals(res, { sort: { _id: 1, bar: 1 } })
assertObjectMatch(res, { sort: { _id: 1, bar: 1 } })
})
})

Expand Down
2 changes: 1 addition & 1 deletion utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const queryOptions = ({
/**
* See https://www.mongodb.com/docs/manual/reference/operator/aggregation/limit/
*/
...(limit ? { limit: Number(limit) } : {}),
...(limit ? { limit: Number(limit) } : { limit: 25 }),
...(fields
? {
projection: fields.reduce(
Expand Down

0 comments on commit 48634d3

Please sign in to comment.