|
| 1 | +import { loadSchema } from '@zenstackhq/testtools'; |
| 2 | + |
| 3 | +describe('issue 1998', () => { |
| 4 | + it('regression', async () => { |
| 5 | + const { enhance } = await loadSchema( |
| 6 | + ` |
| 7 | + model Entity { |
| 8 | + id String @id |
| 9 | + type String |
| 10 | + updatable Boolean |
| 11 | + children Relation[] @relation("children") |
| 12 | + parents Relation[] @relation("parents") |
| 13 | +
|
| 14 | + @@delegate(type) |
| 15 | + @@allow('create,read', true) |
| 16 | + @@allow('update', updatable) |
| 17 | + } |
| 18 | +
|
| 19 | + model A extends Entity {} |
| 20 | +
|
| 21 | + model B extends Entity {} |
| 22 | +
|
| 23 | + model Relation { |
| 24 | + parent Entity @relation("children", fields: [parentId], references: [id]) |
| 25 | + parentId String |
| 26 | + child Entity @relation("parents", fields: [childId], references: [id]) |
| 27 | + childId String |
| 28 | +
|
| 29 | + @@allow('create', true) |
| 30 | + @@allow('read', check(parent, 'read') && check(child, 'read')) |
| 31 | + @@allow('delete', check(parent, 'update') && check(child, 'update')) |
| 32 | +
|
| 33 | + @@id([parentId, childId]) |
| 34 | + } |
| 35 | + ` |
| 36 | + ); |
| 37 | + |
| 38 | + const db = enhance(); |
| 39 | + |
| 40 | + await db.a.create({ data: { id: '1', updatable: true } }); |
| 41 | + await db.b.create({ data: { id: '2', updatable: true } }); |
| 42 | + await db.relation.create({ data: { parentId: '1', childId: '2' } }); |
| 43 | + |
| 44 | + await expect( |
| 45 | + db.relation.deleteMany({ |
| 46 | + where: { parentId: '1', childId: '2' }, |
| 47 | + }) |
| 48 | + ).resolves.toEqual({ count: 1 }); |
| 49 | + |
| 50 | + await db.a.create({ data: { id: '3', updatable: false } }); |
| 51 | + await db.b.create({ data: { id: '4', updatable: false } }); |
| 52 | + await db.relation.create({ data: { parentId: '3', childId: '4' } }); |
| 53 | + await expect( |
| 54 | + db.relation.deleteMany({ |
| 55 | + where: { parentId: '3', childId: '4' }, |
| 56 | + }) |
| 57 | + ).resolves.toEqual({ count: 0 }); |
| 58 | + }); |
| 59 | +}); |
0 commit comments