-
-
Notifications
You must be signed in to change notification settings - Fork 146
Expand file tree
/
Copy pathissue-2433.test.ts
More file actions
43 lines (41 loc) · 1.48 KB
/
issue-2433.test.ts
File metadata and controls
43 lines (41 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { createTestClient } from '@zenstackhq/testtools';
import { describe, expect, it } from 'vitest';
// https://github.com/zenstackhq/zenstack/issues/2433
describe('Regression for issue 2433', () => {
it('should accept short string when only @length(max: N) is specified', async () => {
const db = await createTestClient(
`
model Post {
id String @id @default(cuid())
content String @length(max: 10000)
}
`,
);
// Should succeed: short content is within max limit
await expect(db.post.create({ data: { content: 'hello' } })).resolves.toMatchObject({
content: 'hello',
});
// Should fail validation: content exceeds max
await expect(
db.post.create({ data: { content: 'x'.repeat(10001) } }),
).toBeRejectedByValidation();
});
it('should reject short string when only @length(min: N) is specified', async () => {
const db = await createTestClient(
`
model Post {
id String @id @default(cuid())
content String @length(min: 5)
}
`,
);
// Should succeed: content meets min length
await expect(db.post.create({ data: { content: 'hello world' } })).resolves.toMatchObject({
content: 'hello world',
});
// Should fail validation: content is too short
await expect(
db.post.create({ data: { content: 'hi' } }),
).toBeRejectedByValidation();
});
});