Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(client): 2.29.1 fixes #8720

Merged
merged 9 commits into from Aug 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -303,6 +303,42 @@ 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 () => {
await prisma.user.create({
data: {
email: 'user_1@website.com',
},
})

const result = prisma.$transaction([
prisma.$executeRaw(
'INSERT INTO User (id, email) VALUES ("2", "user_2@website.com")',
),
prisma.$queryRaw('DELETE FROM User'),
prisma.$executeRaw(
'INSERT INTO User (id, email) VALUES ("1", "user_1@website.com")',
),
prisma.$executeRaw(
'INSERT INTO User (id, email) VALUES ("1", "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(1)
})

/**
* Middlewares should work normally on batches
*/
Expand Down
@@ -0,0 +1 @@
!dev.db
Binary file not shown.
@@ -0,0 +1,29 @@
datasource db {
provider = "sqlite"
url = "file:dev.db"
}

generator client {
provider = "prisma-client-js"
}

// / User model comment
model User {
id String @default(uuid()) @id
email String @unique
age Int
// / name comment
name String?
posts Post[]
}

model Post {
id String @default(cuid()) @id
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
published Boolean
title String
content String?
authorId String?
author User? @relation(fields: [authorId], references: [id])
}
@@ -0,0 +1,68 @@
import { getTestClient } from '../../../../utils/getTestClient'
describe('prisma promises', () => {
/**
* Requests must get sent if we call `.catch`
*/
test('catch', async () => {
const PrismaClient = await getTestClient()
const prisma = new PrismaClient()
const handler = (e) => Promise.reject(e)

const remove = await prisma.user.deleteMany().catch(handler)
const queryRaw = await prisma.$queryRaw('SELECT 1').catch(handler)
const executeRaw = await prisma
.$executeRaw('DELETE FROM User')
.catch(handler)
const findMany = await prisma.user.findMany().catch(handler)

expect(remove).toMatchInlineSnapshot(`
Object {
count: 0,
}
`)
expect(queryRaw).toMatchInlineSnapshot(`
Array [
Object {
1: 1,
},
]
`)
expect(executeRaw).toMatchInlineSnapshot(`0`)
expect(findMany).toMatchInlineSnapshot(`Array []`)

await prisma.$disconnect()
})

/**
* Requests must get sent if we call `.finally`
*/
test('finally', async () => {
const PrismaClient = await getTestClient()
const prisma = new PrismaClient()
const handler = () => {}

const remove = await prisma.user.deleteMany().finally(handler)
const queryRaw = await prisma.$queryRaw('SELECT 1').finally(handler)
const executeRaw = await prisma
.$executeRaw('DELETE FROM User')
.finally(handler)
const findMany = await prisma.user.findMany().finally(handler)

expect(remove).toMatchInlineSnapshot(`
Object {
count: 0,
}
`)
expect(queryRaw).toMatchInlineSnapshot(`
Array [
Object {
1: 1,
},
]
`)
expect(executeRaw).toMatchInlineSnapshot(`0`)
expect(findMany).toMatchInlineSnapshot(`Array []`)

await prisma.$disconnect()
})
})