-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathapp-lifecycle-service.test.ts
More file actions
199 lines (182 loc) · 6.38 KB
/
Copy pathapp-lifecycle-service.test.ts
File metadata and controls
199 lines (182 loc) · 6.38 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
187
188
189
190
191
192
193
194
195
196
197
198
199
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
import { describe, it, expect } from 'vitest';
import type { IAppLifecycleService } from './app-lifecycle-service';
import type { AppManifest, AppCompatibilityCheck, AppInstallResult } from '../system/app-install.zod';
describe('App Lifecycle Service Contract', () => {
const sampleManifest: AppManifest = {
name: 'crm_basic',
label: 'Basic CRM',
version: '1.0.0',
description: 'A basic CRM app',
objects: ['contact', 'deal'],
views: ['contact_list', 'deal_board'],
flows: ['new_deal_notification'],
hasSeedData: true,
dependencies: [],
};
it('should allow a minimal IAppLifecycleService implementation with all required methods', () => {
const service: IAppLifecycleService = {
checkCompatibility: async () => ({ compatible: true, issues: [] }),
installApp: async () => ({
success: true,
appId: 'crm_basic',
version: '1.0.0',
installedObjects: [],
createdTables: [],
seededRecords: 0,
}),
upgradeApp: async () => ({
success: true,
appId: 'crm_basic',
version: '2.0.0',
installedObjects: [],
createdTables: [],
seededRecords: 0,
}),
uninstallApp: async () => ({ success: true }),
};
expect(typeof service.checkCompatibility).toBe('function');
expect(typeof service.installApp).toBe('function');
expect(typeof service.upgradeApp).toBe('function');
expect(typeof service.uninstallApp).toBe('function');
});
it('should check compatibility before installation', async () => {
const service: IAppLifecycleService = {
checkCompatibility: async (_tenantId, manifest) => {
const issues: AppCompatibilityCheck['issues'] = [];
if (manifest.minKernelVersion && manifest.minKernelVersion > '3.0.0') {
issues.push({
severity: 'error',
message: 'Kernel version too low',
category: 'kernel_version',
});
}
return { compatible: issues.length === 0, issues };
},
installApp: async () => ({
success: true,
appId: 'crm_basic',
version: '1.0.0',
installedObjects: [],
createdTables: [],
seededRecords: 0,
}),
upgradeApp: async () => ({
success: true,
appId: 'crm_basic',
version: '1.0.0',
installedObjects: [],
createdTables: [],
seededRecords: 0,
}),
uninstallApp: async () => ({ success: true }),
};
const result = await service.checkCompatibility('tenant_001', sampleManifest);
expect(result.compatible).toBe(true);
expect(result.issues).toHaveLength(0);
const incompatible = await service.checkCompatibility('tenant_001', {
...sampleManifest,
minKernelVersion: '5.0.0',
});
expect(incompatible.compatible).toBe(false);
expect(incompatible.issues).toHaveLength(1);
expect(incompatible.issues[0].category).toBe('kernel_version');
});
it('should install an app into a tenant', async () => {
const installedApps = new Map<string, AppInstallResult>();
const service: IAppLifecycleService = {
checkCompatibility: async () => ({ compatible: true, issues: [] }),
installApp: async (_tenantId, manifest) => {
const result: AppInstallResult = {
success: true,
appId: manifest.name,
version: manifest.version,
installedObjects: manifest.objects,
createdTables: manifest.objects.map(o => `app_${o}`),
seededRecords: manifest.hasSeedData ? 50 : 0,
durationMs: 2300,
};
installedApps.set(manifest.name, result);
return result;
},
upgradeApp: async () => ({
success: true,
appId: 'crm_basic',
version: '1.0.0',
installedObjects: [],
createdTables: [],
seededRecords: 0,
}),
uninstallApp: async () => ({ success: true }),
};
const result = await service.installApp('tenant_001', sampleManifest);
expect(result.success).toBe(true);
expect(result.appId).toBe('crm_basic');
expect(result.installedObjects).toEqual(['contact', 'deal']);
expect(result.createdTables).toEqual(['app_contact', 'app_deal']);
expect(result.seededRecords).toBe(50);
});
it('should upgrade an installed app', async () => {
const service: IAppLifecycleService = {
checkCompatibility: async () => ({ compatible: true, issues: [] }),
installApp: async () => ({
success: true,
appId: 'crm_basic',
version: '1.0.0',
installedObjects: [],
createdTables: [],
seededRecords: 0,
}),
upgradeApp: async (_tenantId, manifest) => ({
success: true,
appId: manifest.name,
version: manifest.version,
installedObjects: manifest.objects,
createdTables: [],
seededRecords: 0,
durationMs: 1100,
}),
uninstallApp: async () => ({ success: true }),
};
const upgradeManifest: AppManifest = {
...sampleManifest,
version: '2.0.0',
objects: ['contact', 'deal', 'activity'],
};
const result = await service.upgradeApp('tenant_001', upgradeManifest);
expect(result.success).toBe(true);
expect(result.version).toBe('2.0.0');
expect(result.installedObjects).toContain('activity');
});
it('should uninstall an app', async () => {
const apps = new Set(['crm_basic']);
const service: IAppLifecycleService = {
checkCompatibility: async () => ({ compatible: true, issues: [] }),
installApp: async () => ({
success: true,
appId: 'crm_basic',
version: '1.0.0',
installedObjects: [],
createdTables: [],
seededRecords: 0,
}),
upgradeApp: async () => ({
success: true,
appId: 'crm_basic',
version: '1.0.0',
installedObjects: [],
createdTables: [],
seededRecords: 0,
}),
uninstallApp: async (_tenantId, appId) => {
const existed = apps.delete(appId);
return { success: existed };
},
};
const result = await service.uninstallApp('tenant_001', 'crm_basic');
expect(result.success).toBe(true);
expect(apps.has('crm_basic')).toBe(false);
const notFound = await service.uninstallApp('tenant_001', 'nonexistent');
expect(notFound.success).toBe(false);
});
});