Skip to content

Commit

Permalink
test: add multiple tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Barbapapazes committed Feb 24, 2023
1 parent 8262556 commit 63f2a9d
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions test/features/query/query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,45 @@ describe('Database Provider', () => {

test('Count items', async () => {
const fetcher = createPipelineFetcher(() => Promise.resolve([{ id: 1, _path: '/a' }, { id: 2, _path: '/b' }, { id: 3, _path: '/c' }] as any[]))

const result = await createQuery(fetcher)
.count()

assert(result === 3)
})

test('Count items with where condition', async () => {
const fetcher = createPipelineFetcher(() => Promise.resolve([{ id: 1, _path: '/a' }, { id: 2, _path: '/b' }, { id: 3, _path: '/c' }] as any[]))

const result = await createQuery(fetcher)
.where({ _path: { $contains: 'b' } })
.count()

assert(result === 1)
})

test('Count items with where condition and without method', async () => {
const fetcher = createPipelineFetcher(() => Promise.resolve([{ id: 1, _path: '/a' }, { id: 2, _path: '/b' }, { id: 3, _path: '/c' }] as any[]))

const result = await createQuery(fetcher)
.where({ _path: { $contains: 'b' } })
.without('id')
.count()

assert(result === 1)
})

test('Count items with where condition and only method', async () => {
const fetcher = createPipelineFetcher(() => Promise.resolve([{ id: 1, _path: '/a' }, { id: 2, _path: '/b' }, { id: 3, _path: '/c' }] as any[]))

const result = await createQuery(fetcher)
.where({ _path: { $contains: 'b' } })
.only(['_path'])
.count()

assert(result === 1)
})

test('Chain multiple where conditions', async () => {
const fetcher = createPipelineFetcher(() => Promise.resolve([{ id: 1, path: '/a' }, { id: 2, path: '/b' }, { id: 3, path: '/c' }] as any[]))
const query = createQuery(fetcher).where({ id: { $in: [1, 2] } })
Expand Down

0 comments on commit 63f2a9d

Please sign in to comment.