Skip to content

Commit

Permalink
test(client): move to prismaPromise
Browse files Browse the repository at this point in the history
  • Loading branch information
millsp committed Feb 9, 2022
1 parent adf4da5 commit eba5d17
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 70 deletions.
70 changes: 0 additions & 70 deletions packages/client/src/__tests__/integration/happy/chaining/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,76 +122,6 @@ describe('chaining', () => {
`)
})

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()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!dev.db
Binary file not shown.
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
}
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()
})
})

0 comments on commit eba5d17

Please sign in to comment.