-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
test.ts
52 lines (44 loc) · 1.16 KB
/
test.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
47
48
49
50
51
52
import { getTestClient } from '../../../../utils/getTestClient'
test('middlewares-manipulation', async () => {
const PrismaClient = await getTestClient()
const prisma = new PrismaClient()
let theParams
let firstCall = true
prisma.$use(async (params, next) => {
theParams = JSON.parse(JSON.stringify(params)) // clone
if (firstCall) {
params.args = {
where: {
email: 'asdasd', // this user doesn't exist
},
}
firstCall = false
}
const result = await next(params)
return result
})
prisma.$use(async (params, next) => {
const result = await next(params)
if (result.length > 0) {
result[0].name += '2' // make sure that we can change the result
}
return result
})
const users = await prisma.user.findMany()
expect(theParams).toEqual({
dataPath: [],
runInTransaction: false,
action: 'findMany',
model: 'User',
})
expect(users).toEqual([])
const users2 = await prisma.user.findMany()
expect(users2).toEqual([
{
email: 'a@a.de',
id: '576eddf9-2434-421f-9a86-58bede16fd95',
name: 'Alice2',
},
])
await prisma.$disconnect()
})