Skip to content

Commit

Permalink
test(client): upper-cased chaining api
Browse files Browse the repository at this point in the history
  • Loading branch information
millsp committed Feb 9, 2022
1 parent 95926d3 commit 0dbb401
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ model User {
likes Like[]
property Property @relation(fields: [propertyId], references: [id])
propertyId String
Banking Banking?
}

model Property {
Expand All @@ -28,7 +29,7 @@ model Property {

model House {
id String @id @default(cuid())
Like Like @relation(fields: [likeId], references: [id])
like Like @relation(fields: [likeId], references: [id])
properties Property[]
likeId String
}
Expand All @@ -55,3 +56,11 @@ model Like {
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
}
206 changes: 122 additions & 84 deletions packages/client/src/__tests__/integration/happy/chaining/test.ts
Original file line number Diff line number Diff line change
@@ -1,95 +1,133 @@
import { getTestClient } from '../../../../utils/getTestClient'

test('chaining', async () => {
const PrismaClient = await getTestClient()
const prisma = new PrismaClient()
describe('chaining', () => {
test('lower-cased relations', async () => {
const PrismaClient = await getTestClient()
const prisma = new PrismaClient()

const a: any[] = []
a.push(
await prisma.user
.findUnique({
where: {
email: 'a@a.de',
},
})
.property(),
)
const a: any[] = []
a.push(
await prisma.user
.findUnique({
where: {
email: 'a@a.de',
},
})
.property(),
)

a.push(
await prisma.user
.findUnique({
where: {
email: 'a@a.de',
},
})
.property()
.house(),
)
a.push(
await prisma.user
.findUnique({
where: {
email: 'a@a.de',
},
})
.property()
.house(),
)

a.push(
await prisma.user
.findUnique({
where: {
email: 'a@a.de',
},
})
.property()
.house()
.Like(),
)
a.push(
await prisma.user
.findUnique({
where: {
email: 'a@a.de',
},
})
.property()
.house()
.like(),
)

a.push(
await prisma.user
.findUnique({
where: {
email: 'a@a.de',
},
})
.property()
.house()
.Like()
.post(),
)
a.push(
await prisma.user
.findUnique({
where: {
email: 'a@a.de',
},
})
.property()
.house()
.like()
.post(),
)

a.push(
await prisma.user
.findUnique({
where: {
email: 'a@a.de',
},
})
.property()
.house()
.Like()
.post()
.author(),
)
a.push(
await prisma.user
.findUnique({
where: {
email: 'a@a.de',
},
})
.property()
.house()
.like()
.post()
.author(),
)

a.push(
await prisma.user
.findUnique({
where: {
email: 'a@a.de',
},
})
.property()
.house()
.Like()
.post()
.author()
.property(),
)
a.push(
await prisma.user
.findUnique({
where: {
email: 'a@a.de',
},
})
.property()
.house()
.like()
.post()
.author()
.property(),
)

await prisma.$disconnect()
await prisma.$disconnect()

expect(a).toMatchInlineSnapshot(`
Array [
null,
null,
null,
null,
null,
null,
]
`)
expect(a).toMatchInlineSnapshot(`
Array [
null,
null,
null,
null,
null,
null,
]
`)
})

test('upper-cased relations', async () => {
const PrismaClient = await getTestClient()
const prisma = new PrismaClient()

const a: any[] = []
a.push(
await prisma.user
.findUnique({
where: {
email: 'a@a.de',
},
})
.Banking(),
)

a.push(
await prisma.user
.findUnique({
where: {
email: 'a@a.de',
},
})
.Banking()
.user(),
)

await prisma.$disconnect()

expect(a).toMatchInlineSnapshot(`
Array [
null,
null,
]
`)
})
})

0 comments on commit 0dbb401

Please sign in to comment.