Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
ymc9 committed Nov 13, 2024
1 parent b99f14b commit e7f6b54
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions tests/regression/tests/issue-prisma-extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('issue prisma extension', () => {
});

it('enhance extended client', async () => {
const { enhanceRaw, prisma } = await loadSchema(
const { enhanceRaw, prisma, prismaModule } = await loadSchema(
`
model Post {
id Int @id
Expand All @@ -55,28 +55,31 @@ describe('issue prisma extension', () => {
await prisma.post.create({ data: { id: 1, title: 'post1', published: true } });
await prisma.post.create({ data: { id: 2, title: 'post2', published: false } });

const extended = prisma.$extends({
model: {
post: {
findManyListView: async (args: any) => {
return { view: true, data: await prisma.post.findMany(args) };
const ext = prismaModule.defineExtension((_prisma: any) => {
return _prisma.$extends({
model: {
post: {
findManyListView: async (args: any) => {
return { view: true, data: await prisma.post.findMany(args) };
},
},
},
},
});
});

await expect(extended.post.findMany()).resolves.toHaveLength(2);
await expect(extended.post.findManyListView()).resolves.toMatchObject({
await expect(prisma.$extends(ext).post.findMany()).resolves.toHaveLength(2);
await expect(prisma.$extends(ext).post.findManyListView()).resolves.toMatchObject({
view: true,
data: [
{ id: 1, title: 'post1', published: true },
{ id: 2, title: 'post2', published: false },
],
});

const db = enhanceRaw(extended);
await expect(db.post.findMany()).resolves.toHaveLength(1);
await expect(db.post.findManyListView()).resolves.toMatchObject({
const enhanced = enhanceRaw(prisma.$extends(ext));
await expect(enhanced.post.findMany()).resolves.toHaveLength(1);
// findManyListView internally uses the un-enhanced client
await expect(enhanced.post.findManyListView()).resolves.toMatchObject({
view: true,
data: [
{ id: 1, title: 'post1', published: true },
Expand Down

0 comments on commit e7f6b54

Please sign in to comment.