-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcore-services.test.ts
More file actions
186 lines (159 loc) · 5.53 KB
/
Copy pathcore-services.test.ts
File metadata and controls
186 lines (159 loc) · 5.53 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
185
186
import { describe, it, expect } from 'vitest';
import {
CoreServiceName,
ServiceCriticalitySchema,
ServiceRequirementDef,
ServiceStatusSchema,
KernelServiceMapSchema,
ServiceConfigSchema,
} from './core-services.zod';
describe('CoreServiceName', () => {
it('should accept all valid service names', () => {
const services = [
'metadata', 'data', 'auth',
'file-storage', 'search', 'cache', 'queue',
'automation', 'graphql', 'analytics', 'realtime',
'job', 'notification', 'ai', 'i18n', 'ui', 'workflow',
];
services.forEach((service) => {
expect(() => CoreServiceName.parse(service)).not.toThrow();
});
});
it('should reject invalid service names', () => {
expect(() => CoreServiceName.parse('invalid')).toThrow();
expect(() => CoreServiceName.parse('database')).toThrow();
expect(() => CoreServiceName.parse('')).toThrow();
});
});
describe('ServiceCriticalitySchema', () => {
it('should accept valid criticality levels', () => {
const levels = ['required', 'core', 'optional'];
levels.forEach((level) => {
expect(() => ServiceCriticalitySchema.parse(level)).not.toThrow();
});
});
it('should reject invalid criticality levels', () => {
expect(() => ServiceCriticalitySchema.parse('invalid')).toThrow();
expect(() => ServiceCriticalitySchema.parse('critical')).toThrow();
});
});
describe('ServiceRequirementDef', () => {
it('should define required services', () => {
expect(ServiceRequirementDef.data).toBe('required');
expect(ServiceRequirementDef.metadata).toBe('core');
expect(ServiceRequirementDef.auth).toBe('core');
});
it('should define core services', () => {
expect(ServiceRequirementDef.cache).toBe('core');
expect(ServiceRequirementDef.queue).toBe('core');
expect(ServiceRequirementDef.job).toBe('core');
expect(ServiceRequirementDef.i18n).toBe('core');
});
it('should define optional services', () => {
expect(ServiceRequirementDef['file-storage']).toBe('optional');
expect(ServiceRequirementDef.search).toBe('optional');
expect(ServiceRequirementDef.automation).toBe('optional');
expect(ServiceRequirementDef.graphql).toBe('optional');
expect(ServiceRequirementDef.analytics).toBe('optional');
expect(ServiceRequirementDef.realtime).toBe('optional');
expect(ServiceRequirementDef.notification).toBe('optional');
expect(ServiceRequirementDef.ai).toBe('optional');
expect(ServiceRequirementDef.ui).toBe('optional');
expect(ServiceRequirementDef.workflow).toBe('optional');
});
});
describe('ServiceStatusSchema', () => {
it('should accept valid service status', () => {
const status = ServiceStatusSchema.parse({
name: 'metadata',
enabled: true,
status: 'running',
});
expect(status.name).toBe('metadata');
expect(status.enabled).toBe(true);
expect(status.status).toBe('running');
});
it('should accept all status values', () => {
const statuses = ['running', 'stopped', 'degraded', 'initializing'];
statuses.forEach((s) => {
expect(() => ServiceStatusSchema.parse({
name: 'data',
enabled: true,
status: s,
})).not.toThrow();
});
});
it('should accept optional fields', () => {
const status = ServiceStatusSchema.parse({
name: 'file-storage',
enabled: true,
status: 'running',
version: '1.0.0',
provider: 's3',
features: ['upload', 'download', 'presigned-urls'],
});
expect(status.version).toBe('1.0.0');
expect(status.provider).toBe('s3');
expect(status.features).toEqual(['upload', 'download', 'presigned-urls']);
});
it('should reject invalid service name', () => {
expect(() => ServiceStatusSchema.parse({
name: 'invalid',
enabled: true,
status: 'running',
})).toThrow();
});
it('should reject missing required fields', () => {
expect(() => ServiceStatusSchema.parse({})).toThrow();
expect(() => ServiceStatusSchema.parse({ name: 'metadata' })).toThrow();
});
});
describe('KernelServiceMapSchema', () => {
it('should accept valid service map', () => {
const map = KernelServiceMapSchema.parse({
metadata: {},
data: {},
auth: {},
});
expect(map.metadata).toBeDefined();
expect(map.data).toBeDefined();
expect(map.auth).toBeDefined();
});
it('should accept empty map', () => {
expect(() => KernelServiceMapSchema.parse({})).not.toThrow();
});
it('should reject invalid service name keys', () => {
expect(() => KernelServiceMapSchema.parse({
'invalid-service': {},
})).toThrow();
});
});
describe('ServiceConfigSchema', () => {
it('should accept valid service config', () => {
const config = ServiceConfigSchema.parse({
id: 'metadata-service-1',
name: 'metadata',
});
expect(config.id).toBe('metadata-service-1');
expect(config.name).toBe('metadata');
expect(config.options).toBeUndefined();
});
it('should accept optional options', () => {
const config = ServiceConfigSchema.parse({
id: 'cache-service-1',
name: 'cache',
options: { host: 'localhost', port: 6379 },
});
expect(config.options).toEqual({ host: 'localhost', port: 6379 });
});
it('should reject invalid service name', () => {
expect(() => ServiceConfigSchema.parse({
id: 'test',
name: 'invalid',
})).toThrow();
});
it('should reject missing required fields', () => {
expect(() => ServiceConfigSchema.parse({})).toThrow();
expect(() => ServiceConfigSchema.parse({ id: 'test' })).toThrow();
});
});