Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { defineMatrix } from '../../_utils/defineMatrix' | ||
import { allProviders } from '../../_utils/providers' | ||
|
||
export default defineMatrix(() => [allProviders]) |
36 changes: 36 additions & 0 deletions
36
packages/client/tests/functional/issues/12862/prisma/_schema.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { idForProvider } from '../../../_utils/idForProvider' | ||
import testMatrix from '../_matrix' | ||
|
||
export default testMatrix.setupSchema(({ provider }) => { | ||
return /* Prisma */ ` | ||
generator client { | ||
provider = "prisma-client-js" | ||
previewFeatures = ["interactiveTransactions"] | ||
engineType = "binary" | ||
} | ||
datasource db { | ||
provider = "${provider}" | ||
url = env("DATABASE_URI_${provider}") | ||
} | ||
model User { | ||
id ${idForProvider(provider)} | ||
email String @unique | ||
name String? | ||
posts Post[] | ||
} | ||
model Post { | ||
id ${idForProvider(provider)} | ||
createdAt DateTime @default(now()) | ||
updatedAt DateTime @updatedAt | ||
title String | ||
content String? | ||
published Boolean @default(false) | ||
viewCount Int @default(0) | ||
author User? @relation(fields: [authorId], references: [id]) | ||
authorId String? | ||
} | ||
` | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { faker } from '@faker-js/faker' | ||
import { ClientEngineType, getClientEngineType } from '@prisma/internals' | ||
|
||
import testMatrix from './_matrix' | ||
// @ts-ignore | ||
import type { PrismaClient } from './node_modules/@prisma/client' | ||
|
||
declare let prisma: PrismaClient | ||
|
||
// https://github.com/prisma/prisma/issues/12862 | ||
testMatrix.setupTestSuite( | ||
() => { | ||
if (getClientEngineType() !== ClientEngineType.Binary) { | ||
return | ||
} | ||
|
||
test('should propagate the correct error when a method fails inside an transaction', async () => { | ||
const user = await prisma.user.create({ | ||
data: { | ||
email: faker.internet.email(), | ||
name: faker.name.firstName(), | ||
}, | ||
}) | ||
|
||
await expect( | ||
prisma.$transaction([ | ||
prisma.post.create({ | ||
data: { | ||
authorId: user.id, | ||
title: faker.lorem.sentence(), | ||
viewCount: -1, // should fail, must be >= 0 | ||
}, | ||
}), | ||
]), | ||
).rejects.toThrowError('violates check constraint \\"Post_viewCount_check\\"') | ||
}) | ||
|
||
test('should propagate the correct error when a method fails inside an interactive transaction', async () => { | ||
await expect( | ||
prisma.$transaction(async (client) => { | ||
const user = await client.user.create({ | ||
data: { | ||
email: faker.internet.email(), | ||
name: faker.name.firstName(), | ||
}, | ||
}) | ||
|
||
const post = await client.post.create({ | ||
data: { | ||
authorId: user.id, | ||
title: faker.lorem.sentence(), | ||
viewCount: -1, // should fail, must be >= 0 | ||
}, | ||
}) | ||
|
||
return post | ||
}), | ||
).rejects.toThrowError('violates check constraint \\"Post_viewCount_check\\"') | ||
}) | ||
}, | ||
{ | ||
optOut: { | ||
from: ['cockroachdb', 'mongodb', 'mysql', 'sqlite', 'sqlserver'], | ||
reason: 'bla', | ||
}, | ||
}, | ||
) |