aggregate.ts•922 B
import { faker } from '@faker-js/faker'
import { setupTestSuite } from './_matrix'
// @ts-ignore
import type { PrismaClient } from './generated/prisma/client'
declare let prisma: PrismaClient
const id = faker.database.mongodbObjectId()
setupTestSuite(() => {
beforeAll(async () => {
await prisma.comment.create({
data: {
id,
country: 'France',
content: {
set: {
text: 'Hello World',
upvotes: {
vote: true,
userId: '10',
},
},
},
},
})
})
/**
* Simple aggregate
*/
test('aggregate', async () => {
const comment = await prisma.comment.aggregate({
where: { id },
orderBy: {
content: {
upvotes: {
_count: 'desc',
},
},
},
_count: true,
})
expect(comment).toEqual({ _count: 1 })
})
})