Skip to content

Commit

Permalink
test(client): add occ test with nested operation (#15550)
Browse files Browse the repository at this point in the history
  • Loading branch information
millsp committed Sep 27, 2022
1 parent 69d5d72 commit dd9a8d6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ export default testMatrix.setupSchema(({ provider }) => {
model Resource {
id ${idForProvider(provider)}
occStamp Int @default(0) @unique
child Child?
}
model Child {
id ${idForProvider(provider)}
parent Resource @relation(fields: [parentId], references: [id], onDelete: Cascade)
parentId String @unique
}
`
})
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,30 @@ testMatrix.setupTestSuite(({ provider }) => {

expect(await prisma.resource.findFirst()).toMatchObject({ occStamp: 1 })
})

test('update with upsert relation', async () => {
const fn = async () => {
const resource = (await prisma.resource.findFirst())!

expect(resource).toMatchObject({ occStamp: 0 })

await prisma.resource.update({
where: { occStamp: resource.occStamp },
data: {
occStamp: { increment: 1 },
child: {
upsert: {
create: {},
update: {},
},
},
},
})
}

await Promise.allSettled([fn(), fn(), fn(), fn(), fn()])

expect(await prisma.resource.findFirst()).toMatchObject({ occStamp: 1 })
expect(await prisma.child.count()).toBe(1)
})
})

0 comments on commit dd9a8d6

Please sign in to comment.