@friggframework/devtools 2.0.0--canary.546.74db90f.0 → 2.0.0--canary.545.e7becd9.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/cloudformation-discovery.test.js +4 -7
- 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/README.md
CHANGED
|
@@ -1281,7 +1281,7 @@ npm install @friggframework/frigg-cli@latest
|
|
|
1281
1281
|
npm install -g @friggframework/frigg-cli
|
|
1282
1282
|
|
|
1283
1283
|
# Local project dependencies
|
|
1284
|
-
|
|
1284
|
+
frigg init my-app
|
|
1285
1285
|
# (Will automatically include @friggframework/frigg-cli in package.json)
|
|
1286
1286
|
```
|
|
1287
1287
|
|
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
const {AddApiModuleToIntegrationUseCase} = require('../../../application/use-cases/AddApiModuleToIntegrationUseCase');
|
|
2
|
+
const {Integration} = require('../../../domain/entities/Integration');
|
|
3
|
+
const {IntegrationName} = require('../../../domain/value-objects/IntegrationName');
|
|
4
|
+
const {SemanticVersion} = require('../../../domain/value-objects/SemanticVersion');
|
|
5
|
+
const {ValidationException} = require('../../../domain/exceptions/DomainException');
|
|
6
|
+
|
|
7
|
+
// Mock dependencies
|
|
8
|
+
class MockIntegrationRepository {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.integrations = new Map();
|
|
11
|
+
this.saveCalled = false;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async save(integration) {
|
|
15
|
+
this.saveCalled = true;
|
|
16
|
+
this.integrations.set(integration.name.value, integration);
|
|
17
|
+
return integration;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async findByName(name) {
|
|
21
|
+
return this.integrations.get(name) || null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async exists(name) {
|
|
25
|
+
return this.integrations.has(name);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
class MockApiModuleRepository {
|
|
30
|
+
constructor() {
|
|
31
|
+
this.modules = new Set(['salesforce', 'stripe', 'hubspot']);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async exists(name) {
|
|
35
|
+
return this.modules.has(name);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
class MockUnitOfWork {
|
|
40
|
+
constructor() {
|
|
41
|
+
this.committed = false;
|
|
42
|
+
this.rolledBack = false;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async commit() {
|
|
46
|
+
this.committed = true;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async rollback() {
|
|
50
|
+
this.rolledBack = true;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
class MockIntegrationValidator {
|
|
55
|
+
constructor() {
|
|
56
|
+
this.validateCalled = false;
|
|
57
|
+
this.shouldFail = false;
|
|
58
|
+
this.errors = [];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
validateApiModuleAddition(integration, moduleName, moduleVersion) {
|
|
62
|
+
this.validateCalled = true;
|
|
63
|
+
if (this.shouldFail) {
|
|
64
|
+
return {
|
|
65
|
+
isValid: false,
|
|
66
|
+
errors: this.errors
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
isValid: true,
|
|
71
|
+
errors: []
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
describe('AddApiModuleToIntegrationUseCase', () => {
|
|
77
|
+
let useCase;
|
|
78
|
+
let mockIntegrationRepository;
|
|
79
|
+
let mockApiModuleRepository;
|
|
80
|
+
let mockUnitOfWork;
|
|
81
|
+
let mockValidator;
|
|
82
|
+
|
|
83
|
+
beforeEach(() => {
|
|
84
|
+
mockIntegrationRepository = new MockIntegrationRepository();
|
|
85
|
+
mockApiModuleRepository = new MockApiModuleRepository();
|
|
86
|
+
mockUnitOfWork = new MockUnitOfWork();
|
|
87
|
+
mockValidator = new MockIntegrationValidator();
|
|
88
|
+
|
|
89
|
+
useCase = new AddApiModuleToIntegrationUseCase(
|
|
90
|
+
mockIntegrationRepository,
|
|
91
|
+
mockApiModuleRepository,
|
|
92
|
+
mockUnitOfWork,
|
|
93
|
+
mockValidator
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
// Add a test integration
|
|
97
|
+
const integration = Integration.create({
|
|
98
|
+
name: 'test-integration',
|
|
99
|
+
type: 'api',
|
|
100
|
+
displayName: 'Test Integration',
|
|
101
|
+
description: 'Test',
|
|
102
|
+
category: 'CRM'
|
|
103
|
+
});
|
|
104
|
+
mockIntegrationRepository.integrations.set('test-integration', integration);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
describe('execute()', () => {
|
|
108
|
+
test('successfully adds API module to integration', async () => {
|
|
109
|
+
const request = {
|
|
110
|
+
integrationName: 'test-integration',
|
|
111
|
+
moduleName: 'salesforce',
|
|
112
|
+
moduleVersion: '1.0.0',
|
|
113
|
+
source: 'local'
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const result = await useCase.execute(request);
|
|
117
|
+
|
|
118
|
+
expect(result.success).toBe(true);
|
|
119
|
+
expect(result.message).toContain("API module 'salesforce' added");
|
|
120
|
+
expect(result.integration.apiModules).toHaveLength(1);
|
|
121
|
+
expect(result.integration.apiModules[0].name).toBe('salesforce');
|
|
122
|
+
expect(mockIntegrationRepository.saveCalled).toBe(true);
|
|
123
|
+
expect(mockUnitOfWork.committed).toBe(true);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
test('adds module with correct version', async () => {
|
|
127
|
+
const request = {
|
|
128
|
+
integrationName: 'test-integration',
|
|
129
|
+
moduleName: 'salesforce',
|
|
130
|
+
moduleVersion: '2.3.0'
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
const result = await useCase.execute(request);
|
|
134
|
+
|
|
135
|
+
expect(result.success).toBe(true);
|
|
136
|
+
expect(result.integration.apiModules[0].version).toBe('2.3.0');
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
test('defaults version to 1.0.0 when not provided', async () => {
|
|
140
|
+
const request = {
|
|
141
|
+
integrationName: 'test-integration',
|
|
142
|
+
moduleName: 'salesforce'
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
const result = await useCase.execute(request);
|
|
146
|
+
|
|
147
|
+
expect(result.success).toBe(true);
|
|
148
|
+
expect(result.integration.apiModules[0].version).toBe('1.0.0');
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
test('defaults source to local when not provided', async () => {
|
|
152
|
+
const request = {
|
|
153
|
+
integrationName: 'test-integration',
|
|
154
|
+
moduleName: 'salesforce'
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
const result = await useCase.execute(request);
|
|
158
|
+
|
|
159
|
+
expect(result.success).toBe(true);
|
|
160
|
+
expect(result.integration.apiModules[0].source).toBe('local');
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
test('allows custom source', async () => {
|
|
164
|
+
const request = {
|
|
165
|
+
integrationName: 'test-integration',
|
|
166
|
+
moduleName: 'salesforce',
|
|
167
|
+
source: 'npm'
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
const result = await useCase.execute(request);
|
|
171
|
+
|
|
172
|
+
expect(result.success).toBe(true);
|
|
173
|
+
expect(result.integration.apiModules[0].source).toBe('npm');
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
test('throws error when integration not found', async () => {
|
|
177
|
+
const request = {
|
|
178
|
+
integrationName: 'non-existent',
|
|
179
|
+
moduleName: 'salesforce'
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
await expect(useCase.execute(request)).rejects.toThrow(ValidationException);
|
|
183
|
+
await expect(useCase.execute(request)).rejects.toThrow("Integration 'non-existent' not found");
|
|
184
|
+
expect(mockUnitOfWork.rolledBack).toBe(true);
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
test('throws error when API module does not exist', async () => {
|
|
188
|
+
const request = {
|
|
189
|
+
integrationName: 'test-integration',
|
|
190
|
+
moduleName: 'non-existent-module'
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
await expect(useCase.execute(request)).rejects.toThrow(ValidationException);
|
|
194
|
+
await expect(useCase.execute(request)).rejects.toThrow("API module 'non-existent-module' not found");
|
|
195
|
+
await expect(useCase.execute(request)).rejects.toThrow('Create it first');
|
|
196
|
+
expect(mockUnitOfWork.rolledBack).toBe(true);
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
test('throws error when API module already added', async () => {
|
|
200
|
+
// First add
|
|
201
|
+
await useCase.execute({
|
|
202
|
+
integrationName: 'test-integration',
|
|
203
|
+
moduleName: 'salesforce'
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
// Try to add again
|
|
207
|
+
const request = {
|
|
208
|
+
integrationName: 'test-integration',
|
|
209
|
+
moduleName: 'salesforce'
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
await expect(useCase.execute(request)).rejects.toThrow();
|
|
213
|
+
await expect(useCase.execute(request)).rejects.toThrow('already added');
|
|
214
|
+
expect(mockUnitOfWork.rolledBack).toBe(true);
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
test('calls validator with correct parameters', async () => {
|
|
218
|
+
const request = {
|
|
219
|
+
integrationName: 'test-integration',
|
|
220
|
+
moduleName: 'salesforce',
|
|
221
|
+
moduleVersion: '1.5.0'
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
await useCase.execute(request);
|
|
225
|
+
|
|
226
|
+
expect(mockValidator.validateCalled).toBe(true);
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
test('throws error when validation fails', async () => {
|
|
230
|
+
mockValidator.shouldFail = true;
|
|
231
|
+
mockValidator.errors = ['Some validation error'];
|
|
232
|
+
|
|
233
|
+
const request = {
|
|
234
|
+
integrationName: 'test-integration',
|
|
235
|
+
moduleName: 'salesforce'
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
await expect(useCase.execute(request)).rejects.toThrow(ValidationException);
|
|
239
|
+
expect(mockUnitOfWork.rolledBack).toBe(true);
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
test('commits transaction only after all operations succeed', async () => {
|
|
243
|
+
const request = {
|
|
244
|
+
integrationName: 'test-integration',
|
|
245
|
+
moduleName: 'salesforce'
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
await useCase.execute(request);
|
|
249
|
+
|
|
250
|
+
expect(mockIntegrationRepository.saveCalled).toBe(true);
|
|
251
|
+
expect(mockUnitOfWork.committed).toBe(true);
|
|
252
|
+
expect(mockUnitOfWork.rolledBack).toBe(false);
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
test('rollsback on repository save error', async () => {
|
|
256
|
+
mockIntegrationRepository.save = async () => {
|
|
257
|
+
throw new Error('Database error');
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
const request = {
|
|
261
|
+
integrationName: 'test-integration',
|
|
262
|
+
moduleName: 'salesforce'
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
await expect(useCase.execute(request)).rejects.toThrow('Database error');
|
|
266
|
+
expect(mockUnitOfWork.rolledBack).toBe(true);
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
test('allows adding multiple different API modules', async () => {
|
|
270
|
+
await useCase.execute({
|
|
271
|
+
integrationName: 'test-integration',
|
|
272
|
+
moduleName: 'salesforce'
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
const result = await useCase.execute({
|
|
276
|
+
integrationName: 'test-integration',
|
|
277
|
+
moduleName: 'stripe'
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
expect(result.success).toBe(true);
|
|
281
|
+
expect(result.integration.apiModules).toHaveLength(2);
|
|
282
|
+
expect(result.integration.apiModules.map(m => m.name)).toContain('salesforce');
|
|
283
|
+
expect(result.integration.apiModules.map(m => m.name)).toContain('stripe');
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
test('returns integration object with updated apiModules', async () => {
|
|
287
|
+
const request = {
|
|
288
|
+
integrationName: 'test-integration',
|
|
289
|
+
moduleName: 'salesforce',
|
|
290
|
+
moduleVersion: '1.0.0',
|
|
291
|
+
source: 'local'
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
const result = await useCase.execute(request);
|
|
295
|
+
|
|
296
|
+
expect(result.integration).toHaveProperty('id');
|
|
297
|
+
expect(result.integration).toHaveProperty('name');
|
|
298
|
+
expect(result.integration).toHaveProperty('version');
|
|
299
|
+
expect(result.integration).toHaveProperty('apiModules');
|
|
300
|
+
expect(result.integration.apiModules).toBeInstanceOf(Array);
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
test('preserves existing integration data', async () => {
|
|
304
|
+
const integration = Integration.create({
|
|
305
|
+
name: 'salesforce-sync',
|
|
306
|
+
type: 'sync',
|
|
307
|
+
displayName: 'Salesforce Sync',
|
|
308
|
+
description: 'Sync data with Salesforce',
|
|
309
|
+
category: 'CRM'
|
|
310
|
+
});
|
|
311
|
+
mockIntegrationRepository.integrations.set('salesforce-sync', integration);
|
|
312
|
+
|
|
313
|
+
const request = {
|
|
314
|
+
integrationName: 'salesforce-sync',
|
|
315
|
+
moduleName: 'salesforce'
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
const result = await useCase.execute(request);
|
|
319
|
+
|
|
320
|
+
expect(result.integration.name).toBe('salesforce-sync');
|
|
321
|
+
expect(result.integration.type).toBe('sync');
|
|
322
|
+
expect(result.integration.displayName).toBe('Salesforce Sync');
|
|
323
|
+
expect(result.integration.description).toBe('Sync data with Salesforce');
|
|
324
|
+
});
|
|
325
|
+
});
|
|
326
|
+
});
|
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
const {CreateApiModuleUseCase} = require('../../../application/use-cases/CreateApiModuleUseCase');
|
|
2
|
+
const {ApiModule} = require('../../../domain/entities/ApiModule');
|
|
3
|
+
const {DomainException, ValidationException} = require('../../../domain/exceptions/DomainException');
|
|
4
|
+
|
|
5
|
+
// Mock dependencies
|
|
6
|
+
class MockApiModuleRepository {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.modules = new Map();
|
|
9
|
+
this.saveCalled = false;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async save(apiModule) {
|
|
13
|
+
this.saveCalled = true;
|
|
14
|
+
this.modules.set(apiModule.name, apiModule);
|
|
15
|
+
return apiModule;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async findByName(name) {
|
|
19
|
+
return this.modules.get(name) || null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async exists(name) {
|
|
23
|
+
return this.modules.has(name);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async list() {
|
|
27
|
+
return Array.from(this.modules.values());
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
class MockAppDefinitionRepository {
|
|
32
|
+
constructor() {
|
|
33
|
+
this.appDef = null;
|
|
34
|
+
this.loadCalled = false;
|
|
35
|
+
this.saveCalled = false;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async load() {
|
|
39
|
+
this.loadCalled = true;
|
|
40
|
+
return this.appDef;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async save(appDef) {
|
|
44
|
+
this.saveCalled = true;
|
|
45
|
+
this.appDef = appDef;
|
|
46
|
+
return appDef;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async exists() {
|
|
50
|
+
return this.appDef !== null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
class MockUnitOfWork {
|
|
55
|
+
constructor() {
|
|
56
|
+
this.committed = false;
|
|
57
|
+
this.rolledBack = false;
|
|
58
|
+
this.operations = [];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
addOperation(operation) {
|
|
62
|
+
this.operations.push(operation);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async commit() {
|
|
66
|
+
this.committed = true;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async rollback() {
|
|
70
|
+
this.rolledBack = true;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
describe('CreateApiModuleUseCase', () => {
|
|
75
|
+
let useCase;
|
|
76
|
+
let mockApiModuleRepository;
|
|
77
|
+
let mockAppDefinitionRepository;
|
|
78
|
+
let mockUnitOfWork;
|
|
79
|
+
|
|
80
|
+
beforeEach(() => {
|
|
81
|
+
mockApiModuleRepository = new MockApiModuleRepository();
|
|
82
|
+
mockAppDefinitionRepository = new MockAppDefinitionRepository();
|
|
83
|
+
mockUnitOfWork = new MockUnitOfWork();
|
|
84
|
+
|
|
85
|
+
useCase = new CreateApiModuleUseCase(
|
|
86
|
+
mockApiModuleRepository,
|
|
87
|
+
mockUnitOfWork,
|
|
88
|
+
mockAppDefinitionRepository
|
|
89
|
+
);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
describe('execute()', () => {
|
|
93
|
+
test('successfully creates a new API module with required fields', async () => {
|
|
94
|
+
const request = {
|
|
95
|
+
name: 'salesforce',
|
|
96
|
+
displayName: 'Salesforce',
|
|
97
|
+
description: 'Salesforce CRM API',
|
|
98
|
+
baseUrl: 'https://api.salesforce.com',
|
|
99
|
+
authType: 'oauth2',
|
|
100
|
+
apiVersion: 'v1'
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const result = await useCase.execute(request);
|
|
104
|
+
|
|
105
|
+
expect(result.success).toBe(true);
|
|
106
|
+
expect(result.apiModule.name).toBe('salesforce');
|
|
107
|
+
expect(result.apiModule.displayName).toBe('Salesforce');
|
|
108
|
+
expect(mockApiModuleRepository.saveCalled).toBe(true);
|
|
109
|
+
expect(mockUnitOfWork.committed).toBe(true);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test('creates module with minimal required fields', async () => {
|
|
113
|
+
const request = {
|
|
114
|
+
name: 'stripe-api',
|
|
115
|
+
authType: 'api-key'
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const result = await useCase.execute(request);
|
|
119
|
+
|
|
120
|
+
expect(result.success).toBe(true);
|
|
121
|
+
expect(result.apiModule.name).toBe('stripe-api');
|
|
122
|
+
expect(result.apiModule.displayName).toBe('Stripe Api');
|
|
123
|
+
expect(result.apiModule.apiConfig.authType).toBe('api-key');
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
test('creates module with entities', async () => {
|
|
127
|
+
const request = {
|
|
128
|
+
name: 'salesforce',
|
|
129
|
+
authType: 'oauth2',
|
|
130
|
+
entities: {
|
|
131
|
+
account: {
|
|
132
|
+
label: 'Salesforce Account',
|
|
133
|
+
required: true,
|
|
134
|
+
fields: ['id', 'name']
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
const result = await useCase.execute(request);
|
|
140
|
+
|
|
141
|
+
expect(result.success).toBe(true);
|
|
142
|
+
expect(result.apiModule.entities).toHaveProperty('account');
|
|
143
|
+
expect(result.apiModule.entities.account.label).toBe('Salesforce Account');
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test('creates module with OAuth scopes', async () => {
|
|
147
|
+
const request = {
|
|
148
|
+
name: 'salesforce',
|
|
149
|
+
authType: 'oauth2',
|
|
150
|
+
scopes: ['read:accounts', 'write:accounts']
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
const result = await useCase.execute(request);
|
|
154
|
+
|
|
155
|
+
expect(result.success).toBe(true);
|
|
156
|
+
expect(result.apiModule.scopes).toEqual(['read:accounts', 'write:accounts']);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
test('creates module with credentials', async () => {
|
|
160
|
+
const request = {
|
|
161
|
+
name: 'salesforce',
|
|
162
|
+
authType: 'oauth2',
|
|
163
|
+
credentials: [
|
|
164
|
+
{
|
|
165
|
+
name: 'clientId',
|
|
166
|
+
type: 'string',
|
|
167
|
+
required: true,
|
|
168
|
+
description: 'OAuth client ID'
|
|
169
|
+
}
|
|
170
|
+
]
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
const result = await useCase.execute(request);
|
|
174
|
+
|
|
175
|
+
expect(result.success).toBe(true);
|
|
176
|
+
expect(result.apiModule.credentials).toHaveLength(1);
|
|
177
|
+
expect(result.apiModule.credentials[0].name).toBe('clientId');
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
test('registers API module in app definition if available', async () => {
|
|
181
|
+
// Setup app definition
|
|
182
|
+
const AppDefinition = require('../../../domain/entities/AppDefinition').AppDefinition;
|
|
183
|
+
mockAppDefinitionRepository.appDef = AppDefinition.create({
|
|
184
|
+
name: 'test-app',
|
|
185
|
+
version: '1.0.0'
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
const request = {
|
|
189
|
+
name: 'salesforce',
|
|
190
|
+
authType: 'oauth2'
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
const result = await useCase.execute(request);
|
|
194
|
+
|
|
195
|
+
expect(result.success).toBe(true);
|
|
196
|
+
expect(mockAppDefinitionRepository.loadCalled).toBe(true);
|
|
197
|
+
expect(mockAppDefinitionRepository.saveCalled).toBe(true);
|
|
198
|
+
expect(mockAppDefinitionRepository.appDef.hasApiModule('salesforce')).toBe(true);
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
test('succeeds even if app definition does not exist', async () => {
|
|
202
|
+
mockAppDefinitionRepository.appDef = null;
|
|
203
|
+
|
|
204
|
+
const request = {
|
|
205
|
+
name: 'salesforce',
|
|
206
|
+
authType: 'oauth2'
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
const result = await useCase.execute(request);
|
|
210
|
+
|
|
211
|
+
expect(result.success).toBe(true);
|
|
212
|
+
expect(mockAppDefinitionRepository.loadCalled).toBe(true);
|
|
213
|
+
expect(mockAppDefinitionRepository.saveCalled).toBe(false);
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
test('throws validation error when name is missing', async () => {
|
|
217
|
+
const request = {
|
|
218
|
+
authType: 'oauth2'
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
await expect(useCase.execute(request)).rejects.toThrow(DomainException);
|
|
222
|
+
expect(mockUnitOfWork.rolledBack).toBe(true);
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
test('throws validation error when name is invalid', async () => {
|
|
226
|
+
const request = {
|
|
227
|
+
name: 'Invalid Name!',
|
|
228
|
+
authType: 'oauth2'
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
await expect(useCase.execute(request)).rejects.toThrow();
|
|
232
|
+
expect(mockUnitOfWork.rolledBack).toBe(true);
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
test('defaults authType to oauth2 when missing', async () => {
|
|
236
|
+
const request = {
|
|
237
|
+
name: 'salesforce'
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
const result = await useCase.execute(request);
|
|
241
|
+
|
|
242
|
+
expect(result.success).toBe(true);
|
|
243
|
+
expect(result.apiModule.apiConfig.authType).toBe('oauth2');
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
test('rollsback on repository error', async () => {
|
|
247
|
+
mockApiModuleRepository.save = async () => {
|
|
248
|
+
throw new Error('Database error');
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
const request = {
|
|
252
|
+
name: 'salesforce',
|
|
253
|
+
authType: 'oauth2'
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
await expect(useCase.execute(request)).rejects.toThrow('Database error');
|
|
257
|
+
expect(mockUnitOfWork.rolledBack).toBe(true);
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
test('succeeds even if app definition registration fails', async () => {
|
|
261
|
+
// Setup app definition that will fail
|
|
262
|
+
const AppDefinition = require('../../../domain/entities/AppDefinition').AppDefinition;
|
|
263
|
+
mockAppDefinitionRepository.appDef = AppDefinition.create({
|
|
264
|
+
name: 'test-app',
|
|
265
|
+
version: '1.0.0'
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
// Make save throw error
|
|
269
|
+
const consoleSpy = jest.spyOn(console, 'warn').mockImplementation();
|
|
270
|
+
mockAppDefinitionRepository.save = async () => {
|
|
271
|
+
throw new Error('Failed to update app definition');
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
const request = {
|
|
275
|
+
name: 'salesforce',
|
|
276
|
+
authType: 'oauth2'
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
const result = await useCase.execute(request);
|
|
280
|
+
|
|
281
|
+
expect(result.success).toBe(true);
|
|
282
|
+
expect(consoleSpy).toHaveBeenCalledWith(
|
|
283
|
+
expect.stringContaining('Could not register API module'),
|
|
284
|
+
expect.any(String)
|
|
285
|
+
);
|
|
286
|
+
expect(mockUnitOfWork.committed).toBe(true);
|
|
287
|
+
expect(mockUnitOfWork.rolledBack).toBe(false);
|
|
288
|
+
|
|
289
|
+
consoleSpy.mockRestore();
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
test('commits transaction only after all operations succeed', async () => {
|
|
293
|
+
const AppDefinition = require('../../../domain/entities/AppDefinition').AppDefinition;
|
|
294
|
+
mockAppDefinitionRepository.appDef = AppDefinition.create({
|
|
295
|
+
name: 'test-app',
|
|
296
|
+
version: '1.0.0'
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
const request = {
|
|
300
|
+
name: 'salesforce',
|
|
301
|
+
authType: 'oauth2'
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
const result = await useCase.execute(request);
|
|
305
|
+
|
|
306
|
+
expect(result.success).toBe(true);
|
|
307
|
+
expect(mockApiModuleRepository.saveCalled).toBe(true);
|
|
308
|
+
expect(mockAppDefinitionRepository.saveCalled).toBe(true);
|
|
309
|
+
expect(mockUnitOfWork.committed).toBe(true);
|
|
310
|
+
expect(mockUnitOfWork.rolledBack).toBe(false);
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
test('returns full API module object', async () => {
|
|
314
|
+
const request = {
|
|
315
|
+
name: 'salesforce',
|
|
316
|
+
displayName: 'Salesforce',
|
|
317
|
+
description: 'Salesforce CRM API',
|
|
318
|
+
authType: 'oauth2',
|
|
319
|
+
baseUrl: 'https://api.salesforce.com',
|
|
320
|
+
version: '2.0.0'
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
const result = await useCase.execute(request);
|
|
324
|
+
|
|
325
|
+
expect(result.apiModule).toHaveProperty('name');
|
|
326
|
+
expect(result.apiModule).toHaveProperty('version');
|
|
327
|
+
expect(result.apiModule).toHaveProperty('displayName');
|
|
328
|
+
expect(result.apiModule).toHaveProperty('description');
|
|
329
|
+
expect(result.apiModule).toHaveProperty('apiConfig');
|
|
330
|
+
expect(result.apiModule).toHaveProperty('entities');
|
|
331
|
+
expect(result.apiModule).toHaveProperty('scopes');
|
|
332
|
+
expect(result.apiModule).toHaveProperty('credentials');
|
|
333
|
+
expect(result.apiModule).toHaveProperty('createdAt');
|
|
334
|
+
expect(result.apiModule).toHaveProperty('updatedAt');
|
|
335
|
+
});
|
|
336
|
+
});
|
|
337
|
+
});
|