|
| 1 | +import { loadSchema } from '@zenstackhq/testtools'; |
| 2 | + |
| 3 | +describe('issue 1755', () => { |
| 4 | + it('regression', async () => { |
| 5 | + const { enhance } = await loadSchema( |
| 6 | + ` |
| 7 | + model User { |
| 8 | + id Int @id @default(autoincrement()) |
| 9 | + contents Content[] |
| 10 | + } |
| 11 | +
|
| 12 | + model Content { |
| 13 | + id Int @id @default(autoincrement()) |
| 14 | + createdAt DateTime @default(now()) |
| 15 | + user User @relation(fields: [userId], references: [id]) |
| 16 | + userId Int |
| 17 | + contentType String |
| 18 | + @@delegate(contentType) |
| 19 | + } |
| 20 | +
|
| 21 | + model Post extends Content { |
| 22 | + title String |
| 23 | + } |
| 24 | +
|
| 25 | + model Video extends Content { |
| 26 | + name String |
| 27 | + duration Int |
| 28 | + } |
| 29 | + `, |
| 30 | + { enhancements: ['delegate'] } |
| 31 | + ); |
| 32 | + |
| 33 | + const db = enhance(); |
| 34 | + const user = await db.user.create({ data: {} }); |
| 35 | + const now = Date.now(); |
| 36 | + await db.post.create({ |
| 37 | + data: { title: 'post1', createdAt: new Date(now - 1000), user: { connect: { id: user.id } } }, |
| 38 | + }); |
| 39 | + await db.post.create({ |
| 40 | + data: { title: 'post2', createdAt: new Date(now), user: { connect: { id: user.id } } }, |
| 41 | + }); |
| 42 | + |
| 43 | + // scalar orderBy |
| 44 | + await expect(db.post.findFirst({ orderBy: { createdAt: 'desc' } })).resolves.toMatchObject({ |
| 45 | + title: 'post2', |
| 46 | + }); |
| 47 | + |
| 48 | + // array orderBy |
| 49 | + await expect(db.post.findFirst({ orderBy: [{ createdAt: 'desc' }] })).resolves.toMatchObject({ |
| 50 | + title: 'post2', |
| 51 | + }); |
| 52 | + |
| 53 | + // nested orderBy |
| 54 | + await expect( |
| 55 | + db.user.findFirst({ include: { contents: { orderBy: [{ createdAt: 'desc' }] } } }) |
| 56 | + ).resolves.toMatchObject({ |
| 57 | + id: user.id, |
| 58 | + contents: [{ title: 'post2' }, { title: 'post1' }], |
| 59 | + }); |
| 60 | + }); |
| 61 | +}); |
0 commit comments