@friggframework/devtools 2.0.0--canary.548.c8ae0ca.0 → 2.0.0--canary.545.c40eca4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/frigg-cli/README.md +1 -1
- package/frigg-cli/__tests__/application/use-cases/AddApiModuleToIntegrationUseCase.test.js +326 -0
- package/frigg-cli/__tests__/application/use-cases/CreateApiModuleUseCase.test.js +337 -0
- package/frigg-cli/__tests__/domain/entities/ApiModule.test.js +373 -0
- package/frigg-cli/__tests__/domain/entities/AppDefinition.test.js +313 -0
- package/frigg-cli/__tests__/domain/services/IntegrationValidator.test.js +269 -0
- package/frigg-cli/__tests__/domain/value-objects/IntegrationName.test.js +82 -0
- package/frigg-cli/__tests__/infrastructure/adapters/IntegrationJsUpdater.test.js +408 -0
- package/frigg-cli/__tests__/infrastructure/repositories/FileSystemApiModuleRepository.test.js +583 -0
- package/frigg-cli/__tests__/infrastructure/repositories/FileSystemAppDefinitionRepository.test.js +314 -0
- package/frigg-cli/__tests__/infrastructure/repositories/FileSystemIntegrationRepository.test.js +383 -0
- package/frigg-cli/__tests__/unit/commands/build.test.js +1 -1
- package/frigg-cli/__tests__/unit/commands/doctor.test.js +0 -2
- package/frigg-cli/__tests__/unit/commands/init.test.js +406 -0
- package/frigg-cli/__tests__/unit/commands/install.test.js +23 -19
- package/frigg-cli/__tests__/unit/commands/provider-dispatch.test.js +383 -0
- package/frigg-cli/__tests__/unit/commands/repair.test.js +275 -0
- package/frigg-cli/__tests__/unit/dependencies.test.js +2 -2
- package/frigg-cli/__tests__/unit/start-command/application/RunPreflightChecksUseCase.test.js +411 -0
- package/frigg-cli/__tests__/unit/start-command/infrastructure/DatabaseAdapter.test.js +405 -0
- package/frigg-cli/__tests__/unit/start-command/infrastructure/DockerAdapter.test.js +496 -0
- package/frigg-cli/__tests__/unit/start-command/presentation/InteractivePromptAdapter.test.js +474 -0
- package/frigg-cli/__tests__/unit/utils/output.test.js +196 -0
- package/frigg-cli/application/use-cases/AddApiModuleToIntegrationUseCase.js +93 -0
- package/frigg-cli/application/use-cases/CreateApiModuleUseCase.js +93 -0
- package/frigg-cli/application/use-cases/CreateIntegrationUseCase.js +103 -0
- package/frigg-cli/build-command/index.js +123 -11
- package/frigg-cli/container.js +172 -0
- package/frigg-cli/deploy-command/index.js +83 -1
- package/frigg-cli/docs/OUTPUT_MIGRATION_GUIDE.md +286 -0
- package/frigg-cli/doctor-command/index.js +37 -16
- package/frigg-cli/domain/entities/ApiModule.js +272 -0
- package/frigg-cli/domain/entities/AppDefinition.js +227 -0
- package/frigg-cli/domain/entities/Integration.js +198 -0
- package/frigg-cli/domain/exceptions/DomainException.js +24 -0
- package/frigg-cli/domain/ports/IApiModuleRepository.js +53 -0
- package/frigg-cli/domain/ports/IAppDefinitionRepository.js +43 -0
- package/frigg-cli/domain/ports/IIntegrationRepository.js +61 -0
- package/frigg-cli/domain/services/IntegrationValidator.js +185 -0
- package/frigg-cli/domain/value-objects/IntegrationId.js +42 -0
- package/frigg-cli/domain/value-objects/IntegrationName.js +60 -0
- package/frigg-cli/domain/value-objects/SemanticVersion.js +70 -0
- package/frigg-cli/generate-iam-command.js +21 -1
- package/frigg-cli/index.js +21 -6
- package/frigg-cli/index.test.js +7 -2
- package/frigg-cli/infrastructure/UnitOfWork.js +46 -0
- package/frigg-cli/infrastructure/adapters/BackendJsUpdater.js +197 -0
- package/frigg-cli/infrastructure/adapters/FileSystemAdapter.js +224 -0
- package/frigg-cli/infrastructure/adapters/IntegrationJsUpdater.js +249 -0
- package/frigg-cli/infrastructure/adapters/SchemaValidator.js +92 -0
- package/frigg-cli/infrastructure/repositories/FileSystemApiModuleRepository.js +373 -0
- package/frigg-cli/infrastructure/repositories/FileSystemAppDefinitionRepository.js +116 -0
- package/frigg-cli/infrastructure/repositories/FileSystemIntegrationRepository.js +277 -0
- package/frigg-cli/init-command/backend-first-handler.js +124 -42
- package/frigg-cli/init-command/index.js +2 -1
- package/frigg-cli/init-command/template-handler.js +13 -3
- package/frigg-cli/install-command/backend-js.js +3 -3
- package/frigg-cli/install-command/environment-variables.js +16 -19
- package/frigg-cli/install-command/environment-variables.test.js +12 -13
- package/frigg-cli/install-command/index.js +14 -9
- package/frigg-cli/install-command/integration-file.js +3 -3
- package/frigg-cli/install-command/validate-package.js +5 -9
- package/frigg-cli/jest.config.js +4 -1
- package/frigg-cli/package-lock.json +16226 -0
- package/frigg-cli/repair-command/index.js +121 -128
- package/frigg-cli/start-command/application/RunPreflightChecksUseCase.js +376 -0
- package/frigg-cli/start-command/index.js +324 -2
- package/frigg-cli/start-command/infrastructure/DatabaseAdapter.js +591 -0
- package/frigg-cli/start-command/infrastructure/DockerAdapter.js +306 -0
- package/frigg-cli/start-command/presentation/InteractivePromptAdapter.js +329 -0
- package/frigg-cli/templates/backend/.env.example +62 -0
- package/frigg-cli/templates/backend/.eslintrc.json +12 -0
- package/frigg-cli/templates/backend/.prettierrc +6 -0
- package/frigg-cli/templates/backend/docker-compose.yml +22 -0
- package/frigg-cli/templates/backend/index.js +96 -0
- package/frigg-cli/templates/backend/infrastructure.js +12 -0
- package/frigg-cli/templates/backend/jest.config.js +17 -0
- package/frigg-cli/templates/backend/package.json +50 -0
- package/frigg-cli/templates/backend/src/api-modules/.gitkeep +10 -0
- package/frigg-cli/templates/backend/src/base/.gitkeep +7 -0
- package/frigg-cli/templates/backend/src/integrations/.gitkeep +10 -0
- package/frigg-cli/templates/backend/src/integrations/ExampleIntegration.js +65 -0
- package/frigg-cli/templates/backend/src/utils/.gitkeep +7 -0
- package/frigg-cli/templates/backend/test/setup.js +30 -0
- package/frigg-cli/templates/backend/ui-extensions/.gitkeep +0 -0
- package/frigg-cli/templates/backend/ui-extensions/README.md +77 -0
- package/frigg-cli/ui-command/index.js +58 -36
- package/frigg-cli/utils/__tests__/provider-helper.test.js +55 -0
- package/frigg-cli/utils/__tests__/repo-detection.test.js +436 -0
- package/frigg-cli/utils/output.js +382 -0
- package/frigg-cli/utils/provider-helper.js +75 -0
- package/frigg-cli/utils/repo-detection.js +85 -37
- package/frigg-cli/validate-command/__tests__/adapters/validate-command.test.js +205 -0
- package/frigg-cli/validate-command/__tests__/application/validate-app-use-case.test.js +104 -0
- package/frigg-cli/validate-command/__tests__/domain/fix-suggestion.test.js +153 -0
- package/frigg-cli/validate-command/__tests__/domain/validation-error.test.js +162 -0
- package/frigg-cli/validate-command/__tests__/domain/validation-result.test.js +152 -0
- package/frigg-cli/validate-command/__tests__/infrastructure/api-module-validator.test.js +332 -0
- package/frigg-cli/validate-command/__tests__/infrastructure/app-definition-validator.test.js +191 -0
- package/frigg-cli/validate-command/__tests__/infrastructure/integration-class-validator.test.js +146 -0
- package/frigg-cli/validate-command/__tests__/infrastructure/template-validation.test.js +155 -0
- package/frigg-cli/validate-command/adapters/cli/validate-command.js +199 -0
- package/frigg-cli/validate-command/application/use-cases/validate-app-use-case.js +35 -0
- package/frigg-cli/validate-command/domain/entities/validation-result.js +74 -0
- package/frigg-cli/validate-command/domain/value-objects/fix-suggestion.js +74 -0
- package/frigg-cli/validate-command/domain/value-objects/validation-error.js +68 -0
- package/frigg-cli/validate-command/infrastructure/validators/api-module-validator.js +181 -0
- package/frigg-cli/validate-command/infrastructure/validators/app-definition-validator.js +128 -0
- package/frigg-cli/validate-command/infrastructure/validators/integration-class-validator.js +113 -0
- package/infrastructure/create-frigg-infrastructure.js +93 -0
- package/infrastructure/docs/iam-policy-templates.md +1 -1
- package/infrastructure/domains/admin-scripts/admin-script-builder.js +200 -0
- package/infrastructure/domains/admin-scripts/admin-script-builder.test.js +499 -0
- package/infrastructure/domains/admin-scripts/index.js +5 -0
- package/infrastructure/domains/networking/vpc-builder.test.js +2 -4
- package/infrastructure/domains/networking/vpc-resolver.test.js +1 -1
- package/infrastructure/domains/shared/resource-discovery.js +5 -5
- package/infrastructure/domains/shared/types/app-definition.js +21 -0
- package/infrastructure/domains/shared/types/discovery-result.test.js +1 -1
- package/infrastructure/domains/shared/utilities/base-definition-factory.js +10 -1
- package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +2 -2
- package/infrastructure/infrastructure-composer.js +2 -0
- package/infrastructure/infrastructure-composer.test.js +2 -2
- package/infrastructure/jest.config.js +16 -0
- package/management-ui/README.md +245 -109
- package/package.json +8 -7
- package/frigg-cli/install-command/logger.js +0 -12
package/frigg-cli/__tests__/infrastructure/repositories/FileSystemAppDefinitionRepository.test.js
ADDED
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
const {FileSystemAppDefinitionRepository} = require('../../../infrastructure/repositories/FileSystemAppDefinitionRepository');
|
|
2
|
+
const {AppDefinition} = require('../../../domain/entities/AppDefinition');
|
|
3
|
+
|
|
4
|
+
describe('FileSystemAppDefinitionRepository', () => {
|
|
5
|
+
let repository;
|
|
6
|
+
let mockFileSystemAdapter;
|
|
7
|
+
let mockSchemaValidator;
|
|
8
|
+
let projectRoot;
|
|
9
|
+
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
projectRoot = '/test/project/backend';
|
|
12
|
+
|
|
13
|
+
mockFileSystemAdapter = {
|
|
14
|
+
exists: jest.fn(),
|
|
15
|
+
ensureDirectory: jest.fn(),
|
|
16
|
+
writeFile: jest.fn(),
|
|
17
|
+
updateFile: jest.fn(),
|
|
18
|
+
readFile: jest.fn(),
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
mockSchemaValidator = {
|
|
22
|
+
validate: jest.fn(),
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
repository = new FileSystemAppDefinitionRepository(
|
|
26
|
+
mockFileSystemAdapter,
|
|
27
|
+
projectRoot,
|
|
28
|
+
mockSchemaValidator
|
|
29
|
+
);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe('load', () => {
|
|
33
|
+
it('should load app definition from file', async () => {
|
|
34
|
+
const appDefJson = {
|
|
35
|
+
name: 'my-frigg-app',
|
|
36
|
+
version: '1.0.0',
|
|
37
|
+
description: 'Test app',
|
|
38
|
+
integrations: ['integration-1'],
|
|
39
|
+
apiModules: ['salesforce', 'stripe'],
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
mockFileSystemAdapter.exists.mockResolvedValue(true);
|
|
43
|
+
mockFileSystemAdapter.readFile.mockResolvedValue(JSON.stringify(appDefJson));
|
|
44
|
+
|
|
45
|
+
const result = await repository.load();
|
|
46
|
+
|
|
47
|
+
expect(result).toBeInstanceOf(AppDefinition);
|
|
48
|
+
expect(result.name).toBe('my-frigg-app');
|
|
49
|
+
expect(result.version.value).toBe('1.0.0');
|
|
50
|
+
expect(result.integrations).toEqual(['integration-1']);
|
|
51
|
+
expect(result.apiModules).toEqual(['salesforce', 'stripe']);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('should return null if app definition does not exist', async () => {
|
|
55
|
+
mockFileSystemAdapter.exists.mockResolvedValue(false);
|
|
56
|
+
|
|
57
|
+
const result = await repository.load();
|
|
58
|
+
|
|
59
|
+
expect(result).toBeNull();
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('should handle missing integrations array', async () => {
|
|
63
|
+
const appDefJson = {
|
|
64
|
+
name: 'my-frigg-app',
|
|
65
|
+
version: '1.0.0',
|
|
66
|
+
// no integrations field
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
mockFileSystemAdapter.exists.mockResolvedValue(true);
|
|
70
|
+
mockFileSystemAdapter.readFile.mockResolvedValue(JSON.stringify(appDefJson));
|
|
71
|
+
|
|
72
|
+
const result = await repository.load();
|
|
73
|
+
|
|
74
|
+
expect(result).toBeInstanceOf(AppDefinition);
|
|
75
|
+
expect(result.integrations).toEqual([]);
|
|
76
|
+
expect(result.apiModules).toEqual([]);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
describe('save', () => {
|
|
81
|
+
it('should save app definition to file', async () => {
|
|
82
|
+
const appDef = AppDefinition.create({
|
|
83
|
+
name: 'my-frigg-app',
|
|
84
|
+
version: '1.0.0',
|
|
85
|
+
description: 'Test app',
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
mockSchemaValidator.validate.mockResolvedValue({valid: true, errors: []});
|
|
89
|
+
mockFileSystemAdapter.exists.mockResolvedValue(false);
|
|
90
|
+
|
|
91
|
+
await repository.save(appDef);
|
|
92
|
+
|
|
93
|
+
expect(mockFileSystemAdapter.ensureDirectory).toHaveBeenCalledWith(
|
|
94
|
+
'/test/project/backend'
|
|
95
|
+
);
|
|
96
|
+
expect(mockFileSystemAdapter.writeFile).toHaveBeenCalledWith(
|
|
97
|
+
'/test/project/backend/app-definition.json',
|
|
98
|
+
expect.stringContaining('"name": "my-frigg-app"')
|
|
99
|
+
);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('should update existing app definition file', async () => {
|
|
103
|
+
const appDef = AppDefinition.create({
|
|
104
|
+
name: 'my-frigg-app',
|
|
105
|
+
version: '1.0.0',
|
|
106
|
+
description: 'Test app',
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
mockSchemaValidator.validate.mockResolvedValue({valid: true, errors: []});
|
|
110
|
+
mockFileSystemAdapter.exists.mockResolvedValue(true);
|
|
111
|
+
|
|
112
|
+
await repository.save(appDef);
|
|
113
|
+
|
|
114
|
+
expect(mockFileSystemAdapter.updateFile).toHaveBeenCalled();
|
|
115
|
+
expect(mockFileSystemAdapter.writeFile).not.toHaveBeenCalled();
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('should throw error if validation fails', async () => {
|
|
119
|
+
const appDef = AppDefinition.create({
|
|
120
|
+
name: 'my-frigg-app',
|
|
121
|
+
version: '1.0.0',
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
// Mock validate to return invalid
|
|
125
|
+
jest.spyOn(appDef, 'validate').mockReturnValue({
|
|
126
|
+
isValid: false,
|
|
127
|
+
errors: ['Invalid configuration'],
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
await expect(repository.save(appDef)).rejects.toThrow(
|
|
131
|
+
'AppDefinition validation failed'
|
|
132
|
+
);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it('should throw error if schema validation fails', async () => {
|
|
136
|
+
const appDef = AppDefinition.create({
|
|
137
|
+
name: 'my-frigg-app',
|
|
138
|
+
version: '1.0.0',
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
mockSchemaValidator.validate.mockResolvedValue({
|
|
142
|
+
valid: false,
|
|
143
|
+
errors: ['Invalid schema'],
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
await expect(repository.save(appDef)).rejects.toThrow(
|
|
147
|
+
'Schema validation failed'
|
|
148
|
+
);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it('should save with integrations and API modules', async () => {
|
|
152
|
+
const appDef = AppDefinition.create({
|
|
153
|
+
name: 'my-frigg-app',
|
|
154
|
+
version: '1.0.0',
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
appDef.registerIntegration('test-integration', {
|
|
158
|
+
name: 'test-integration',
|
|
159
|
+
version: '1.0.0',
|
|
160
|
+
type: 'api',
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
appDef.registerApiModule('salesforce', {
|
|
164
|
+
name: 'salesforce',
|
|
165
|
+
version: '1.0.0',
|
|
166
|
+
authType: 'oauth2',
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
mockSchemaValidator.validate.mockResolvedValue({valid: true, errors: []});
|
|
170
|
+
mockFileSystemAdapter.exists.mockResolvedValue(false);
|
|
171
|
+
|
|
172
|
+
await repository.save(appDef);
|
|
173
|
+
|
|
174
|
+
const writeCall = mockFileSystemAdapter.writeFile.mock.calls[0];
|
|
175
|
+
const savedData = JSON.parse(writeCall[1]);
|
|
176
|
+
|
|
177
|
+
// AppDefinition stores integrations and apiModules as objects
|
|
178
|
+
expect(savedData.integrations).toEqual([{
|
|
179
|
+
name: 'test-integration',
|
|
180
|
+
enabled: true,
|
|
181
|
+
}]);
|
|
182
|
+
// apiModules include name, source, and version object
|
|
183
|
+
expect(savedData.apiModules).toHaveLength(1);
|
|
184
|
+
expect(savedData.apiModules[0].name).toBe('salesforce');
|
|
185
|
+
expect(savedData.apiModules[0].source).toBe('npm'); // default source
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it('should format JSON with 2-space indentation', async () => {
|
|
189
|
+
const appDef = AppDefinition.create({
|
|
190
|
+
name: 'my-frigg-app',
|
|
191
|
+
version: '1.0.0',
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
mockSchemaValidator.validate.mockResolvedValue({valid: true, errors: []});
|
|
195
|
+
mockFileSystemAdapter.exists.mockResolvedValue(false);
|
|
196
|
+
|
|
197
|
+
await repository.save(appDef);
|
|
198
|
+
|
|
199
|
+
const writeCall = mockFileSystemAdapter.writeFile.mock.calls[0];
|
|
200
|
+
const content = writeCall[1];
|
|
201
|
+
|
|
202
|
+
// Check for 2-space indentation
|
|
203
|
+
expect(content).toMatch(/{\n "name"/);
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
describe('exists', () => {
|
|
208
|
+
it('should return true if app definition exists', async () => {
|
|
209
|
+
mockFileSystemAdapter.exists.mockResolvedValue(true);
|
|
210
|
+
|
|
211
|
+
const result = await repository.exists();
|
|
212
|
+
|
|
213
|
+
expect(result).toBe(true);
|
|
214
|
+
expect(mockFileSystemAdapter.exists).toHaveBeenCalledWith(
|
|
215
|
+
'/test/project/backend/app-definition.json'
|
|
216
|
+
);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it('should return false if app definition does not exist', async () => {
|
|
220
|
+
mockFileSystemAdapter.exists.mockResolvedValue(false);
|
|
221
|
+
|
|
222
|
+
const result = await repository.exists();
|
|
223
|
+
|
|
224
|
+
expect(result).toBe(false);
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
describe('create', () => {
|
|
229
|
+
it('should create new app definition', async () => {
|
|
230
|
+
mockFileSystemAdapter.exists.mockResolvedValue(false);
|
|
231
|
+
mockSchemaValidator.validate.mockResolvedValue({valid: true, errors: []});
|
|
232
|
+
|
|
233
|
+
const result = await repository.create({
|
|
234
|
+
name: 'my-frigg-app',
|
|
235
|
+
version: '1.0.0',
|
|
236
|
+
description: 'Test app',
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
expect(result).toBeInstanceOf(AppDefinition);
|
|
240
|
+
expect(result.name).toBe('my-frigg-app');
|
|
241
|
+
expect(mockFileSystemAdapter.writeFile).toHaveBeenCalled();
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
it('should throw error if app definition already exists', async () => {
|
|
245
|
+
mockFileSystemAdapter.exists.mockResolvedValue(true);
|
|
246
|
+
|
|
247
|
+
await expect(
|
|
248
|
+
repository.create({
|
|
249
|
+
name: 'my-frigg-app',
|
|
250
|
+
version: '1.0.0',
|
|
251
|
+
})
|
|
252
|
+
).rejects.toThrow('App definition already exists');
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
it('should validate and save created app definition', async () => {
|
|
256
|
+
mockFileSystemAdapter.exists.mockResolvedValue(false);
|
|
257
|
+
mockSchemaValidator.validate.mockResolvedValue({valid: true, errors: []});
|
|
258
|
+
|
|
259
|
+
await repository.create({
|
|
260
|
+
name: 'my-frigg-app',
|
|
261
|
+
version: '1.0.0',
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
expect(mockSchemaValidator.validate).toHaveBeenCalledWith(
|
|
265
|
+
'app-definition',
|
|
266
|
+
expect.any(Object)
|
|
267
|
+
);
|
|
268
|
+
expect(mockFileSystemAdapter.writeFile).toHaveBeenCalled();
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
describe('_toDomainEntity', () => {
|
|
273
|
+
it('should convert JSON to AppDefinition entity', () => {
|
|
274
|
+
const data = {
|
|
275
|
+
name: 'my-frigg-app',
|
|
276
|
+
version: '1.0.0',
|
|
277
|
+
description: 'Test app',
|
|
278
|
+
author: 'Test Author',
|
|
279
|
+
license: 'MIT',
|
|
280
|
+
repository: 'https://github.com/test/repo',
|
|
281
|
+
integrations: ['integration-1'],
|
|
282
|
+
apiModules: ['salesforce'],
|
|
283
|
+
config: {env: 'production'},
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
const result = repository._toDomainEntity(data);
|
|
287
|
+
|
|
288
|
+
expect(result).toBeInstanceOf(AppDefinition);
|
|
289
|
+
expect(result.name).toBe('my-frigg-app');
|
|
290
|
+
expect(result.version.value).toBe('1.0.0');
|
|
291
|
+
expect(result.description).toBe('Test app');
|
|
292
|
+
expect(result.author).toBe('Test Author');
|
|
293
|
+
expect(result.license).toBe('MIT');
|
|
294
|
+
expect(result.repository).toBe('https://github.com/test/repo');
|
|
295
|
+
expect(result.integrations).toEqual(['integration-1']);
|
|
296
|
+
expect(result.apiModules).toEqual(['salesforce']);
|
|
297
|
+
expect(result.config).toEqual({env: 'production'});
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
it('should handle minimal data', () => {
|
|
301
|
+
const data = {
|
|
302
|
+
name: 'my-frigg-app',
|
|
303
|
+
version: '1.0.0',
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
const result = repository._toDomainEntity(data);
|
|
307
|
+
|
|
308
|
+
expect(result).toBeInstanceOf(AppDefinition);
|
|
309
|
+
expect(result.integrations).toEqual([]);
|
|
310
|
+
expect(result.apiModules).toEqual([]);
|
|
311
|
+
expect(result.config).toEqual({});
|
|
312
|
+
});
|
|
313
|
+
});
|
|
314
|
+
});
|
package/frigg-cli/__tests__/infrastructure/repositories/FileSystemIntegrationRepository.test.js
ADDED
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
const {FileSystemIntegrationRepository} = require('../../../infrastructure/repositories/FileSystemIntegrationRepository');
|
|
2
|
+
const {Integration} = require('../../../domain/entities/Integration');
|
|
3
|
+
const {IntegrationName} = require('../../../domain/value-objects/IntegrationName');
|
|
4
|
+
|
|
5
|
+
describe('FileSystemIntegrationRepository', () => {
|
|
6
|
+
let repository;
|
|
7
|
+
let mockFileSystemAdapter;
|
|
8
|
+
let mockSchemaValidator;
|
|
9
|
+
let backendPath;
|
|
10
|
+
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
backendPath = '/test/project/backend';
|
|
13
|
+
|
|
14
|
+
mockFileSystemAdapter = {
|
|
15
|
+
exists: jest.fn(),
|
|
16
|
+
ensureDirectory: jest.fn(),
|
|
17
|
+
writeFile: jest.fn(),
|
|
18
|
+
readFile: jest.fn(),
|
|
19
|
+
listFiles: jest.fn(),
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
mockSchemaValidator = {
|
|
23
|
+
validate: jest.fn(),
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
repository = new FileSystemIntegrationRepository(
|
|
27
|
+
mockFileSystemAdapter,
|
|
28
|
+
backendPath,
|
|
29
|
+
mockSchemaValidator
|
|
30
|
+
);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
describe('save', () => {
|
|
34
|
+
it('should save a new integration as a single file', async () => {
|
|
35
|
+
const integration = new Integration({
|
|
36
|
+
name: 'test-integration',
|
|
37
|
+
version: '1.0.0',
|
|
38
|
+
displayName: 'Test Integration',
|
|
39
|
+
description: 'Test description',
|
|
40
|
+
type: 'sync',
|
|
41
|
+
category: 'CRM',
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
mockSchemaValidator.validate.mockResolvedValue({valid: true, errors: []});
|
|
45
|
+
mockFileSystemAdapter.exists.mockResolvedValue(false); // Integration.js doesn't exist yet
|
|
46
|
+
|
|
47
|
+
await repository.save(integration);
|
|
48
|
+
|
|
49
|
+
// Verify integrations directory created
|
|
50
|
+
expect(mockFileSystemAdapter.ensureDirectory).toHaveBeenCalledWith(
|
|
51
|
+
'/test/project/backend/src/integrations'
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
// Verify schema validation
|
|
55
|
+
expect(mockSchemaValidator.validate).toHaveBeenCalledWith(
|
|
56
|
+
'integration-definition',
|
|
57
|
+
expect.any(Object)
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
// Verify only Integration.js written
|
|
61
|
+
expect(mockFileSystemAdapter.writeFile).toHaveBeenCalledTimes(1);
|
|
62
|
+
|
|
63
|
+
// Verify Integration.js content
|
|
64
|
+
const writeCall = mockFileSystemAdapter.writeFile.mock.calls[0];
|
|
65
|
+
expect(writeCall[0]).toBe('/test/project/backend/src/integrations/TestIntegrationIntegration.js');
|
|
66
|
+
expect(writeCall[1]).toContain('class TestIntegrationIntegration extends IntegrationBase');
|
|
67
|
+
expect(writeCall[1]).toContain('static Definition = {');
|
|
68
|
+
expect(writeCall[1]).toContain("name: 'test-integration'");
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('should NOT write Integration.js if it already exists', async () => {
|
|
72
|
+
const integration = new Integration({
|
|
73
|
+
name: 'test-integration',
|
|
74
|
+
version: '1.0.0',
|
|
75
|
+
displayName: 'Test Integration',
|
|
76
|
+
description: 'Test description',
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
mockSchemaValidator.validate.mockResolvedValue({valid: true, errors: []});
|
|
80
|
+
mockFileSystemAdapter.exists.mockResolvedValue(true); // Integration.js already exists
|
|
81
|
+
|
|
82
|
+
await repository.save(integration);
|
|
83
|
+
|
|
84
|
+
// Verify Integration.js NOT written
|
|
85
|
+
expect(mockFileSystemAdapter.writeFile).not.toHaveBeenCalled();
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('should throw error if integration is invalid', async () => {
|
|
89
|
+
// Create invalid integration (invalid type)
|
|
90
|
+
const integration = new Integration({
|
|
91
|
+
name: 'test-integration',
|
|
92
|
+
version: '1.0.0',
|
|
93
|
+
displayName: 'Test Integration',
|
|
94
|
+
type: 'invalid-type',
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
await expect(repository.save(integration)).rejects.toThrow('Invalid integration');
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('should throw error if schema validation fails', async () => {
|
|
101
|
+
const integration = new Integration({
|
|
102
|
+
name: 'test-integration',
|
|
103
|
+
version: '1.0.0',
|
|
104
|
+
displayName: 'Test Integration',
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
mockSchemaValidator.validate.mockResolvedValue({
|
|
108
|
+
valid: false,
|
|
109
|
+
errors: ['Invalid schema'],
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
await expect(repository.save(integration)).rejects.toThrow('Schema validation failed');
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('should handle kebab-case to PascalCase conversion correctly', async () => {
|
|
116
|
+
const integration = new Integration({
|
|
117
|
+
name: 'my-awesome-api',
|
|
118
|
+
version: '1.0.0',
|
|
119
|
+
displayName: 'My Awesome API',
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
mockSchemaValidator.validate.mockResolvedValue({valid: true, errors: []});
|
|
123
|
+
mockFileSystemAdapter.exists.mockResolvedValue(false);
|
|
124
|
+
|
|
125
|
+
await repository.save(integration);
|
|
126
|
+
|
|
127
|
+
const writeCall = mockFileSystemAdapter.writeFile.mock.calls[0];
|
|
128
|
+
expect(writeCall[0]).toBe('/test/project/backend/src/integrations/MyAwesomeApiIntegration.js');
|
|
129
|
+
expect(writeCall[1]).toContain('class MyAwesomeApiIntegration extends IntegrationBase');
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
describe('findByName', () => {
|
|
134
|
+
it('should find integration by name string', async () => {
|
|
135
|
+
const integrationJsContent = `
|
|
136
|
+
class TestIntegrationIntegration extends IntegrationBase {
|
|
137
|
+
static Definition = {
|
|
138
|
+
name: 'test-integration',
|
|
139
|
+
version: '1.0.0',
|
|
140
|
+
display: {
|
|
141
|
+
label: 'Test Integration',
|
|
142
|
+
description: 'Test description',
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
module.exports = TestIntegrationIntegration;
|
|
147
|
+
`;
|
|
148
|
+
|
|
149
|
+
mockFileSystemAdapter.exists.mockResolvedValue(true);
|
|
150
|
+
mockFileSystemAdapter.readFile.mockResolvedValue(integrationJsContent);
|
|
151
|
+
|
|
152
|
+
const result = await repository.findByName('test-integration');
|
|
153
|
+
|
|
154
|
+
expect(result).toBeInstanceOf(Integration);
|
|
155
|
+
expect(result.name.value).toBe('test-integration');
|
|
156
|
+
expect(result.version.value).toBe('1.0.0');
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it('should find integration by IntegrationName value object', async () => {
|
|
160
|
+
const integrationJsContent = `
|
|
161
|
+
class TestIntegrationIntegration extends IntegrationBase {
|
|
162
|
+
static Definition = {
|
|
163
|
+
name: 'test-integration',
|
|
164
|
+
version: '1.0.0',
|
|
165
|
+
display: {},
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
`;
|
|
169
|
+
|
|
170
|
+
mockFileSystemAdapter.exists.mockResolvedValue(true);
|
|
171
|
+
mockFileSystemAdapter.readFile.mockResolvedValue(integrationJsContent);
|
|
172
|
+
|
|
173
|
+
const name = new IntegrationName('test-integration');
|
|
174
|
+
const result = await repository.findByName(name);
|
|
175
|
+
|
|
176
|
+
expect(result).toBeInstanceOf(Integration);
|
|
177
|
+
expect(result.name.value).toBe('test-integration');
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it('should return null if integration file does not exist', async () => {
|
|
181
|
+
mockFileSystemAdapter.exists.mockResolvedValue(false);
|
|
182
|
+
|
|
183
|
+
const result = await repository.findByName('nonexistent');
|
|
184
|
+
|
|
185
|
+
expect(result).toBeNull();
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
describe('exists', () => {
|
|
190
|
+
it('should return true if integration exists', async () => {
|
|
191
|
+
mockFileSystemAdapter.exists.mockResolvedValue(true);
|
|
192
|
+
|
|
193
|
+
const result = await repository.exists('test-integration');
|
|
194
|
+
|
|
195
|
+
expect(result).toBe(true);
|
|
196
|
+
expect(mockFileSystemAdapter.exists).toHaveBeenCalledWith(
|
|
197
|
+
'/test/project/backend/src/integrations/TestIntegrationIntegration.js'
|
|
198
|
+
);
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it('should return false if integration does not exist', async () => {
|
|
202
|
+
mockFileSystemAdapter.exists.mockResolvedValue(false);
|
|
203
|
+
|
|
204
|
+
const result = await repository.exists('nonexistent');
|
|
205
|
+
|
|
206
|
+
expect(result).toBe(false);
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it('should work with IntegrationName value object', async () => {
|
|
210
|
+
mockFileSystemAdapter.exists.mockResolvedValue(true);
|
|
211
|
+
|
|
212
|
+
const name = new IntegrationName('test-integration');
|
|
213
|
+
const result = await repository.exists(name);
|
|
214
|
+
|
|
215
|
+
expect(result).toBe(true);
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
describe('list', () => {
|
|
220
|
+
it('should return empty array if integrations directory does not exist', async () => {
|
|
221
|
+
mockFileSystemAdapter.exists.mockResolvedValue(false);
|
|
222
|
+
|
|
223
|
+
const result = await repository.list();
|
|
224
|
+
|
|
225
|
+
expect(result).toEqual([]);
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
it('should return list of all integrations', async () => {
|
|
229
|
+
mockFileSystemAdapter.exists.mockResolvedValue(true);
|
|
230
|
+
mockFileSystemAdapter.listFiles.mockResolvedValue([
|
|
231
|
+
'Integration1Integration.js',
|
|
232
|
+
'Integration2Integration.js',
|
|
233
|
+
]);
|
|
234
|
+
|
|
235
|
+
const integration1Content = `
|
|
236
|
+
class Integration1Integration extends IntegrationBase {
|
|
237
|
+
static Definition = {
|
|
238
|
+
name: 'integration-1',
|
|
239
|
+
version: '1.0.0',
|
|
240
|
+
display: {},
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
`;
|
|
244
|
+
|
|
245
|
+
const integration2Content = `
|
|
246
|
+
class Integration2Integration extends IntegrationBase {
|
|
247
|
+
static Definition = {
|
|
248
|
+
name: 'integration-2',
|
|
249
|
+
version: '2.0.0',
|
|
250
|
+
display: {},
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
`;
|
|
254
|
+
|
|
255
|
+
mockFileSystemAdapter.readFile
|
|
256
|
+
.mockResolvedValueOnce(integration1Content)
|
|
257
|
+
.mockResolvedValueOnce(integration2Content);
|
|
258
|
+
|
|
259
|
+
const result = await repository.list();
|
|
260
|
+
|
|
261
|
+
expect(result).toHaveLength(2);
|
|
262
|
+
expect(result[0]).toBeInstanceOf(Integration);
|
|
263
|
+
expect(result[0].name.value).toBe('integration-1');
|
|
264
|
+
expect(result[1].name.value).toBe('integration-2');
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
it('should skip invalid integrations and log warning', async () => {
|
|
268
|
+
const consoleWarnSpy = jest.spyOn(console, 'warn').mockImplementation();
|
|
269
|
+
|
|
270
|
+
mockFileSystemAdapter.exists.mockResolvedValue(true);
|
|
271
|
+
mockFileSystemAdapter.listFiles.mockResolvedValue([
|
|
272
|
+
'ValidIntegration.js',
|
|
273
|
+
'InvalidIntegration.js',
|
|
274
|
+
]);
|
|
275
|
+
|
|
276
|
+
const validContent = `
|
|
277
|
+
class ValidIntegration extends IntegrationBase {
|
|
278
|
+
static Definition = {
|
|
279
|
+
name: 'valid-integration',
|
|
280
|
+
version: '1.0.0',
|
|
281
|
+
display: {},
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
`;
|
|
285
|
+
|
|
286
|
+
mockFileSystemAdapter.readFile
|
|
287
|
+
.mockResolvedValueOnce(validContent)
|
|
288
|
+
.mockRejectedValueOnce(new Error('Read error'));
|
|
289
|
+
|
|
290
|
+
const result = await repository.list();
|
|
291
|
+
|
|
292
|
+
expect(result).toHaveLength(1);
|
|
293
|
+
expect(result[0].name.value).toBe('valid-integration');
|
|
294
|
+
expect(consoleWarnSpy).toHaveBeenCalledWith(
|
|
295
|
+
expect.stringContaining('Failed to load integration'),
|
|
296
|
+
expect.any(String)
|
|
297
|
+
);
|
|
298
|
+
|
|
299
|
+
consoleWarnSpy.mockRestore();
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
it('should filter out non-Integration files', async () => {
|
|
303
|
+
mockFileSystemAdapter.exists.mockResolvedValue(true);
|
|
304
|
+
mockFileSystemAdapter.listFiles.mockResolvedValue([
|
|
305
|
+
'TestIntegration.js',
|
|
306
|
+
'helper.js',
|
|
307
|
+
'utils.js',
|
|
308
|
+
]);
|
|
309
|
+
|
|
310
|
+
const integrationContent = `
|
|
311
|
+
class TestIntegration extends IntegrationBase {
|
|
312
|
+
static Definition = {
|
|
313
|
+
name: 'test',
|
|
314
|
+
version: '1.0.0',
|
|
315
|
+
display: {},
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
`;
|
|
319
|
+
|
|
320
|
+
mockFileSystemAdapter.readFile.mockResolvedValue(integrationContent);
|
|
321
|
+
|
|
322
|
+
const result = await repository.list();
|
|
323
|
+
|
|
324
|
+
// Should only process TestIntegration.js (ends with Integration.js)
|
|
325
|
+
expect(mockFileSystemAdapter.readFile).toHaveBeenCalledTimes(1);
|
|
326
|
+
expect(result).toHaveLength(1);
|
|
327
|
+
});
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
describe('_generateIntegrationClass', () => {
|
|
331
|
+
it('should generate valid Integration.js class file', () => {
|
|
332
|
+
const integration = new Integration({
|
|
333
|
+
name: 'my-test-integration',
|
|
334
|
+
version: '1.0.0',
|
|
335
|
+
displayName: 'My Test Integration',
|
|
336
|
+
description: 'Test description',
|
|
337
|
+
category: 'CRM',
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
const result = repository._generateIntegrationClass(integration);
|
|
341
|
+
|
|
342
|
+
expect(result).toContain("const { IntegrationBase } = require('@friggframework/core');");
|
|
343
|
+
expect(result).toContain('class MyTestIntegrationIntegration extends IntegrationBase');
|
|
344
|
+
expect(result).toContain('static Definition = {');
|
|
345
|
+
expect(result).toContain("name: 'my-test-integration'");
|
|
346
|
+
expect(result).toContain("version: '1.0.0'");
|
|
347
|
+
expect(result).toContain('modules: {');
|
|
348
|
+
expect(result).toContain('routes: [');
|
|
349
|
+
expect(result).toContain('module.exports = MyTestIntegrationIntegration');
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
it('should handle single-word integration names', () => {
|
|
353
|
+
const integration = new Integration({
|
|
354
|
+
name: 'salesforce',
|
|
355
|
+
version: '1.0.0',
|
|
356
|
+
displayName: 'Salesforce',
|
|
357
|
+
description: 'Salesforce integration',
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
const result = repository._generateIntegrationClass(integration);
|
|
361
|
+
|
|
362
|
+
expect(result).toContain('class SalesforceIntegration extends IntegrationBase');
|
|
363
|
+
expect(result).toContain('module.exports = SalesforceIntegration');
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
it('should include proper JSDoc comments', () => {
|
|
367
|
+
const integration = new Integration({
|
|
368
|
+
name: 'test-integration',
|
|
369
|
+
version: '1.0.0',
|
|
370
|
+
displayName: 'Test Integration',
|
|
371
|
+
description: 'Test description',
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
const result = repository._generateIntegrationClass(integration);
|
|
375
|
+
|
|
376
|
+
expect(result).toContain('/**');
|
|
377
|
+
expect(result).toContain('* Test Integration');
|
|
378
|
+
expect(result).toContain('* Test description');
|
|
379
|
+
expect(result).toContain('*/');
|
|
380
|
+
});
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
});
|