-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathprovisioning.test.ts
More file actions
173 lines (155 loc) · 5.41 KB
/
provisioning.test.ts
File metadata and controls
173 lines (155 loc) · 5.41 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
import { describe, it, expect } from 'vitest';
import {
TenantProvisioningStatusEnum,
TenantPlanSchema,
TenantRegionSchema,
ProvisioningStepSchema,
TenantProvisioningRequestSchema,
TenantProvisioningResultSchema,
type TenantProvisioningStatus,
type TenantPlan,
type TenantRegion,
type ProvisioningStep,
type TenantProvisioningRequest,
type TenantProvisioningResult,
} from './provisioning.zod';
describe('TenantProvisioningStatusEnum', () => {
it('should accept valid statuses', () => {
const statuses: TenantProvisioningStatus[] = ['provisioning', 'active', 'suspended', 'failed', 'destroying'];
statuses.forEach((s) => {
expect(() => TenantProvisioningStatusEnum.parse(s)).not.toThrow();
});
});
it('should reject invalid status', () => {
expect(() => TenantProvisioningStatusEnum.parse('pending')).toThrow();
});
});
describe('TenantPlanSchema', () => {
it('should accept valid plans', () => {
const plans: TenantPlan[] = ['free', 'pro', 'enterprise'];
plans.forEach((p) => {
expect(() => TenantPlanSchema.parse(p)).not.toThrow();
});
});
it('should reject invalid plan', () => {
expect(() => TenantPlanSchema.parse('basic')).toThrow();
});
});
describe('TenantRegionSchema', () => {
it('should accept valid regions', () => {
const regions: TenantRegion[] = ['us-east', 'us-west', 'eu-west', 'eu-central', 'ap-southeast', 'ap-northeast'];
regions.forEach((r) => {
expect(() => TenantRegionSchema.parse(r)).not.toThrow();
});
});
it('should reject invalid region', () => {
expect(() => TenantRegionSchema.parse('us-south')).toThrow();
});
});
describe('ProvisioningStepSchema', () => {
it('should accept a completed step', () => {
const step: ProvisioningStep = {
name: 'create_database',
status: 'completed',
startedAt: '2026-01-01T00:00:00Z',
completedAt: '2026-01-01T00:00:02Z',
durationMs: 2000,
};
const parsed = ProvisioningStepSchema.parse(step);
expect(parsed.name).toBe('create_database');
expect(parsed.status).toBe('completed');
});
it('should accept a pending step with minimal fields', () => {
const step = { name: 'sync_schema', status: 'pending' };
expect(() => ProvisioningStepSchema.parse(step)).not.toThrow();
});
it('should accept a failed step with error', () => {
const step = {
name: 'create_database',
status: 'failed',
error: 'Turso API rate limit exceeded',
};
expect(() => ProvisioningStepSchema.parse(step)).not.toThrow();
});
it('should accept all step statuses', () => {
const statuses = ['pending', 'running', 'completed', 'failed', 'skipped'];
statuses.forEach((status) => {
expect(() => ProvisioningStepSchema.parse({ name: 'test', status })).not.toThrow();
});
});
it('should reject empty step name', () => {
expect(() => ProvisioningStepSchema.parse({ name: '', status: 'pending' })).toThrow();
});
});
describe('TenantProvisioningRequestSchema', () => {
it('should accept full request', () => {
const request: TenantProvisioningRequest = {
orgId: 'org_123',
plan: 'pro',
region: 'eu-west',
displayName: 'Acme Corp',
adminEmail: 'admin@acme.com',
metadata: { industry: 'tech' },
};
const parsed = TenantProvisioningRequestSchema.parse(request);
expect(parsed.orgId).toBe('org_123');
expect(parsed.plan).toBe('pro');
expect(parsed.region).toBe('eu-west');
});
it('should accept minimal request with defaults', () => {
const request = { orgId: 'org_456' };
const parsed = TenantProvisioningRequestSchema.parse(request);
expect(parsed.plan).toBe('free');
expect(parsed.region).toBe('us-east');
expect(parsed.displayName).toBeUndefined();
});
it('should reject missing orgId', () => {
expect(() => TenantProvisioningRequestSchema.parse({})).toThrow();
});
it('should reject invalid email', () => {
expect(() => TenantProvisioningRequestSchema.parse({
orgId: 'org_789',
adminEmail: 'not-an-email',
})).toThrow();
});
});
describe('TenantProvisioningResultSchema', () => {
it('should accept full result', () => {
const result: TenantProvisioningResult = {
tenantId: 'tenant_abc',
connectionUrl: 'libsql://tenant-abc-myorg.turso.io',
status: 'active',
region: 'us-east',
plan: 'free',
steps: [
{ name: 'create_database', status: 'completed', durationMs: 1500 },
{ name: 'sync_schema', status: 'completed', durationMs: 800 },
],
totalDurationMs: 2300,
provisionedAt: '2026-01-01T00:00:03Z',
};
const parsed = TenantProvisioningResultSchema.parse(result);
expect(parsed.tenantId).toBe('tenant_abc');
expect(parsed.status).toBe('active');
expect(parsed.steps).toHaveLength(2);
});
it('should accept failed result with error', () => {
const result = {
tenantId: 'tenant_fail',
connectionUrl: 'libsql://failed.turso.io',
status: 'failed',
region: 'us-east',
plan: 'free',
error: 'Database creation timeout',
};
const parsed = TenantProvisioningResultSchema.parse(result);
expect(parsed.status).toBe('failed');
expect(parsed.error).toBe('Database creation timeout');
expect(parsed.steps).toEqual([]);
});
it('should reject missing required fields', () => {
expect(() => TenantProvisioningResultSchema.parse({
tenantId: 'test',
})).toThrow();
});
});