|
| 1 | +import { createTestClient } from '@zenstackhq/testtools'; |
| 2 | +import { describe, expect, it } from 'vitest'; |
| 3 | + |
| 4 | +// https://github.com/zenstackhq/zenstack/issues/2433 |
| 5 | +describe('Regression for issue 2433', () => { |
| 6 | + it('should accept short string when only @length(max: N) is specified', async () => { |
| 7 | + const db = await createTestClient( |
| 8 | + ` |
| 9 | +model Post { |
| 10 | + id String @id @default(cuid()) |
| 11 | + content String @length(max: 10000) |
| 12 | +} |
| 13 | + `, |
| 14 | + ); |
| 15 | + // Should succeed: short content is within max limit |
| 16 | + await expect(db.post.create({ data: { content: 'hello' } })).resolves.toMatchObject({ |
| 17 | + content: 'hello', |
| 18 | + }); |
| 19 | + // Should fail validation: content exceeds max |
| 20 | + await expect( |
| 21 | + db.post.create({ data: { content: 'x'.repeat(10001) } }), |
| 22 | + ).toBeRejectedByValidation(); |
| 23 | + }); |
| 24 | + |
| 25 | + it('should reject short string when only @length(min: N) is specified', async () => { |
| 26 | + const db = await createTestClient( |
| 27 | + ` |
| 28 | +model Post { |
| 29 | + id String @id @default(cuid()) |
| 30 | + content String @length(min: 5) |
| 31 | +} |
| 32 | + `, |
| 33 | + ); |
| 34 | + // Should succeed: content meets min length |
| 35 | + await expect(db.post.create({ data: { content: 'hello world' } })).resolves.toMatchObject({ |
| 36 | + content: 'hello world', |
| 37 | + }); |
| 38 | + // Should fail validation: content is too short |
| 39 | + await expect( |
| 40 | + db.post.create({ data: { content: 'hi' } }), |
| 41 | + ).toBeRejectedByValidation(); |
| 42 | + }); |
| 43 | +}); |
0 commit comments