Skip to content

Commit

Permalink
test(client): add itx raw rollback
Browse files Browse the repository at this point in the history
  • Loading branch information
millsp committed Aug 12, 2021
1 parent c2ce854 commit 4ea6a74
Showing 1 changed file with 29 additions and 0 deletions.
Expand Up @@ -303,6 +303,35 @@ Invalid \`prisma.user.create()\` invocation:
expect(users.length).toBe(0)
})

/**
* A bad batch should rollback using the interactive transaction logic
*/
test('batching raw rollback', async () => {
const result = prisma.$transaction([
prisma.$executeRaw(
'INSERT INTO User (id, email) VALUES ("1", "user_1@website.com")',
),
prisma.$executeRaw(
'INSERT INTO User (id, email) VALUES ("2", "user_2@website.com")',
),
prisma.$executeRaw(
'INSERT INTO User (id, email) VALUES ("3", "user_1@website.com")',
),
])

await expect(result).rejects.toThrowErrorMatchingInlineSnapshot(`
Invalid \`prisma.executeRaw()\` invocation:
Raw query failed. Code: \`2067\`. Message: \`UNIQUE constraint failed: User.email\`
`)

const users = await prisma.user.findMany()

expect(users.length).toBe(0)
})

/**
* Middlewares should work normally on batches
*/
Expand Down

0 comments on commit 4ea6a74

Please sign in to comment.