@friggframework/devtools 2.0.0--canary.545.e256e95.0 → 2.0.0--canary.553.dc5f898.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.
Files changed (129) hide show
  1. package/frigg-cli/README.md +1 -1
  2. package/frigg-cli/__tests__/unit/commands/build.test.js +1 -1
  3. package/frigg-cli/__tests__/unit/commands/doctor.test.js +2 -0
  4. package/frigg-cli/__tests__/unit/commands/install.test.js +19 -23
  5. package/frigg-cli/__tests__/unit/dependencies.test.js +2 -2
  6. package/frigg-cli/build-command/index.js +11 -123
  7. package/frigg-cli/deploy-command/index.js +1 -83
  8. package/frigg-cli/doctor-command/index.js +16 -37
  9. package/frigg-cli/generate-iam-command.js +1 -21
  10. package/frigg-cli/index.js +6 -21
  11. package/frigg-cli/index.test.js +2 -7
  12. package/frigg-cli/init-command/backend-first-handler.js +42 -124
  13. package/frigg-cli/init-command/index.js +1 -2
  14. package/frigg-cli/init-command/template-handler.js +3 -13
  15. package/frigg-cli/install-command/backend-js.js +3 -3
  16. package/frigg-cli/install-command/environment-variables.js +19 -16
  17. package/frigg-cli/install-command/environment-variables.test.js +13 -12
  18. package/frigg-cli/install-command/index.js +9 -14
  19. package/frigg-cli/install-command/integration-file.js +3 -3
  20. package/frigg-cli/install-command/logger.js +12 -0
  21. package/frigg-cli/install-command/validate-package.js +9 -5
  22. package/frigg-cli/jest.config.js +1 -4
  23. package/frigg-cli/repair-command/index.js +128 -121
  24. package/frigg-cli/start-command/index.js +2 -324
  25. package/frigg-cli/ui-command/index.js +36 -58
  26. package/frigg-cli/utils/repo-detection.js +37 -85
  27. package/infrastructure/create-frigg-infrastructure.js +0 -93
  28. package/infrastructure/docs/iam-policy-templates.md +1 -1
  29. package/infrastructure/domains/integration/integration-builder.js +3 -2
  30. package/infrastructure/domains/integration/integration-builder.test.js +54 -2
  31. package/infrastructure/domains/networking/vpc-builder.test.js +4 -2
  32. package/infrastructure/domains/networking/vpc-resolver.test.js +1 -1
  33. package/infrastructure/domains/shared/resource-discovery.js +5 -5
  34. package/infrastructure/domains/shared/types/app-definition.js +0 -35
  35. package/infrastructure/domains/shared/types/discovery-result.test.js +1 -1
  36. package/infrastructure/domains/shared/utilities/base-definition-factory.js +1 -10
  37. package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +2 -2
  38. package/infrastructure/infrastructure-composer.js +0 -2
  39. package/infrastructure/infrastructure-composer.test.js +6 -5
  40. package/management-ui/README.md +109 -245
  41. package/package.json +7 -8
  42. package/frigg-cli/__tests__/application/use-cases/AddApiModuleToIntegrationUseCase.test.js +0 -326
  43. package/frigg-cli/__tests__/application/use-cases/CreateApiModuleUseCase.test.js +0 -337
  44. package/frigg-cli/__tests__/domain/entities/ApiModule.test.js +0 -373
  45. package/frigg-cli/__tests__/domain/entities/AppDefinition.test.js +0 -313
  46. package/frigg-cli/__tests__/domain/services/IntegrationValidator.test.js +0 -269
  47. package/frigg-cli/__tests__/domain/value-objects/IntegrationName.test.js +0 -82
  48. package/frigg-cli/__tests__/infrastructure/adapters/IntegrationJsUpdater.test.js +0 -408
  49. package/frigg-cli/__tests__/infrastructure/repositories/FileSystemApiModuleRepository.test.js +0 -583
  50. package/frigg-cli/__tests__/infrastructure/repositories/FileSystemAppDefinitionRepository.test.js +0 -314
  51. package/frigg-cli/__tests__/infrastructure/repositories/FileSystemIntegrationRepository.test.js +0 -383
  52. package/frigg-cli/__tests__/unit/commands/init.test.js +0 -406
  53. package/frigg-cli/__tests__/unit/commands/provider-dispatch.test.js +0 -383
  54. package/frigg-cli/__tests__/unit/commands/repair.test.js +0 -275
  55. package/frigg-cli/__tests__/unit/start-command/application/RunPreflightChecksUseCase.test.js +0 -411
  56. package/frigg-cli/__tests__/unit/start-command/infrastructure/DatabaseAdapter.test.js +0 -405
  57. package/frigg-cli/__tests__/unit/start-command/infrastructure/DockerAdapter.test.js +0 -496
  58. package/frigg-cli/__tests__/unit/start-command/presentation/InteractivePromptAdapter.test.js +0 -474
  59. package/frigg-cli/__tests__/unit/utils/output.test.js +0 -196
  60. package/frigg-cli/application/use-cases/AddApiModuleToIntegrationUseCase.js +0 -93
  61. package/frigg-cli/application/use-cases/CreateApiModuleUseCase.js +0 -93
  62. package/frigg-cli/application/use-cases/CreateIntegrationUseCase.js +0 -103
  63. package/frigg-cli/container.js +0 -172
  64. package/frigg-cli/docs/OUTPUT_MIGRATION_GUIDE.md +0 -286
  65. package/frigg-cli/domain/entities/ApiModule.js +0 -272
  66. package/frigg-cli/domain/entities/AppDefinition.js +0 -227
  67. package/frigg-cli/domain/entities/Integration.js +0 -198
  68. package/frigg-cli/domain/exceptions/DomainException.js +0 -24
  69. package/frigg-cli/domain/ports/IApiModuleRepository.js +0 -53
  70. package/frigg-cli/domain/ports/IAppDefinitionRepository.js +0 -43
  71. package/frigg-cli/domain/ports/IIntegrationRepository.js +0 -61
  72. package/frigg-cli/domain/services/IntegrationValidator.js +0 -185
  73. package/frigg-cli/domain/value-objects/IntegrationId.js +0 -42
  74. package/frigg-cli/domain/value-objects/IntegrationName.js +0 -60
  75. package/frigg-cli/domain/value-objects/SemanticVersion.js +0 -70
  76. package/frigg-cli/infrastructure/UnitOfWork.js +0 -46
  77. package/frigg-cli/infrastructure/adapters/BackendJsUpdater.js +0 -197
  78. package/frigg-cli/infrastructure/adapters/FileSystemAdapter.js +0 -224
  79. package/frigg-cli/infrastructure/adapters/IntegrationJsUpdater.js +0 -249
  80. package/frigg-cli/infrastructure/adapters/SchemaValidator.js +0 -92
  81. package/frigg-cli/infrastructure/repositories/FileSystemApiModuleRepository.js +0 -373
  82. package/frigg-cli/infrastructure/repositories/FileSystemAppDefinitionRepository.js +0 -116
  83. package/frigg-cli/infrastructure/repositories/FileSystemIntegrationRepository.js +0 -277
  84. package/frigg-cli/package-lock.json +0 -16226
  85. package/frigg-cli/start-command/application/RunPreflightChecksUseCase.js +0 -376
  86. package/frigg-cli/start-command/infrastructure/DatabaseAdapter.js +0 -591
  87. package/frigg-cli/start-command/infrastructure/DockerAdapter.js +0 -306
  88. package/frigg-cli/start-command/presentation/InteractivePromptAdapter.js +0 -329
  89. package/frigg-cli/templates/backend/.env.example +0 -62
  90. package/frigg-cli/templates/backend/.eslintrc.json +0 -12
  91. package/frigg-cli/templates/backend/.prettierrc +0 -6
  92. package/frigg-cli/templates/backend/docker-compose.yml +0 -22
  93. package/frigg-cli/templates/backend/index.js +0 -96
  94. package/frigg-cli/templates/backend/infrastructure.js +0 -12
  95. package/frigg-cli/templates/backend/jest.config.js +0 -17
  96. package/frigg-cli/templates/backend/package.json +0 -50
  97. package/frigg-cli/templates/backend/src/api-modules/.gitkeep +0 -10
  98. package/frigg-cli/templates/backend/src/base/.gitkeep +0 -7
  99. package/frigg-cli/templates/backend/src/integrations/.gitkeep +0 -10
  100. package/frigg-cli/templates/backend/src/integrations/ExampleIntegration.js +0 -65
  101. package/frigg-cli/templates/backend/src/utils/.gitkeep +0 -7
  102. package/frigg-cli/templates/backend/test/setup.js +0 -30
  103. package/frigg-cli/templates/backend/ui-extensions/.gitkeep +0 -0
  104. package/frigg-cli/templates/backend/ui-extensions/README.md +0 -77
  105. package/frigg-cli/utils/__tests__/provider-helper.test.js +0 -55
  106. package/frigg-cli/utils/__tests__/repo-detection.test.js +0 -436
  107. package/frigg-cli/utils/output.js +0 -382
  108. package/frigg-cli/utils/provider-helper.js +0 -75
  109. package/frigg-cli/validate-command/__tests__/adapters/validate-command.test.js +0 -205
  110. package/frigg-cli/validate-command/__tests__/application/validate-app-use-case.test.js +0 -104
  111. package/frigg-cli/validate-command/__tests__/domain/fix-suggestion.test.js +0 -153
  112. package/frigg-cli/validate-command/__tests__/domain/validation-error.test.js +0 -162
  113. package/frigg-cli/validate-command/__tests__/domain/validation-result.test.js +0 -152
  114. package/frigg-cli/validate-command/__tests__/infrastructure/api-module-validator.test.js +0 -332
  115. package/frigg-cli/validate-command/__tests__/infrastructure/app-definition-validator.test.js +0 -191
  116. package/frigg-cli/validate-command/__tests__/infrastructure/integration-class-validator.test.js +0 -146
  117. package/frigg-cli/validate-command/__tests__/infrastructure/template-validation.test.js +0 -155
  118. package/frigg-cli/validate-command/adapters/cli/validate-command.js +0 -199
  119. package/frigg-cli/validate-command/application/use-cases/validate-app-use-case.js +0 -35
  120. package/frigg-cli/validate-command/domain/entities/validation-result.js +0 -74
  121. package/frigg-cli/validate-command/domain/value-objects/fix-suggestion.js +0 -74
  122. package/frigg-cli/validate-command/domain/value-objects/validation-error.js +0 -68
  123. package/frigg-cli/validate-command/infrastructure/validators/api-module-validator.js +0 -181
  124. package/frigg-cli/validate-command/infrastructure/validators/app-definition-validator.js +0 -145
  125. package/frigg-cli/validate-command/infrastructure/validators/integration-class-validator.js +0 -113
  126. package/infrastructure/domains/admin-scripts/admin-script-builder.js +0 -200
  127. package/infrastructure/domains/admin-scripts/admin-script-builder.test.js +0 -499
  128. package/infrastructure/domains/admin-scripts/index.js +0 -5
  129. package/infrastructure/jest.config.js +0 -16
@@ -1,314 +0,0 @@
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
- });
@@ -1,383 +0,0 @@
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
- });