Skip to content

Commit

Permalink
test fluent api usage
Browse files Browse the repository at this point in the history
  • Loading branch information
casey-chow committed Jun 26, 2024
1 parent a275315 commit 9482bc4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
18 changes: 18 additions & 0 deletions tests/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,24 @@ test('read query is executed against replica', async () => {
expect(logs).toEqual([{ server: 'replica', operation: 'findMany' }])
})

test('read query can resolve fluent queries against replica', async () => {
await prisma.user.create({
data: {
email: '[email protected]',
posts: {
create: [{}],
},
},
})
const res = await prisma.user.findFirst().posts().author().posts().author()

expect(logs).toEqual([
{ server: 'primary', operation: 'create' },
{ server: 'replica', operation: 'findFirst' },
])
expect(res).toMatchObject([{ email: '[email protected]' }])
})

test('write query is executed against primary', async () => {
await prisma.user.updateMany({ data: {} })

Expand Down
11 changes: 9 additions & 2 deletions tests/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ datasource db {
}

model User {
id String @id @default(uuid())
email String @unique
id String @id @db.Uuid @default(uuid())
email String
posts Post[] @relation("PostToUser")
}

model Post {
id String @id @default(uuid())
authorId String @db.Uuid
author User @relation("PostToUser", fields: [authorId], references: [id])
}

0 comments on commit 9482bc4

Please sign in to comment.