Skip to content

Commit 0458037

Browse files
committed
more tests
1 parent 99a9835 commit 0458037

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

tests/integration/tests/enhancements/with-delegate/enhanced-client.test.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,66 @@ describe('Polymorphism Test', () => {
378378
).resolves.toHaveLength(1);
379379
});
380380

381+
it('read with counting relation defined in base', async () => {
382+
const { enhance } = await loadSchema(
383+
`
384+
385+
model A {
386+
id Int @id @default(autoincrement())
387+
type String
388+
bs B[]
389+
cs C[]
390+
@@delegate(type)
391+
}
392+
393+
model A1 extends A {
394+
a1 Int
395+
type1 String
396+
@@delegate(type1)
397+
}
398+
399+
model A2 extends A1 {
400+
a2 Int
401+
}
402+
403+
model B {
404+
id Int @id @default(autoincrement())
405+
a A @relation(fields: [aId], references: [id])
406+
aId Int
407+
b Int
408+
}
409+
410+
model C {
411+
id Int @id @default(autoincrement())
412+
a A @relation(fields: [aId], references: [id])
413+
aId Int
414+
c Int
415+
}
416+
`,
417+
{ enhancements: ['delegate'] }
418+
);
419+
const db = enhance();
420+
421+
const a2 = await db.a2.create({
422+
data: { a1: 1, a2: 2, bs: { create: [{ b: 1 }, { b: 2 }] }, cs: { create: [{ c: 1 }] } },
423+
include: { _count: { select: { bs: true } } },
424+
});
425+
expect(a2).toMatchObject({ a1: 1, a2: 2, _count: { bs: 2 } });
426+
427+
await expect(
428+
db.a2.findFirst({ select: { a1: true, _count: { select: { bs: true } } } })
429+
).resolves.toStrictEqual({
430+
a1: 1,
431+
_count: { bs: 2 },
432+
});
433+
434+
await expect(db.a.findFirst({ select: { _count: { select: { bs: true, cs: true } } } })).resolves.toMatchObject(
435+
{
436+
_count: { bs: 2, cs: 1 },
437+
}
438+
);
439+
});
440+
381441
it('order by base fields', async () => {
382442
const { db, user } = await setup();
383443

0 commit comments

Comments
 (0)