-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtenant.test.ts
More file actions
184 lines (153 loc) · 4.49 KB
/
Copy pathtenant.test.ts
File metadata and controls
184 lines (153 loc) · 4.49 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
import { describe, it, expect } from 'vitest';
import {
TenantSchema,
TenantIsolationLevel,
TenantQuotaSchema,
type Tenant,
type TenantQuota,
} from './tenant.zod';
describe('TenantIsolationLevel', () => {
it('should accept valid isolation levels', () => {
const levels = ['shared_schema', 'isolated_schema', 'isolated_db'];
levels.forEach((level) => {
expect(() => TenantIsolationLevel.parse(level)).not.toThrow();
});
});
it('should reject invalid isolation levels', () => {
expect(() => TenantIsolationLevel.parse('invalid')).toThrow();
expect(() => TenantIsolationLevel.parse('sharedSchema')).toThrow();
});
});
describe('TenantQuotaSchema', () => {
it('should accept valid quota configuration', () => {
const validQuota: TenantQuota = {
maxUsers: 100,
maxStorage: 10737418240, // 10GB in bytes
apiRateLimit: 1000,
};
expect(() => TenantQuotaSchema.parse(validQuota)).not.toThrow();
});
it('should accept partial quota configuration', () => {
const partialQuota = {
maxUsers: 50,
};
expect(() => TenantQuotaSchema.parse(partialQuota)).not.toThrow();
});
it('should accept empty quota configuration', () => {
const emptyQuota = {};
expect(() => TenantQuotaSchema.parse(emptyQuota)).not.toThrow();
});
it('should reject negative values', () => {
const invalidQuota = {
maxUsers: -10,
};
expect(() => TenantQuotaSchema.parse(invalidQuota)).toThrow();
});
it('should reject non-integer values', () => {
const invalidQuota = {
maxUsers: 10.5,
};
expect(() => TenantQuotaSchema.parse(invalidQuota)).toThrow();
});
});
describe('TenantSchema', () => {
it('should accept valid tenant configuration', () => {
const validTenant: Tenant = {
id: 'tenant_123',
name: 'Acme Corporation',
isolationLevel: 'isolated_schema',
customizations: {
theme: 'dark',
logo: 'https://example.com/logo.png',
},
quotas: {
maxUsers: 100,
maxStorage: 10737418240,
apiRateLimit: 1000,
},
};
expect(() => TenantSchema.parse(validTenant)).not.toThrow();
});
it('should accept minimal tenant configuration', () => {
const minimalTenant = {
id: 'tenant_456',
name: 'Basic Tenant',
isolationLevel: 'shared_schema',
};
expect(() => TenantSchema.parse(minimalTenant)).not.toThrow();
});
it('should accept tenant with customizations but no quotas', () => {
const tenant = {
id: 'tenant_789',
name: 'Custom Tenant',
isolationLevel: 'isolated_db',
customizations: {
feature_flags: {
advanced_analytics: true,
api_access: true,
},
},
};
expect(() => TenantSchema.parse(tenant)).not.toThrow();
});
it('should accept tenant with quotas but no customizations', () => {
const tenant = {
id: 'tenant_101',
name: 'Quota Tenant',
isolationLevel: 'shared_schema',
quotas: {
maxUsers: 50,
apiRateLimit: 500,
},
};
expect(() => TenantSchema.parse(tenant)).not.toThrow();
});
it('should require id field', () => {
const invalidTenant = {
name: 'Missing ID Tenant',
isolationLevel: 'shared_schema',
};
expect(() => TenantSchema.parse(invalidTenant)).toThrow();
});
it('should require name field', () => {
const invalidTenant = {
id: 'tenant_202',
isolationLevel: 'shared_schema',
};
expect(() => TenantSchema.parse(invalidTenant)).toThrow();
});
it('should require isolationLevel field', () => {
const invalidTenant = {
id: 'tenant_303',
name: 'Missing Isolation Tenant',
};
expect(() => TenantSchema.parse(invalidTenant)).toThrow();
});
it('should reject invalid isolationLevel', () => {
const invalidTenant = {
id: 'tenant_404',
name: 'Invalid Isolation Tenant',
isolationLevel: 'wrong_level',
};
expect(() => TenantSchema.parse(invalidTenant)).toThrow();
});
it('should allow arbitrary customization values', () => {
const tenant = {
id: 'tenant_505',
name: 'Flexible Customizations',
isolationLevel: 'shared_schema',
customizations: {
string_value: 'text',
number_value: 42,
boolean_value: true,
array_value: [1, 2, 3],
nested_object: {
deep: {
property: 'value',
},
},
},
};
expect(() => TenantSchema.parse(tenant)).not.toThrow();
});
});