|
| 1 | +import { loadSchema } from '@zenstackhq/testtools'; |
| 2 | +describe('issue 1522', () => { |
| 3 | + it('regression', async () => { |
| 4 | + const { enhance } = await loadSchema( |
| 5 | + ` |
| 6 | + model Course { |
| 7 | + id String @id @default(uuid()) |
| 8 | + title String |
| 9 | + description String |
| 10 | + sections Section[] |
| 11 | + activities Activity[] |
| 12 | + @@allow('all', true) |
| 13 | + } |
| 14 | +
|
| 15 | + model Section { |
| 16 | + id String @id @default(uuid()) |
| 17 | + title String |
| 18 | + courseId String |
| 19 | + idx Int @default(0) |
| 20 | + course Course @relation(fields: [courseId], references: [id]) |
| 21 | + activities Activity[] |
| 22 | + } |
| 23 | +
|
| 24 | + model Activity { |
| 25 | + id String @id @default(uuid()) |
| 26 | + title String |
| 27 | + courseId String |
| 28 | + sectionId String |
| 29 | + idx Int @default(0) |
| 30 | + type String |
| 31 | + course Course @relation(fields: [courseId], references: [id]) |
| 32 | + section Section @relation(fields: [sectionId], references: [id]) |
| 33 | + @@delegate(type) |
| 34 | + } |
| 35 | +
|
| 36 | + model UrlActivity extends Activity { |
| 37 | + url String |
| 38 | + } |
| 39 | +
|
| 40 | + model TaskActivity extends Activity { |
| 41 | + description String |
| 42 | + } |
| 43 | + `, |
| 44 | + { enhancements: ['delegate'] } |
| 45 | + ); |
| 46 | + |
| 47 | + const db = enhance(); |
| 48 | + const course = await db.course.create({ |
| 49 | + data: { |
| 50 | + title: 'Test Course', |
| 51 | + description: 'Description of course', |
| 52 | + sections: { |
| 53 | + create: { |
| 54 | + id: '00000000-0000-0000-0000-000000000002', |
| 55 | + title: 'Test Section', |
| 56 | + idx: 0, |
| 57 | + }, |
| 58 | + }, |
| 59 | + }, |
| 60 | + include: { |
| 61 | + sections: true, |
| 62 | + }, |
| 63 | + }); |
| 64 | + |
| 65 | + const section = course.sections[0]; |
| 66 | + await db.taskActivity.create({ |
| 67 | + data: { |
| 68 | + title: 'Test Activity', |
| 69 | + description: 'Description of task', |
| 70 | + idx: 0, |
| 71 | + courseId: course.id, |
| 72 | + sectionId: section.id, |
| 73 | + }, |
| 74 | + }); |
| 75 | + |
| 76 | + const found = await db.course.findFirst({ |
| 77 | + where: { id: course.id }, |
| 78 | + include: { |
| 79 | + sections: { |
| 80 | + orderBy: { idx: 'asc' }, |
| 81 | + include: { |
| 82 | + activities: { orderBy: { idx: 'asc' } }, |
| 83 | + }, |
| 84 | + }, |
| 85 | + }, |
| 86 | + }); |
| 87 | + |
| 88 | + expect(found.sections[0].activities[0]).toMatchObject({ |
| 89 | + description: 'Description of task', |
| 90 | + }); |
| 91 | + }); |
| 92 | +}); |
0 commit comments