-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
tests.ts
46 lines (40 loc) · 1.45 KB
/
tests.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { faker } from '@faker-js/faker'
import testMatrix from './_matrix'
// @ts-ignore
import type { PrismaClient } from './node_modules/@prisma/client'
declare let prisma: PrismaClient
const missing = faker.database.mongodbObjectId()
testMatrix.setupTestSuite((suiteConfig, suiteMeta, clientMeta) => {
let id1: string
let id2: string
beforeAll(async () => {
id1 = await prisma.user
.create({
data: {},
})
.then((user) => user.id)
id2 = await prisma.user
.create({
data: {},
})
.then((user) => user.id)
})
test('batched errors are when all objects in batch are found', async () => {
const found = prisma.user.findUniqueOrThrow({ where: { id: id1 } })
const foundToo = prisma.user.findUniqueOrThrow({ where: { id: id2 } })
const result = await Promise.allSettled([found, foundToo])
expect(result).toEqual([
{ status: 'fulfilled', value: { id: id1 } },
{ status: 'fulfilled', value: { id: id2 } },
])
})
test('batched errors when some of the objects not found', async () => {
const found = prisma.user.findUniqueOrThrow({ where: { id: id1 } })
const notFound = prisma.user.findUniqueOrThrow({ where: { id: missing } })
const newResult = await Promise.allSettled([found, notFound])
expect(newResult).toEqual([
{ status: 'fulfilled', value: { id: id1 } },
{ status: 'rejected', reason: expect.objectContaining({ code: 'P2025' }) },
])
})
}, {})