Skip to content

Commit 90a1e4e

Browse files
committed
break down large test suite into smaller ones
1 parent ebc7cfe commit 90a1e4e

14 files changed

+1047
-1012
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
2+
import { ZenStackValidationTester, createTestDir, expectValidationSuccess, expectValidationFailure, baseSchema } from './test-utils';
3+
4+
describe('Attributes Validation', () => {
5+
let tester: ZenStackValidationTester;
6+
let tempDir: string;
7+
8+
beforeEach(() => {
9+
tempDir = createTestDir();
10+
tester = new ZenStackValidationTester(tempDir);
11+
});
12+
13+
afterEach(() => {
14+
tester.cleanup();
15+
});
16+
17+
it('should reject duplicate field attributes', () => {
18+
const result = tester.runValidation(`
19+
${baseSchema}
20+
21+
model User {
22+
id Int @id @default(autoincrement())
23+
email String @unique @unique
24+
name String
25+
}
26+
`);
27+
28+
expectValidationFailure(result);
29+
});
30+
31+
it('should reject invalid default value type', () => {
32+
const result = tester.runValidation(`
33+
${baseSchema}
34+
35+
model User {
36+
id Int @id @default(autoincrement())
37+
email String @default(123)
38+
name String
39+
}
40+
`);
41+
42+
expectValidationFailure(result);
43+
});
44+
45+
it('should accept valid @map attribute', () => {
46+
const result = tester.runValidation(`
47+
${baseSchema}
48+
49+
model User {
50+
id Int @id @default(autoincrement())
51+
email String @unique @map("email_address")
52+
name String
53+
54+
@@map("users")
55+
}
56+
`);
57+
58+
expectValidationSuccess(result);
59+
});
60+
});
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
2+
import { ZenStackValidationTester, createTestDir, expectValidationSuccess, expectValidationFailure, baseSchema } from './test-utils';
3+
4+
describe('Basic Models Validation', () => {
5+
let tester: ZenStackValidationTester;
6+
let tempDir: string;
7+
8+
beforeEach(() => {
9+
tempDir = createTestDir();
10+
tester = new ZenStackValidationTester(tempDir);
11+
});
12+
13+
afterEach(() => {
14+
tester.cleanup();
15+
});
16+
17+
it('should accept valid basic model with id field', () => {
18+
const result = tester.runValidation(`
19+
${baseSchema}
20+
21+
model User {
22+
id Int @id @default(autoincrement())
23+
email String @unique
24+
name String?
25+
}
26+
`);
27+
28+
expectValidationSuccess(result);
29+
});
30+
31+
it('should reject model without any unique criterion', () => {
32+
const result = tester.runValidation(`
33+
${baseSchema}
34+
35+
model User {
36+
email String
37+
name String?
38+
}
39+
`);
40+
41+
expectValidationFailure(result);
42+
});
43+
44+
it('should reject model with multiple @id fields', () => {
45+
const result = tester.runValidation(`
46+
${baseSchema}
47+
48+
model User {
49+
id Int @id @default(autoincrement())
50+
email String @id
51+
name String?
52+
}
53+
`);
54+
55+
expectValidationFailure(result);
56+
});
57+
58+
it('should reject model with both @id field and @@id', () => {
59+
const result = tester.runValidation(`
60+
${baseSchema}
61+
62+
model User {
63+
id Int @id @default(autoincrement())
64+
firstName String
65+
lastName String
66+
67+
@@id([firstName, lastName])
68+
}
69+
`);
70+
71+
expectValidationFailure(result);
72+
});
73+
74+
it('should reject optional ID field', () => {
75+
const result = tester.runValidation(`
76+
${baseSchema}
77+
78+
model User {
79+
id Int? @id @default(autoincrement())
80+
email String @unique
81+
}
82+
`);
83+
84+
expectValidationFailure(result);
85+
});
86+
87+
it('should reject array ID field', () => {
88+
const result = tester.runValidation(`
89+
${baseSchema}
90+
91+
model User {
92+
id Int[] @id
93+
email String @unique
94+
}
95+
`);
96+
97+
expectValidationFailure(result);
98+
});
99+
});
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
2+
import { ZenStackValidationTester, createTestDir, expectValidationSuccess, expectValidationFailure, baseSchema } from './test-utils';
3+
4+
describe('Compound IDs Validation', () => {
5+
let tester: ZenStackValidationTester;
6+
let tempDir: string;
7+
8+
beforeEach(() => {
9+
tempDir = createTestDir();
10+
tester = new ZenStackValidationTester(tempDir);
11+
});
12+
13+
afterEach(() => {
14+
tester.cleanup();
15+
});
16+
17+
it('should accept valid compound ID with @@id', () => {
18+
const result = tester.runValidation(`
19+
${baseSchema}
20+
21+
model User {
22+
firstName String
23+
lastName String
24+
age Int
25+
26+
@@id([firstName, lastName])
27+
}
28+
`);
29+
30+
expectValidationSuccess(result);
31+
});
32+
33+
it('should reject empty compound ID', () => {
34+
const result = tester.runValidation(`
35+
${baseSchema}
36+
37+
model User {
38+
firstName String
39+
lastName String
40+
41+
@@id([])
42+
}
43+
`);
44+
45+
expectValidationFailure(result);
46+
});
47+
});
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
2+
import { ZenStackValidationTester, createTestDir, expectValidationSuccess, expectValidationFailure, baseSchema } from './test-utils';
3+
4+
describe('Datasource Validation', () => {
5+
let tester: ZenStackValidationTester;
6+
let tempDir: string;
7+
8+
beforeEach(() => {
9+
tempDir = createTestDir();
10+
tester = new ZenStackValidationTester(tempDir);
11+
});
12+
13+
afterEach(() => {
14+
tester.cleanup();
15+
});
16+
17+
it('should reject multiple datasources', () => {
18+
const result = tester.runValidation(`
19+
datasource db1 {
20+
provider = "postgresql"
21+
url = env("DATABASE_URL")
22+
}
23+
24+
datasource db2 {
25+
provider = "sqlite"
26+
url = "file:./dev.db"
27+
}
28+
29+
model User {
30+
id Int @id @default(autoincrement())
31+
name String
32+
}
33+
`);
34+
35+
expectValidationFailure(result);
36+
});
37+
38+
it('should reject missing datasource', () => {
39+
const result = tester.runValidation(`
40+
model User {
41+
id Int @id @default(autoincrement())
42+
name String
43+
}
44+
`);
45+
46+
expectValidationFailure(result);
47+
});
48+
49+
it('should reject invalid provider', () => {
50+
const result = tester.runValidation(`
51+
datasource db {
52+
provider = "nosql"
53+
url = env("DATABASE_URL")
54+
}
55+
56+
model User {
57+
id Int @id @default(autoincrement())
58+
name String
59+
}
60+
`);
61+
62+
expectValidationFailure(result);
63+
});
64+
});
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
2+
import { ZenStackValidationTester, createTestDir, expectValidationSuccess, expectValidationFailure, baseSchema } from './test-utils';
3+
4+
describe('Enums Validation', () => {
5+
let tester: ZenStackValidationTester;
6+
let tempDir: string;
7+
8+
beforeEach(() => {
9+
tempDir = createTestDir();
10+
tester = new ZenStackValidationTester(tempDir);
11+
});
12+
13+
afterEach(() => {
14+
tester.cleanup();
15+
});
16+
17+
it('should accept valid enum definition and usage', () => {
18+
const result = tester.runValidation(`
19+
${baseSchema}
20+
21+
enum Role {
22+
USER
23+
ADMIN
24+
MODERATOR
25+
}
26+
27+
model User {
28+
id Int @id @default(autoincrement())
29+
role Role @default(USER)
30+
name String
31+
}
32+
`);
33+
34+
expectValidationSuccess(result);
35+
});
36+
37+
it('should reject empty enum', () => {
38+
const result = tester.runValidation(`
39+
${baseSchema}
40+
41+
enum Role {
42+
}
43+
44+
model User {
45+
id Int @id @default(autoincrement())
46+
role Role @default(USER)
47+
name String
48+
}
49+
`);
50+
51+
expectValidationFailure(result);
52+
});
53+
});
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
2+
import { ZenStackValidationTester, createTestDir, expectValidationSuccess, expectValidationFailure, baseSchema, sqliteSchema } from './test-utils';
3+
4+
describe('Field Types Validation', () => {
5+
let tester: ZenStackValidationTester;
6+
let tempDir: string;
7+
8+
beforeEach(() => {
9+
tempDir = createTestDir();
10+
tester = new ZenStackValidationTester(tempDir);
11+
});
12+
13+
afterEach(() => {
14+
tester.cleanup();
15+
});
16+
17+
it('should reject optional array field', () => {
18+
const result = tester.runValidation(`
19+
${baseSchema}
20+
21+
model User {
22+
id Int @id @default(autoincrement())
23+
tags String[]?
24+
}
25+
`);
26+
27+
expectValidationFailure(result);
28+
});
29+
30+
it('should reject array field with SQLite', () => {
31+
const result = tester.runValidation(`
32+
${sqliteSchema}
33+
34+
model User {
35+
id Int @id @default(autoincrement())
36+
tags String[]
37+
}
38+
`);
39+
40+
expectValidationFailure(result);
41+
});
42+
43+
it('should accept array field with PostgreSQL', () => {
44+
const result = tester.runValidation(`
45+
${baseSchema}
46+
47+
model User {
48+
id Int @id @default(autoincrement())
49+
tags String[]
50+
}
51+
`);
52+
53+
expectValidationSuccess(result);
54+
});
55+
});

0 commit comments

Comments
 (0)