@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,583 +0,0 @@
1
- const {FileSystemApiModuleRepository} = require('../../../infrastructure/repositories/FileSystemApiModuleRepository');
2
- const {ApiModule} = require('../../../domain/entities/ApiModule');
3
-
4
- describe('FileSystemApiModuleRepository', () => {
5
- let repository;
6
- let mockFileSystemAdapter;
7
- let mockSchemaValidator;
8
- let projectRoot;
9
-
10
- beforeEach(() => {
11
- projectRoot = '/test/project';
12
-
13
- mockFileSystemAdapter = {
14
- exists: jest.fn(),
15
- ensureDirectory: jest.fn(),
16
- writeFile: jest.fn(),
17
- readFile: jest.fn(),
18
- listDirectories: jest.fn(),
19
- deleteDirectory: jest.fn(),
20
- };
21
-
22
- mockSchemaValidator = {
23
- validate: jest.fn(),
24
- };
25
-
26
- repository = new FileSystemApiModuleRepository(
27
- mockFileSystemAdapter,
28
- projectRoot,
29
- mockSchemaValidator
30
- );
31
- });
32
-
33
- describe('save', () => {
34
- it('should save an API module with all required files', async () => {
35
- const apiModule = ApiModule.create({
36
- name: 'salesforce',
37
- version: '1.0.0',
38
- displayName: 'Salesforce',
39
- description: 'Salesforce API',
40
- apiConfig: {
41
- authType: 'oauth2',
42
- baseUrl: 'https://api.salesforce.com',
43
- },
44
- });
45
-
46
- await repository.save(apiModule);
47
-
48
- // Verify directories created
49
- expect(mockFileSystemAdapter.ensureDirectory).toHaveBeenCalledWith(
50
- '/test/project/backend/src/api-modules/salesforce'
51
- );
52
- expect(mockFileSystemAdapter.ensureDirectory).toHaveBeenCalledWith(
53
- '/test/project/backend/src/api-modules/salesforce/tests'
54
- );
55
-
56
- // Verify files written (4 files without Entity.js)
57
- expect(mockFileSystemAdapter.writeFile).toHaveBeenCalledTimes(4);
58
- });
59
-
60
- it('should generate Entity.js if module has entities', async () => {
61
- const apiModule = ApiModule.create({
62
- name: 'salesforce',
63
- version: '1.0.0',
64
- displayName: 'Salesforce',
65
- apiConfig: {
66
- authType: 'oauth2',
67
- },
68
- });
69
-
70
- apiModule.addEntity('credential', {
71
- label: 'Credential',
72
- type: 'credential',
73
- required: true,
74
- fields: ['accessToken', 'refreshToken'],
75
- });
76
-
77
- await repository.save(apiModule);
78
-
79
- // Verify Entity.js written (5 files with Entity.js)
80
- expect(mockFileSystemAdapter.writeFile).toHaveBeenCalledTimes(5);
81
-
82
- const entityCall = mockFileSystemAdapter.writeFile.mock.calls.find(
83
- call => call[0].endsWith('Entity.js')
84
- );
85
- expect(entityCall).toBeDefined();
86
- expect(entityCall[1]).toContain('class SalesforceEntity extends EntityBase');
87
- });
88
-
89
- it('should generate Api.js class file correctly', async () => {
90
- const apiModule = ApiModule.create({
91
- name: 'my-test-api',
92
- version: '1.0.0',
93
- displayName: 'My Test API',
94
- description: 'Test API description',
95
- apiConfig: {
96
- authType: 'oauth2',
97
- baseUrl: 'https://api.test.com',
98
- },
99
- });
100
-
101
- await repository.save(apiModule);
102
-
103
- const apiCall = mockFileSystemAdapter.writeFile.mock.calls.find(
104
- call => call[0].endsWith('Api.js')
105
- );
106
-
107
- expect(apiCall).toBeDefined();
108
- expect(apiCall[1]).toContain('class MyTestApiApi extends ApiBase');
109
- expect(apiCall[1]).toContain("this.baseUrl = 'https://api.test.com'");
110
- expect(apiCall[1]).toContain("this.authType = 'oauth2'");
111
- expect(apiCall[1]).toContain('module.exports = MyTestApiApi');
112
- });
113
-
114
- it('should generate definition.js file correctly', async () => {
115
- const apiModule = ApiModule.create({
116
- name: 'salesforce',
117
- version: '1.0.0',
118
- displayName: 'Salesforce',
119
- apiConfig: {
120
- authType: 'oauth2',
121
- },
122
- });
123
-
124
- await repository.save(apiModule);
125
-
126
- const definitionCall = mockFileSystemAdapter.writeFile.mock.calls.find(
127
- call => call[0].endsWith('definition.js')
128
- );
129
-
130
- expect(definitionCall).toBeDefined();
131
- expect(definitionCall[1]).toContain('module.exports = {');
132
- expect(definitionCall[1]).toContain('"name": "salesforce"');
133
- });
134
-
135
- it('should generate config.json file correctly', async () => {
136
- const apiModule = ApiModule.create({
137
- name: 'salesforce',
138
- version: '1.0.0',
139
- displayName: 'Salesforce',
140
- apiConfig: {
141
- authType: 'oauth2',
142
- },
143
- });
144
-
145
- await repository.save(apiModule);
146
-
147
- const configCall = mockFileSystemAdapter.writeFile.mock.calls.find(
148
- call => call[0].endsWith('config.json')
149
- );
150
-
151
- expect(configCall).toBeDefined();
152
- const config = JSON.parse(configCall[1]);
153
- expect(config.name).toBe('salesforce');
154
- expect(config.version).toBe('1.0.0');
155
- expect(config.authType).toBe('oauth2');
156
- });
157
-
158
- it('should generate README.md file correctly', async () => {
159
- const apiModule = ApiModule.create({
160
- name: 'salesforce',
161
- version: '1.0.0',
162
- displayName: 'Salesforce',
163
- description: 'Salesforce API client',
164
- apiConfig: {
165
- authType: 'oauth2',
166
- baseUrl: 'https://api.salesforce.com',
167
- },
168
- });
169
-
170
- await repository.save(apiModule);
171
-
172
- const readmeCall = mockFileSystemAdapter.writeFile.mock.calls.find(
173
- call => call[0].endsWith('README.md')
174
- );
175
-
176
- expect(readmeCall).toBeDefined();
177
- expect(readmeCall[1]).toContain('# Salesforce');
178
- expect(readmeCall[1]).toContain('Salesforce API client');
179
- expect(readmeCall[1]).toContain('https://api.salesforce.com');
180
- });
181
-
182
- it('should throw error if API module validation fails', async () => {
183
- const apiModule = ApiModule.create({
184
- name: 'test-api',
185
- version: '1.0.0',
186
- displayName: 'Test API',
187
- apiConfig: {
188
- authType: 'oauth2',
189
- },
190
- });
191
-
192
- // Mock validate to return errors
193
- jest.spyOn(apiModule, 'validate').mockReturnValue({
194
- isValid: false,
195
- errors: ['Invalid configuration'],
196
- });
197
-
198
- await expect(repository.save(apiModule)).rejects.toThrow(
199
- 'ApiModule validation failed'
200
- );
201
- });
202
-
203
- it('should handle endpoints in Api.js generation', async () => {
204
- const apiModule = ApiModule.create({
205
- name: 'salesforce',
206
- version: '1.0.0',
207
- displayName: 'Salesforce',
208
- apiConfig: {
209
- authType: 'oauth2',
210
- },
211
- });
212
-
213
- apiModule.addEndpoint('getUser', {
214
- method: 'GET',
215
- path: '/user',
216
- description: 'Get user information',
217
- });
218
-
219
- await repository.save(apiModule);
220
-
221
- const apiCall = mockFileSystemAdapter.writeFile.mock.calls.find(
222
- call => call[0].endsWith('Api.js')
223
- );
224
-
225
- expect(apiCall[1]).toContain('async getUser()');
226
- expect(apiCall[1]).toContain('return await this.get(\'/user\')');
227
- });
228
-
229
- it('should handle OAuth scopes in README', async () => {
230
- const apiModule = ApiModule.create({
231
- name: 'salesforce',
232
- version: '1.0.0',
233
- displayName: 'Salesforce',
234
- apiConfig: {
235
- authType: 'oauth2',
236
- },
237
- });
238
-
239
- apiModule.addScope('read:users');
240
- apiModule.addScope('write:users');
241
-
242
- await repository.save(apiModule);
243
-
244
- const readmeCall = mockFileSystemAdapter.writeFile.mock.calls.find(
245
- call => call[0].endsWith('README.md')
246
- );
247
-
248
- expect(readmeCall[1]).toContain('read:users');
249
- expect(readmeCall[1]).toContain('write:users');
250
- });
251
-
252
- it('should handle credentials in README', async () => {
253
- const apiModule = ApiModule.create({
254
- name: 'salesforce',
255
- version: '1.0.0',
256
- displayName: 'Salesforce',
257
- apiConfig: {
258
- authType: 'oauth2',
259
- },
260
- });
261
-
262
- apiModule.addCredential('clientId', {
263
- type: 'string',
264
- description: 'OAuth Client ID',
265
- required: true,
266
- });
267
-
268
- await repository.save(apiModule);
269
-
270
- const readmeCall = mockFileSystemAdapter.writeFile.mock.calls.find(
271
- call => call[0].endsWith('README.md')
272
- );
273
-
274
- expect(readmeCall[1]).toContain('clientId');
275
- expect(readmeCall[1]).toContain('OAuth Client ID');
276
- expect(readmeCall[1]).toContain('(Required)');
277
- });
278
- });
279
-
280
- describe('findByName', () => {
281
- it.skip('should find API module by name (TODO: needs full implementation)', async () => {
282
- // Skip this test because findByName is a simple implementation that
283
- // calls ApiModule.create({name}) which requires apiConfig.
284
- // Full implementation would parse the definition.js file.
285
- mockFileSystemAdapter.exists.mockResolvedValue(true);
286
- mockFileSystemAdapter.readFile.mockResolvedValue('module.exports = {}');
287
-
288
- const result = await repository.findByName('salesforce');
289
-
290
- expect(result).toBeInstanceOf(ApiModule);
291
- expect(result.name).toBe('salesforce');
292
- });
293
-
294
- it('should return null if module directory does not exist', async () => {
295
- mockFileSystemAdapter.exists.mockResolvedValueOnce(false);
296
-
297
- const result = await repository.findByName('nonexistent');
298
-
299
- expect(result).toBeNull();
300
- });
301
-
302
- it('should return null if definition file does not exist', async () => {
303
- mockFileSystemAdapter.exists
304
- .mockResolvedValueOnce(true) // Directory exists
305
- .mockResolvedValueOnce(false); // Definition file doesn't exist
306
-
307
- const result = await repository.findByName('salesforce');
308
-
309
- expect(result).toBeNull();
310
- });
311
- });
312
-
313
- describe('exists', () => {
314
- it('should return true if API module exists', async () => {
315
- mockFileSystemAdapter.exists.mockResolvedValue(true);
316
-
317
- const result = await repository.exists('salesforce');
318
-
319
- expect(result).toBe(true);
320
- expect(mockFileSystemAdapter.exists).toHaveBeenCalledWith(
321
- '/test/project/backend/src/api-modules/salesforce'
322
- );
323
- });
324
-
325
- it('should return false if API module does not exist', async () => {
326
- mockFileSystemAdapter.exists.mockResolvedValue(false);
327
-
328
- const result = await repository.exists('nonexistent');
329
-
330
- expect(result).toBe(false);
331
- });
332
- });
333
-
334
- describe('list', () => {
335
- it('should return empty array if api-modules directory does not exist', async () => {
336
- mockFileSystemAdapter.exists.mockResolvedValue(false);
337
-
338
- const result = await repository.list();
339
-
340
- expect(result).toEqual([]);
341
- });
342
-
343
- it.skip('should list all API modules (TODO: needs full findByName implementation)', async () => {
344
- // Skip because list() uses findByName() which needs full implementation
345
- mockFileSystemAdapter.exists.mockResolvedValue(true);
346
- mockFileSystemAdapter.listDirectories.mockResolvedValue([
347
- 'salesforce',
348
- 'stripe',
349
- ]);
350
- mockFileSystemAdapter.readFile.mockResolvedValue('module.exports = {}');
351
-
352
- const result = await repository.list();
353
-
354
- expect(result).toHaveLength(2);
355
- expect(result[0]).toBeInstanceOf(ApiModule);
356
- expect(result[0].name).toBe('salesforce');
357
- expect(result[1].name).toBe('stripe');
358
- });
359
-
360
- it('should skip invalid modules and log warning', async () => {
361
- const consoleWarnSpy = jest.spyOn(console, 'warn').mockImplementation();
362
-
363
- mockFileSystemAdapter.exists
364
- .mockResolvedValueOnce(true) // Directory exists
365
- .mockResolvedValueOnce(true) // salesforce dir
366
- .mockResolvedValueOnce(true) // salesforce definition
367
- .mockResolvedValueOnce(false); // invalid dir (doesn't exist)
368
-
369
- mockFileSystemAdapter.listDirectories.mockResolvedValue([
370
- 'salesforce',
371
- 'invalid',
372
- ]);
373
- mockFileSystemAdapter.readFile.mockResolvedValue('module.exports = {}');
374
-
375
- const result = await repository.list();
376
-
377
- // Result will be empty because findByName throws errors
378
- expect(result).toEqual([]);
379
- expect(consoleWarnSpy).toHaveBeenCalledWith(
380
- expect.stringContaining('Failed to load API module'),
381
- expect.any(String)
382
- );
383
-
384
- consoleWarnSpy.mockRestore();
385
- });
386
- });
387
-
388
- describe('delete', () => {
389
- it('should delete API module if it exists', async () => {
390
- mockFileSystemAdapter.exists.mockResolvedValue(true);
391
-
392
- const result = await repository.delete('salesforce');
393
-
394
- expect(result).toBe(true);
395
- expect(mockFileSystemAdapter.deleteDirectory).toHaveBeenCalledWith(
396
- '/test/project/backend/src/api-modules/salesforce'
397
- );
398
- });
399
-
400
- it('should return false if API module does not exist', async () => {
401
- mockFileSystemAdapter.exists.mockResolvedValue(false);
402
-
403
- const result = await repository.delete('nonexistent');
404
-
405
- expect(result).toBe(false);
406
- expect(mockFileSystemAdapter.deleteDirectory).not.toHaveBeenCalled();
407
- });
408
- });
409
-
410
- describe('_generateApiClass', () => {
411
- it('should generate API class with OAuth methods', () => {
412
- const apiModule = ApiModule.create({
413
- name: 'salesforce',
414
- version: '1.0.0',
415
- displayName: 'Salesforce',
416
- apiConfig: {
417
- authType: 'oauth2',
418
- baseUrl: 'https://api.salesforce.com',
419
- },
420
- });
421
-
422
- const result = repository._generateApiClass(apiModule);
423
-
424
- expect(result).toContain('class SalesforceApi extends ApiBase');
425
- expect(result).toContain('async getAuthorizationUri()');
426
- expect(result).toContain('async getTokenFromCode(code)');
427
- expect(result).toContain('async setCredential(credential)');
428
- expect(result).toContain('async testAuth()');
429
- });
430
-
431
- it('should handle kebab-case module names', () => {
432
- const apiModule = ApiModule.create({
433
- name: 'my-api-module',
434
- version: '1.0.0',
435
- displayName: 'My API Module',
436
- apiConfig: {
437
- authType: 'api-key',
438
- },
439
- });
440
-
441
- const result = repository._generateApiClass(apiModule);
442
-
443
- expect(result).toContain('class MyApiModuleApi extends ApiBase');
444
- expect(result).toContain('module.exports = MyApiModuleApi');
445
- });
446
-
447
- it('should include credential parameter if entity exists', () => {
448
- const apiModule = ApiModule.create({
449
- name: 'salesforce',
450
- version: '1.0.0',
451
- displayName: 'Salesforce',
452
- apiConfig: {
453
- authType: 'oauth2',
454
- },
455
- });
456
-
457
- apiModule.addEntity('credential', {
458
- label: 'Credential',
459
- type: 'credential',
460
- required: true,
461
- });
462
-
463
- const result = repository._generateApiClass(apiModule);
464
-
465
- expect(result).toContain('this.credential = params.credential');
466
- });
467
- });
468
-
469
- describe('_generateEndpointMethods', () => {
470
- it('should generate methods for each endpoint', () => {
471
- const apiModule = ApiModule.create({
472
- name: 'salesforce',
473
- version: '1.0.0',
474
- displayName: 'Salesforce',
475
- apiConfig: {
476
- authType: 'oauth2',
477
- },
478
- });
479
-
480
- apiModule.addEndpoint('getUser', {
481
- method: 'GET',
482
- path: '/user',
483
- description: 'Get user information',
484
- });
485
-
486
- apiModule.addEndpoint('createContact', {
487
- method: 'POST',
488
- path: '/contacts',
489
- description: 'Create a contact',
490
- parameters: [{name: 'data'}],
491
- });
492
-
493
- const result = repository._generateEndpointMethods(apiModule);
494
-
495
- expect(result).toContain('async getUser()');
496
- expect(result).toContain("return await this.get('/user')");
497
- expect(result).toContain('async createContact(data)');
498
- expect(result).toContain("return await this.post('/contacts', {data})");
499
- });
500
-
501
- it('should return empty string if no endpoints', () => {
502
- const apiModule = ApiModule.create({
503
- name: 'salesforce',
504
- version: '1.0.0',
505
- displayName: 'Salesforce',
506
- apiConfig: {
507
- authType: 'oauth2',
508
- },
509
- });
510
-
511
- const result = repository._generateEndpointMethods(apiModule);
512
-
513
- expect(result).toBe('');
514
- });
515
- });
516
-
517
- describe('_generateEntityClass', () => {
518
- it('should generate Entity class correctly', () => {
519
- const apiModule = ApiModule.create({
520
- name: 'salesforce',
521
- version: '1.0.0',
522
- displayName: 'Salesforce',
523
- apiConfig: {
524
- authType: 'oauth2',
525
- },
526
- });
527
-
528
- apiModule.addEntity('credential', {
529
- label: 'Credential',
530
- type: 'credential',
531
- required: true,
532
- fields: ['accessToken', 'refreshToken'],
533
- });
534
-
535
- const result = repository._generateEntityClass(apiModule);
536
-
537
- expect(result).toContain('class SalesforceEntity extends EntityBase');
538
- expect(result).toContain("return 'credential'");
539
- expect(result).toContain('accessToken');
540
- expect(result).toContain('refreshToken');
541
- expect(result).toContain('module.exports = SalesforceEntity');
542
- });
543
- });
544
-
545
- describe('_generateReadme', () => {
546
- it('should generate comprehensive README', () => {
547
- const apiModule = ApiModule.create({
548
- name: 'salesforce',
549
- version: '1.0.0',
550
- displayName: 'Salesforce',
551
- description: 'Salesforce API client',
552
- apiConfig: {
553
- authType: 'oauth2',
554
- baseUrl: 'https://api.salesforce.com',
555
- },
556
- });
557
-
558
- apiModule.addScope('read:users');
559
- apiModule.addCredential('clientId', {
560
- type: 'string',
561
- description: 'OAuth Client ID',
562
- required: true,
563
- });
564
- apiModule.addEntity('credential', {
565
- label: 'Credential',
566
- type: 'credential',
567
- required: true,
568
- });
569
-
570
- const result = repository._generateReadme(apiModule);
571
-
572
- expect(result).toContain('# Salesforce');
573
- expect(result).toContain('Salesforce API client');
574
- expect(result).toContain('https://api.salesforce.com');
575
- expect(result).toContain('oauth2');
576
- expect(result).toContain('read:users');
577
- expect(result).toContain('clientId');
578
- expect(result).toContain('OAuth Client ID');
579
- expect(result).toContain('## Usage');
580
- expect(result).toContain('## Development');
581
- });
582
- });
583
- });