@friggframework/devtools 2.0.0--canary.545.ae2019f.0 → 2.0.0--canary.549.a579cca.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 (127) 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/networking/vpc-builder.test.js +4 -2
  30. package/infrastructure/domains/networking/vpc-resolver.test.js +1 -1
  31. package/infrastructure/domains/shared/resource-discovery.js +5 -5
  32. package/infrastructure/domains/shared/types/app-definition.js +0 -21
  33. package/infrastructure/domains/shared/types/discovery-result.test.js +1 -1
  34. package/infrastructure/domains/shared/utilities/base-definition-factory.js +1 -10
  35. package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +2 -2
  36. package/infrastructure/infrastructure-composer.js +0 -2
  37. package/infrastructure/infrastructure-composer.test.js +2 -2
  38. package/management-ui/README.md +109 -245
  39. package/package.json +7 -8
  40. package/frigg-cli/__tests__/application/use-cases/AddApiModuleToIntegrationUseCase.test.js +0 -326
  41. package/frigg-cli/__tests__/application/use-cases/CreateApiModuleUseCase.test.js +0 -337
  42. package/frigg-cli/__tests__/domain/entities/ApiModule.test.js +0 -373
  43. package/frigg-cli/__tests__/domain/entities/AppDefinition.test.js +0 -313
  44. package/frigg-cli/__tests__/domain/services/IntegrationValidator.test.js +0 -269
  45. package/frigg-cli/__tests__/domain/value-objects/IntegrationName.test.js +0 -82
  46. package/frigg-cli/__tests__/infrastructure/adapters/IntegrationJsUpdater.test.js +0 -408
  47. package/frigg-cli/__tests__/infrastructure/repositories/FileSystemApiModuleRepository.test.js +0 -583
  48. package/frigg-cli/__tests__/infrastructure/repositories/FileSystemAppDefinitionRepository.test.js +0 -314
  49. package/frigg-cli/__tests__/infrastructure/repositories/FileSystemIntegrationRepository.test.js +0 -383
  50. package/frigg-cli/__tests__/unit/commands/init.test.js +0 -406
  51. package/frigg-cli/__tests__/unit/commands/provider-dispatch.test.js +0 -383
  52. package/frigg-cli/__tests__/unit/commands/repair.test.js +0 -275
  53. package/frigg-cli/__tests__/unit/start-command/application/RunPreflightChecksUseCase.test.js +0 -411
  54. package/frigg-cli/__tests__/unit/start-command/infrastructure/DatabaseAdapter.test.js +0 -405
  55. package/frigg-cli/__tests__/unit/start-command/infrastructure/DockerAdapter.test.js +0 -496
  56. package/frigg-cli/__tests__/unit/start-command/presentation/InteractivePromptAdapter.test.js +0 -474
  57. package/frigg-cli/__tests__/unit/utils/output.test.js +0 -196
  58. package/frigg-cli/application/use-cases/AddApiModuleToIntegrationUseCase.js +0 -93
  59. package/frigg-cli/application/use-cases/CreateApiModuleUseCase.js +0 -93
  60. package/frigg-cli/application/use-cases/CreateIntegrationUseCase.js +0 -103
  61. package/frigg-cli/container.js +0 -172
  62. package/frigg-cli/docs/OUTPUT_MIGRATION_GUIDE.md +0 -286
  63. package/frigg-cli/domain/entities/ApiModule.js +0 -272
  64. package/frigg-cli/domain/entities/AppDefinition.js +0 -227
  65. package/frigg-cli/domain/entities/Integration.js +0 -198
  66. package/frigg-cli/domain/exceptions/DomainException.js +0 -24
  67. package/frigg-cli/domain/ports/IApiModuleRepository.js +0 -53
  68. package/frigg-cli/domain/ports/IAppDefinitionRepository.js +0 -43
  69. package/frigg-cli/domain/ports/IIntegrationRepository.js +0 -61
  70. package/frigg-cli/domain/services/IntegrationValidator.js +0 -185
  71. package/frigg-cli/domain/value-objects/IntegrationId.js +0 -42
  72. package/frigg-cli/domain/value-objects/IntegrationName.js +0 -60
  73. package/frigg-cli/domain/value-objects/SemanticVersion.js +0 -70
  74. package/frigg-cli/infrastructure/UnitOfWork.js +0 -46
  75. package/frigg-cli/infrastructure/adapters/BackendJsUpdater.js +0 -197
  76. package/frigg-cli/infrastructure/adapters/FileSystemAdapter.js +0 -224
  77. package/frigg-cli/infrastructure/adapters/IntegrationJsUpdater.js +0 -249
  78. package/frigg-cli/infrastructure/adapters/SchemaValidator.js +0 -92
  79. package/frigg-cli/infrastructure/repositories/FileSystemApiModuleRepository.js +0 -373
  80. package/frigg-cli/infrastructure/repositories/FileSystemAppDefinitionRepository.js +0 -116
  81. package/frigg-cli/infrastructure/repositories/FileSystemIntegrationRepository.js +0 -277
  82. package/frigg-cli/package-lock.json +0 -16226
  83. package/frigg-cli/start-command/application/RunPreflightChecksUseCase.js +0 -376
  84. package/frigg-cli/start-command/infrastructure/DatabaseAdapter.js +0 -591
  85. package/frigg-cli/start-command/infrastructure/DockerAdapter.js +0 -306
  86. package/frigg-cli/start-command/presentation/InteractivePromptAdapter.js +0 -329
  87. package/frigg-cli/templates/backend/.env.example +0 -62
  88. package/frigg-cli/templates/backend/.eslintrc.json +0 -12
  89. package/frigg-cli/templates/backend/.prettierrc +0 -6
  90. package/frigg-cli/templates/backend/docker-compose.yml +0 -22
  91. package/frigg-cli/templates/backend/index.js +0 -96
  92. package/frigg-cli/templates/backend/infrastructure.js +0 -12
  93. package/frigg-cli/templates/backend/jest.config.js +0 -17
  94. package/frigg-cli/templates/backend/package.json +0 -50
  95. package/frigg-cli/templates/backend/src/api-modules/.gitkeep +0 -10
  96. package/frigg-cli/templates/backend/src/base/.gitkeep +0 -7
  97. package/frigg-cli/templates/backend/src/integrations/.gitkeep +0 -10
  98. package/frigg-cli/templates/backend/src/integrations/ExampleIntegration.js +0 -65
  99. package/frigg-cli/templates/backend/src/utils/.gitkeep +0 -7
  100. package/frigg-cli/templates/backend/test/setup.js +0 -30
  101. package/frigg-cli/templates/backend/ui-extensions/.gitkeep +0 -0
  102. package/frigg-cli/templates/backend/ui-extensions/README.md +0 -77
  103. package/frigg-cli/utils/__tests__/provider-helper.test.js +0 -55
  104. package/frigg-cli/utils/__tests__/repo-detection.test.js +0 -436
  105. package/frigg-cli/utils/output.js +0 -382
  106. package/frigg-cli/utils/provider-helper.js +0 -75
  107. package/frigg-cli/validate-command/__tests__/adapters/validate-command.test.js +0 -205
  108. package/frigg-cli/validate-command/__tests__/application/validate-app-use-case.test.js +0 -104
  109. package/frigg-cli/validate-command/__tests__/domain/fix-suggestion.test.js +0 -153
  110. package/frigg-cli/validate-command/__tests__/domain/validation-error.test.js +0 -162
  111. package/frigg-cli/validate-command/__tests__/domain/validation-result.test.js +0 -152
  112. package/frigg-cli/validate-command/__tests__/infrastructure/api-module-validator.test.js +0 -332
  113. package/frigg-cli/validate-command/__tests__/infrastructure/app-definition-validator.test.js +0 -191
  114. package/frigg-cli/validate-command/__tests__/infrastructure/integration-class-validator.test.js +0 -146
  115. package/frigg-cli/validate-command/__tests__/infrastructure/template-validation.test.js +0 -155
  116. package/frigg-cli/validate-command/adapters/cli/validate-command.js +0 -199
  117. package/frigg-cli/validate-command/application/use-cases/validate-app-use-case.js +0 -35
  118. package/frigg-cli/validate-command/domain/entities/validation-result.js +0 -74
  119. package/frigg-cli/validate-command/domain/value-objects/fix-suggestion.js +0 -74
  120. package/frigg-cli/validate-command/domain/value-objects/validation-error.js +0 -68
  121. package/frigg-cli/validate-command/infrastructure/validators/api-module-validator.js +0 -181
  122. package/frigg-cli/validate-command/infrastructure/validators/app-definition-validator.js +0 -128
  123. package/frigg-cli/validate-command/infrastructure/validators/integration-class-validator.js +0 -113
  124. package/infrastructure/domains/admin-scripts/admin-script-builder.js +0 -200
  125. package/infrastructure/domains/admin-scripts/admin-script-builder.test.js +0 -499
  126. package/infrastructure/domains/admin-scripts/index.js +0 -5
  127. package/infrastructure/jest.config.js +0 -16
@@ -1,104 +0,0 @@
1
- const { ValidateAppUseCase } = require('../../application/use-cases/validate-app-use-case');
2
-
3
- describe('ValidateAppUseCase', () => {
4
- let useCase;
5
- let mockAppDefinitionValidator;
6
- let mockIntegrationClassValidator;
7
-
8
- beforeEach(() => {
9
- mockAppDefinitionValidator = {
10
- validate: jest.fn()
11
- };
12
- mockIntegrationClassValidator = {
13
- validate: jest.fn()
14
- };
15
- useCase = new ValidateAppUseCase({
16
- appDefinitionValidator: mockAppDefinitionValidator,
17
- integrationClassValidator: mockIntegrationClassValidator
18
- });
19
- });
20
-
21
- describe('execute', () => {
22
- it('validates app definition structure', async () => {
23
- const { ValidationResult } = require('../../domain/entities/validation-result');
24
- mockAppDefinitionValidator.validate.mockReturnValue(ValidationResult.create());
25
- mockIntegrationClassValidator.validate.mockReturnValue(ValidationResult.create());
26
-
27
- const definition = { integrations: [] };
28
- await useCase.execute({ definition });
29
-
30
- expect(mockAppDefinitionValidator.validate).toHaveBeenCalledWith(definition);
31
- });
32
-
33
- it('validates each integration class', async () => {
34
- const { ValidationResult } = require('../../domain/entities/validation-result');
35
- mockAppDefinitionValidator.validate.mockReturnValue(ValidationResult.create());
36
- mockIntegrationClassValidator.validate.mockReturnValue(ValidationResult.create());
37
-
38
- class Int1 { static Definition = { name: 'int1' }; }
39
- class Int2 { static Definition = { name: 'int2' }; }
40
- const definition = { integrations: [Int1, Int2] };
41
-
42
- await useCase.execute({ definition });
43
-
44
- expect(mockIntegrationClassValidator.validate).toHaveBeenCalledWith(Int1, 0);
45
- expect(mockIntegrationClassValidator.validate).toHaveBeenCalledWith(Int2, 1);
46
- });
47
-
48
- it('merges all validation results', async () => {
49
- const { ValidationResult } = require('../../domain/entities/validation-result');
50
- const { ValidationError } = require('../../domain/value-objects/validation-error');
51
-
52
- const appError = ValidationError.create({ path: 'database', message: 'missing', severity: 'error' });
53
- const intError = ValidationError.create({ path: 'integrations[0]', message: 'invalid', severity: 'error' });
54
-
55
- mockAppDefinitionValidator.validate.mockReturnValue(
56
- ValidationResult.create({ errors: [appError] })
57
- );
58
- mockIntegrationClassValidator.validate.mockReturnValue(
59
- ValidationResult.create({ errors: [intError] })
60
- );
61
-
62
- class Int1 { static Definition = { name: 'int1' }; }
63
- const definition = { integrations: [Int1] };
64
-
65
- const result = await useCase.execute({ definition });
66
-
67
- expect(result.getErrors()).toHaveLength(2);
68
- });
69
-
70
- it('returns valid result when no errors', async () => {
71
- const { ValidationResult } = require('../../domain/entities/validation-result');
72
- mockAppDefinitionValidator.validate.mockReturnValue(ValidationResult.create());
73
- mockIntegrationClassValidator.validate.mockReturnValue(ValidationResult.create());
74
-
75
- const definition = { integrations: [] };
76
- const result = await useCase.execute({ definition });
77
-
78
- expect(result.isValid()).toBe(true);
79
- });
80
-
81
- it('adds context with definition metadata', async () => {
82
- const { ValidationResult } = require('../../domain/entities/validation-result');
83
- mockAppDefinitionValidator.validate.mockReturnValue(ValidationResult.create());
84
-
85
- const definition = { integrations: [] };
86
- const result = await useCase.execute({ definition, appPath: '/app/backend' });
87
-
88
- expect(result.getContext()).toMatchObject({ appPath: '/app/backend' });
89
- });
90
- });
91
-
92
- describe('error handling', () => {
93
- it('handles validator throwing error', async () => {
94
- mockAppDefinitionValidator.validate.mockImplementation(() => {
95
- throw new Error('Validator crashed');
96
- });
97
-
98
- const definition = { integrations: [] };
99
-
100
- await expect(useCase.execute({ definition }))
101
- .rejects.toThrow('Validator crashed');
102
- });
103
- });
104
- });
@@ -1,153 +0,0 @@
1
- const { FixSuggestion } = require('../../domain/value-objects/fix-suggestion');
2
-
3
- describe('FixSuggestion', () => {
4
- describe('creation', () => {
5
- it('creates fix with action and description', () => {
6
- const fix = FixSuggestion.create({
7
- action: 'add',
8
- description: 'Add the name field to the configuration'
9
- });
10
- expect(fix.action).toBe('add');
11
- expect(fix.description).toBe('Add the name field to the configuration');
12
- });
13
-
14
- it('creates fix with template', () => {
15
- const fix = FixSuggestion.create({
16
- action: 'add',
17
- description: 'Add database configuration',
18
- template: { database: { mongoDB: { enable: true } } }
19
- });
20
- expect(fix.template).toEqual({ database: { mongoDB: { enable: true } } });
21
- });
22
-
23
- it('creates fix with code snippet', () => {
24
- const fix = FixSuggestion.create({
25
- action: 'replace',
26
- description: 'Update the export',
27
- codeSnippet: 'module.exports = { Definition };'
28
- });
29
- expect(fix.codeSnippet).toBe('module.exports = { Definition };');
30
- });
31
-
32
- it('throws for missing action', () => {
33
- expect(() => FixSuggestion.create({ description: 'Fix it' }))
34
- .toThrow('action is required');
35
- });
36
-
37
- it('throws for missing description', () => {
38
- expect(() => FixSuggestion.create({ action: 'add' }))
39
- .toThrow('description is required');
40
- });
41
-
42
- it('throws for invalid action', () => {
43
- expect(() => FixSuggestion.create({ action: 'destroy', description: 'd' }))
44
- .toThrow('Invalid action');
45
- });
46
- });
47
-
48
- describe('actions', () => {
49
- it('supports add action', () => {
50
- const fix = FixSuggestion.create({ action: 'add', description: 'd' });
51
- expect(fix.isAdd()).toBe(true);
52
- expect(fix.isRemove()).toBe(false);
53
- });
54
-
55
- it('supports remove action', () => {
56
- const fix = FixSuggestion.create({ action: 'remove', description: 'd' });
57
- expect(fix.isRemove()).toBe(true);
58
- });
59
-
60
- it('supports replace action', () => {
61
- const fix = FixSuggestion.create({ action: 'replace', description: 'd' });
62
- expect(fix.isReplace()).toBe(true);
63
- });
64
-
65
- it('supports rename action', () => {
66
- const fix = FixSuggestion.create({ action: 'rename', description: 'd' });
67
- expect(fix.isRename()).toBe(true);
68
- });
69
-
70
- it('supports update action', () => {
71
- const fix = FixSuggestion.create({ action: 'update', description: 'd' });
72
- expect(fix.isUpdate()).toBe(true);
73
- });
74
- });
75
-
76
- describe('applicability', () => {
77
- it('is auto-applicable with template', () => {
78
- const fix = FixSuggestion.create({
79
- action: 'add',
80
- description: 'd',
81
- template: { key: 'value' }
82
- });
83
- expect(fix.isAutoApplicable()).toBe(true);
84
- });
85
-
86
- it('is auto-applicable with code snippet', () => {
87
- const fix = FixSuggestion.create({
88
- action: 'replace',
89
- description: 'd',
90
- codeSnippet: 'const x = 1;'
91
- });
92
- expect(fix.isAutoApplicable()).toBe(true);
93
- });
94
-
95
- it('is not auto-applicable without template or snippet', () => {
96
- const fix = FixSuggestion.create({ action: 'add', description: 'd' });
97
- expect(fix.isAutoApplicable()).toBe(false);
98
- });
99
- });
100
-
101
- describe('target', () => {
102
- it('sets target path', () => {
103
- const fix = FixSuggestion.create({
104
- action: 'add',
105
- description: 'd',
106
- targetPath: 'config.database'
107
- });
108
- expect(fix.targetPath).toBe('config.database');
109
- });
110
-
111
- it('sets target file', () => {
112
- const fix = FixSuggestion.create({
113
- action: 'update',
114
- description: 'd',
115
- targetFile: 'backend/index.js'
116
- });
117
- expect(fix.targetFile).toBe('backend/index.js');
118
- });
119
- });
120
-
121
- describe('serialization', () => {
122
- it('converts to JSON', () => {
123
- const fix = FixSuggestion.create({
124
- action: 'add',
125
- description: 'Add config',
126
- template: { key: 'value' },
127
- targetPath: 'config'
128
- });
129
- const json = fix.toJSON();
130
- expect(json).toEqual({
131
- action: 'add',
132
- description: 'Add config',
133
- template: { key: 'value' },
134
- codeSnippet: null,
135
- targetPath: 'config',
136
- targetFile: null
137
- });
138
- });
139
- });
140
-
141
- describe('formatting', () => {
142
- it('formats for console display', () => {
143
- const fix = FixSuggestion.create({
144
- action: 'add',
145
- description: 'Add the name field',
146
- template: { name: 'my-app' }
147
- });
148
- const formatted = fix.format();
149
- expect(formatted).toContain('add');
150
- expect(formatted).toContain('Add the name field');
151
- });
152
- });
153
- });
@@ -1,162 +0,0 @@
1
- const { ValidationError } = require('../../domain/value-objects/validation-error');
2
- const { FixSuggestion } = require('../../domain/value-objects/fix-suggestion');
3
-
4
- describe('ValidationError', () => {
5
- describe('creation', () => {
6
- it('creates error with required fields', () => {
7
- const error = ValidationError.create({
8
- path: 'integrations[0].name',
9
- message: 'Integration name is required'
10
- });
11
- expect(error.path).toBe('integrations[0].name');
12
- expect(error.message).toBe('Integration name is required');
13
- expect(error.severity).toBe('error');
14
- });
15
-
16
- it('creates error with custom severity', () => {
17
- const warning = ValidationError.create({
18
- path: 'config.timeout',
19
- message: 'Timeout value seems high',
20
- severity: 'warning'
21
- });
22
- expect(warning.severity).toBe('warning');
23
- expect(warning.isWarning()).toBe(true);
24
- expect(warning.isError()).toBe(false);
25
- });
26
-
27
- it('creates error with fix suggestion', () => {
28
- const fix = FixSuggestion.create({
29
- action: 'add',
30
- description: 'Add the name field to integration'
31
- });
32
- const error = ValidationError.create({
33
- path: 'integrations[0].name',
34
- message: 'Required field missing',
35
- fix
36
- });
37
- expect(error.fix).toBe(fix);
38
- expect(error.hasFix()).toBe(true);
39
- });
40
-
41
- it('throws for missing path', () => {
42
- expect(() => ValidationError.create({ message: 'error' }))
43
- .toThrow('path is required');
44
- });
45
-
46
- it('throws for missing message', () => {
47
- expect(() => ValidationError.create({ path: 'a.b' }))
48
- .toThrow('message is required');
49
- });
50
-
51
- it('throws for invalid severity', () => {
52
- expect(() => ValidationError.create({
53
- path: 'a',
54
- message: 'b',
55
- severity: 'critical'
56
- })).toThrow('Invalid severity');
57
- });
58
- });
59
-
60
- describe('path parsing', () => {
61
- it('parses simple path', () => {
62
- const error = ValidationError.create({ path: 'name', message: 'm' });
63
- expect(error.getPathSegments()).toEqual(['name']);
64
- });
65
-
66
- it('parses nested path', () => {
67
- const error = ValidationError.create({ path: 'config.database.uri', message: 'm' });
68
- expect(error.getPathSegments()).toEqual(['config', 'database', 'uri']);
69
- });
70
-
71
- it('parses array path', () => {
72
- const error = ValidationError.create({ path: 'integrations[0].modules[1].name', message: 'm' });
73
- expect(error.getPathSegments()).toEqual(['integrations', '0', 'modules', '1', 'name']);
74
- });
75
-
76
- it('gets root path', () => {
77
- const error = ValidationError.create({ path: 'integrations[0].config.timeout', message: 'm' });
78
- expect(error.getRootPath()).toBe('integrations');
79
- });
80
- });
81
-
82
- describe('severity helpers', () => {
83
- it('identifies error severity', () => {
84
- const error = ValidationError.create({ path: 'a', message: 'm', severity: 'error' });
85
- expect(error.isError()).toBe(true);
86
- expect(error.isWarning()).toBe(false);
87
- expect(error.isInfo()).toBe(false);
88
- });
89
-
90
- it('identifies warning severity', () => {
91
- const error = ValidationError.create({ path: 'a', message: 'm', severity: 'warning' });
92
- expect(error.isError()).toBe(false);
93
- expect(error.isWarning()).toBe(true);
94
- });
95
-
96
- it('identifies info severity', () => {
97
- const error = ValidationError.create({ path: 'a', message: 'm', severity: 'info' });
98
- expect(error.isError()).toBe(false);
99
- expect(error.isInfo()).toBe(true);
100
- });
101
- });
102
-
103
- describe('code', () => {
104
- it('assigns error code', () => {
105
- const error = ValidationError.create({
106
- path: 'name',
107
- message: 'Required',
108
- code: 'REQUIRED_FIELD'
109
- });
110
- expect(error.code).toBe('REQUIRED_FIELD');
111
- });
112
-
113
- it('defaults to null code', () => {
114
- const error = ValidationError.create({ path: 'a', message: 'm' });
115
- expect(error.code).toBeNull();
116
- });
117
- });
118
-
119
- describe('serialization', () => {
120
- it('converts to JSON', () => {
121
- const error = ValidationError.create({
122
- path: 'config.name',
123
- message: 'Name required',
124
- severity: 'error',
125
- code: 'REQUIRED'
126
- });
127
- const json = error.toJSON();
128
- expect(json).toEqual({
129
- path: 'config.name',
130
- message: 'Name required',
131
- severity: 'error',
132
- code: 'REQUIRED',
133
- fix: null
134
- });
135
- });
136
-
137
- it('includes fix in JSON', () => {
138
- const fix = FixSuggestion.create({ action: 'add', description: 'Add field' });
139
- const error = ValidationError.create({
140
- path: 'a',
141
- message: 'm',
142
- fix
143
- });
144
- const json = error.toJSON();
145
- expect(json.fix).toMatchObject({ action: 'add', description: 'Add field' });
146
- });
147
- });
148
-
149
- describe('equality', () => {
150
- it('considers errors equal by path and message', () => {
151
- const error1 = ValidationError.create({ path: 'a.b', message: 'Required' });
152
- const error2 = ValidationError.create({ path: 'a.b', message: 'Required' });
153
- expect(error1.equals(error2)).toBe(true);
154
- });
155
-
156
- it('considers errors different by path', () => {
157
- const error1 = ValidationError.create({ path: 'a.b', message: 'Required' });
158
- const error2 = ValidationError.create({ path: 'a.c', message: 'Required' });
159
- expect(error1.equals(error2)).toBe(false);
160
- });
161
- });
162
- });
@@ -1,152 +0,0 @@
1
- const { ValidationResult } = require('../../domain/entities/validation-result');
2
- const { ValidationError } = require('../../domain/value-objects/validation-error');
3
- const { FixSuggestion } = require('../../domain/value-objects/fix-suggestion');
4
-
5
- describe('ValidationResult', () => {
6
- describe('creation', () => {
7
- it('creates empty result with no errors', () => {
8
- const result = ValidationResult.create();
9
- expect(result.isValid()).toBe(true);
10
- expect(result.getErrors()).toHaveLength(0);
11
- expect(result.getWarnings()).toHaveLength(0);
12
- });
13
-
14
- it('creates result with errors', () => {
15
- const error = ValidationError.create({
16
- path: 'integrations[0].name',
17
- message: 'Integration name is required',
18
- severity: 'error'
19
- });
20
- const result = ValidationResult.create({ errors: [error] });
21
- expect(result.isValid()).toBe(false);
22
- expect(result.getErrors()).toHaveLength(1);
23
- });
24
-
25
- it('creates result with warnings', () => {
26
- const warning = ValidationError.create({
27
- path: 'config.timeout',
28
- message: 'Timeout value is unusually high',
29
- severity: 'warning'
30
- });
31
- const result = ValidationResult.create({ errors: [warning] });
32
- expect(result.isValid()).toBe(true);
33
- expect(result.getWarnings()).toHaveLength(1);
34
- });
35
- });
36
-
37
- describe('addError', () => {
38
- it('adds error to result', () => {
39
- const result = ValidationResult.create();
40
- const error = ValidationError.create({
41
- path: 'name',
42
- message: 'Name is required',
43
- severity: 'error'
44
- });
45
- result.addError(error);
46
- expect(result.isValid()).toBe(false);
47
- expect(result.getErrors()).toContain(error);
48
- });
49
-
50
- it('adds warning without affecting validity', () => {
51
- const result = ValidationResult.create();
52
- const warning = ValidationError.create({
53
- path: 'description',
54
- message: 'Description is recommended',
55
- severity: 'warning'
56
- });
57
- result.addError(warning);
58
- expect(result.isValid()).toBe(true);
59
- expect(result.getWarnings()).toContain(warning);
60
- });
61
- });
62
-
63
- describe('merge', () => {
64
- it('merges two valid results', () => {
65
- const result1 = ValidationResult.create();
66
- const result2 = ValidationResult.create();
67
- const merged = result1.merge(result2);
68
- expect(merged.isValid()).toBe(true);
69
- });
70
-
71
- it('merges results with errors', () => {
72
- const error1 = ValidationError.create({
73
- path: 'name',
74
- message: 'Name required',
75
- severity: 'error'
76
- });
77
- const error2 = ValidationError.create({
78
- path: 'version',
79
- message: 'Version required',
80
- severity: 'error'
81
- });
82
- const result1 = ValidationResult.create({ errors: [error1] });
83
- const result2 = ValidationResult.create({ errors: [error2] });
84
- const merged = result1.merge(result2);
85
- expect(merged.isValid()).toBe(false);
86
- expect(merged.getErrors()).toHaveLength(2);
87
- });
88
-
89
- it('preserves context from both results', () => {
90
- const result1 = ValidationResult.create({ context: { file: 'index.js' } });
91
- const result2 = ValidationResult.create({ context: { integration: 'oauth' } });
92
- const merged = result1.merge(result2);
93
- expect(merged.getContext()).toMatchObject({ file: 'index.js', integration: 'oauth' });
94
- });
95
- });
96
-
97
- describe('filtering', () => {
98
- it('filters errors by path prefix', () => {
99
- const errors = [
100
- ValidationError.create({ path: 'integrations[0].name', message: 'a', severity: 'error' }),
101
- ValidationError.create({ path: 'integrations[1].config', message: 'b', severity: 'error' }),
102
- ValidationError.create({ path: 'database.uri', message: 'c', severity: 'error' })
103
- ];
104
- const result = ValidationResult.create({ errors });
105
- const filtered = result.filterByPath('integrations');
106
- expect(filtered.getErrors()).toHaveLength(2);
107
- });
108
-
109
- it('filters by severity', () => {
110
- const errors = [
111
- ValidationError.create({ path: 'a', message: 'error1', severity: 'error' }),
112
- ValidationError.create({ path: 'b', message: 'warning1', severity: 'warning' }),
113
- ValidationError.create({ path: 'c', message: 'info1', severity: 'info' })
114
- ];
115
- const result = ValidationResult.create({ errors });
116
- expect(result.getBySeverity('error')).toHaveLength(1);
117
- expect(result.getBySeverity('warning')).toHaveLength(1);
118
- expect(result.getBySeverity('info')).toHaveLength(1);
119
- });
120
- });
121
-
122
- describe('summary', () => {
123
- it('generates summary statistics', () => {
124
- const errors = [
125
- ValidationError.create({ path: 'a', message: 'm1', severity: 'error' }),
126
- ValidationError.create({ path: 'b', message: 'm2', severity: 'error' }),
127
- ValidationError.create({ path: 'c', message: 'm3', severity: 'warning' })
128
- ];
129
- const result = ValidationResult.create({ errors });
130
- const summary = result.getSummary();
131
- expect(summary.errorCount).toBe(2);
132
- expect(summary.warningCount).toBe(1);
133
- expect(summary.isValid).toBe(false);
134
- });
135
- });
136
-
137
- describe('serialization', () => {
138
- it('converts to JSON', () => {
139
- const error = ValidationError.create({
140
- path: 'name',
141
- message: 'Required',
142
- severity: 'error',
143
- fix: FixSuggestion.create({ action: 'add', description: 'Add name field' })
144
- });
145
- const result = ValidationResult.create({ errors: [error] });
146
- const json = result.toJSON();
147
- expect(json).toHaveProperty('valid', false);
148
- expect(json).toHaveProperty('errors');
149
- expect(json.errors[0]).toHaveProperty('path', 'name');
150
- });
151
- });
152
- });