-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
5 changed files
with
154 additions
and
70 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
1 change: 1 addition & 0 deletions
1
packages/client/src/__tests__/integration/happy/prismaPromise/.gitignore
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 @@ | ||
!dev.db |
Binary file not shown.
66 changes: 66 additions & 0 deletions
66
packages/client/src/__tests__/integration/happy/prismaPromise/schema.prisma
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,66 @@ | ||
datasource db { | ||
provider = "sqlite" | ||
url = "file:dev.db" | ||
} | ||
|
||
generator client { | ||
provider = "prisma-client-js" | ||
binaryTargets = ["native"] | ||
} | ||
|
||
model User { | ||
id String @id @default(cuid()) | ||
email String @unique | ||
name String? | ||
age Int? | ||
posts Post[] | ||
likes Like[] | ||
property Property? @relation(fields: [propertyId], references: [id]) | ||
propertyId String? | ||
Banking Banking? | ||
} | ||
|
||
model Property { | ||
id String @id @default(cuid()) | ||
house House @relation(fields: [houseId], references: [id]) | ||
users User[] | ||
houseId String | ||
} | ||
|
||
model House { | ||
id String @id @default(cuid()) | ||
like Like @relation(fields: [likeId], references: [id]) | ||
properties Property[] | ||
likeId String | ||
} | ||
|
||
model Post { | ||
id String @id @default(cuid()) | ||
createdAt DateTime @default(now()) | ||
updatedAt DateTime @updatedAt | ||
published Boolean | ||
title String | ||
content String? | ||
authorId String? | ||
author User? @relation(fields: [authorId], references: [id]) | ||
Like Like[] | ||
} | ||
|
||
model Like { | ||
id String @id @default(cuid()) | ||
userId String | ||
user User @relation(fields: [userId], references: [id]) | ||
postId String | ||
post Post @relation(fields: [postId], references: [id]) | ||
House House[] | ||
@@unique([userId, postId]) | ||
} | ||
|
||
model Banking { | ||
id String @id @default(cuid()) | ||
userId String | ||
user User? @relation(fields: [userId], references: [id]) | ||
iban String | ||
bic String | ||
} |
87 changes: 87 additions & 0 deletions
87
packages/client/src/__tests__/integration/happy/prismaPromise/test.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,87 @@ | ||
import { getTestClient } from '../../../../utils/getTestClient' | ||
|
||
let prisma | ||
describe('prismaPromise', () => { | ||
test('repeated calls to .then', async () => { | ||
const createPromise = prisma.user.create({ | ||
data: { | ||
email: 'email@email.em', | ||
}, | ||
}) | ||
|
||
// repeated calls to then should not change the result | ||
const createResult1 = await createPromise.then() | ||
const createResult2 = await createPromise.then() | ||
|
||
expect(createResult1).toStrictEqual(createResult2) | ||
}) | ||
|
||
test('repeated calls to .catch', async () => { | ||
const createPromise = prisma.user.create({ | ||
data: { | ||
email: 'email@email.em', | ||
}, | ||
}) | ||
|
||
// repeated calls to catch should not change the result | ||
const createResult1 = await createPromise.catch() | ||
const createResult2 = await createPromise.catch() | ||
|
||
expect(createResult1).toStrictEqual(createResult2) | ||
}) | ||
|
||
test('repeated calls to .finally', async () => { | ||
const createPromise = prisma.user.create({ | ||
data: { | ||
email: 'email@email.em', | ||
}, | ||
}) | ||
|
||
// repeated calls to finally should not change the result | ||
const createResult1 = await createPromise.finally() | ||
const createResult2 = await createPromise.finally() | ||
|
||
expect(createResult1).toStrictEqual(createResult2) | ||
}) | ||
|
||
test('repeated mixed calls to .then, .catch, .finally', async () => { | ||
const createPromise = prisma.user.create({ | ||
data: { | ||
email: 'email@email.em', | ||
}, | ||
}) | ||
|
||
// repeated calls to then & co should not change the result | ||
const createResult1 = await createPromise.finally().then().catch() | ||
const createResult2 = await createPromise.catch().finally().then() | ||
|
||
expect(createResult1).toStrictEqual(createResult2) | ||
}) | ||
|
||
test('repeated calls to .requestTransaction', async () => { | ||
const createPromise = prisma.user.create({ | ||
data: { | ||
email: 'email@email.em', | ||
}, | ||
}) | ||
|
||
// repeated calls to then & co should not change the result | ||
const createResult1 = await createPromise.requestTransaction(1) | ||
const createResult2 = await createPromise.requestTransaction(1) | ||
|
||
expect(createResult1).toStrictEqual(createResult2) | ||
}) | ||
|
||
beforeAll(async () => { | ||
const PrismaClient = await getTestClient() | ||
prisma = new PrismaClient() | ||
}) | ||
|
||
beforeEach(async () => { | ||
await prisma.user.deleteMany() | ||
}) | ||
|
||
afterAll(async () => { | ||
await prisma.$disconnect() | ||
}) | ||
}) |