@friggframework/devtools 2.0.0--canary.548.c8ae0ca.0 → 2.0.0--canary.545.c40eca4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/frigg-cli/README.md +1 -1
- package/frigg-cli/__tests__/application/use-cases/AddApiModuleToIntegrationUseCase.test.js +326 -0
- package/frigg-cli/__tests__/application/use-cases/CreateApiModuleUseCase.test.js +337 -0
- package/frigg-cli/__tests__/domain/entities/ApiModule.test.js +373 -0
- package/frigg-cli/__tests__/domain/entities/AppDefinition.test.js +313 -0
- package/frigg-cli/__tests__/domain/services/IntegrationValidator.test.js +269 -0
- package/frigg-cli/__tests__/domain/value-objects/IntegrationName.test.js +82 -0
- package/frigg-cli/__tests__/infrastructure/adapters/IntegrationJsUpdater.test.js +408 -0
- package/frigg-cli/__tests__/infrastructure/repositories/FileSystemApiModuleRepository.test.js +583 -0
- package/frigg-cli/__tests__/infrastructure/repositories/FileSystemAppDefinitionRepository.test.js +314 -0
- package/frigg-cli/__tests__/infrastructure/repositories/FileSystemIntegrationRepository.test.js +383 -0
- package/frigg-cli/__tests__/unit/commands/build.test.js +1 -1
- package/frigg-cli/__tests__/unit/commands/doctor.test.js +0 -2
- package/frigg-cli/__tests__/unit/commands/init.test.js +406 -0
- package/frigg-cli/__tests__/unit/commands/install.test.js +23 -19
- package/frigg-cli/__tests__/unit/commands/provider-dispatch.test.js +383 -0
- package/frigg-cli/__tests__/unit/commands/repair.test.js +275 -0
- package/frigg-cli/__tests__/unit/dependencies.test.js +2 -2
- package/frigg-cli/__tests__/unit/start-command/application/RunPreflightChecksUseCase.test.js +411 -0
- package/frigg-cli/__tests__/unit/start-command/infrastructure/DatabaseAdapter.test.js +405 -0
- package/frigg-cli/__tests__/unit/start-command/infrastructure/DockerAdapter.test.js +496 -0
- package/frigg-cli/__tests__/unit/start-command/presentation/InteractivePromptAdapter.test.js +474 -0
- package/frigg-cli/__tests__/unit/utils/output.test.js +196 -0
- package/frigg-cli/application/use-cases/AddApiModuleToIntegrationUseCase.js +93 -0
- package/frigg-cli/application/use-cases/CreateApiModuleUseCase.js +93 -0
- package/frigg-cli/application/use-cases/CreateIntegrationUseCase.js +103 -0
- package/frigg-cli/build-command/index.js +123 -11
- package/frigg-cli/container.js +172 -0
- package/frigg-cli/deploy-command/index.js +83 -1
- package/frigg-cli/docs/OUTPUT_MIGRATION_GUIDE.md +286 -0
- package/frigg-cli/doctor-command/index.js +37 -16
- package/frigg-cli/domain/entities/ApiModule.js +272 -0
- package/frigg-cli/domain/entities/AppDefinition.js +227 -0
- package/frigg-cli/domain/entities/Integration.js +198 -0
- package/frigg-cli/domain/exceptions/DomainException.js +24 -0
- package/frigg-cli/domain/ports/IApiModuleRepository.js +53 -0
- package/frigg-cli/domain/ports/IAppDefinitionRepository.js +43 -0
- package/frigg-cli/domain/ports/IIntegrationRepository.js +61 -0
- package/frigg-cli/domain/services/IntegrationValidator.js +185 -0
- package/frigg-cli/domain/value-objects/IntegrationId.js +42 -0
- package/frigg-cli/domain/value-objects/IntegrationName.js +60 -0
- package/frigg-cli/domain/value-objects/SemanticVersion.js +70 -0
- package/frigg-cli/generate-iam-command.js +21 -1
- package/frigg-cli/index.js +21 -6
- package/frigg-cli/index.test.js +7 -2
- package/frigg-cli/infrastructure/UnitOfWork.js +46 -0
- package/frigg-cli/infrastructure/adapters/BackendJsUpdater.js +197 -0
- package/frigg-cli/infrastructure/adapters/FileSystemAdapter.js +224 -0
- package/frigg-cli/infrastructure/adapters/IntegrationJsUpdater.js +249 -0
- package/frigg-cli/infrastructure/adapters/SchemaValidator.js +92 -0
- package/frigg-cli/infrastructure/repositories/FileSystemApiModuleRepository.js +373 -0
- package/frigg-cli/infrastructure/repositories/FileSystemAppDefinitionRepository.js +116 -0
- package/frigg-cli/infrastructure/repositories/FileSystemIntegrationRepository.js +277 -0
- package/frigg-cli/init-command/backend-first-handler.js +124 -42
- package/frigg-cli/init-command/index.js +2 -1
- package/frigg-cli/init-command/template-handler.js +13 -3
- package/frigg-cli/install-command/backend-js.js +3 -3
- package/frigg-cli/install-command/environment-variables.js +16 -19
- package/frigg-cli/install-command/environment-variables.test.js +12 -13
- package/frigg-cli/install-command/index.js +14 -9
- package/frigg-cli/install-command/integration-file.js +3 -3
- package/frigg-cli/install-command/validate-package.js +5 -9
- package/frigg-cli/jest.config.js +4 -1
- package/frigg-cli/package-lock.json +16226 -0
- package/frigg-cli/repair-command/index.js +121 -128
- package/frigg-cli/start-command/application/RunPreflightChecksUseCase.js +376 -0
- package/frigg-cli/start-command/index.js +324 -2
- package/frigg-cli/start-command/infrastructure/DatabaseAdapter.js +591 -0
- package/frigg-cli/start-command/infrastructure/DockerAdapter.js +306 -0
- package/frigg-cli/start-command/presentation/InteractivePromptAdapter.js +329 -0
- package/frigg-cli/templates/backend/.env.example +62 -0
- package/frigg-cli/templates/backend/.eslintrc.json +12 -0
- package/frigg-cli/templates/backend/.prettierrc +6 -0
- package/frigg-cli/templates/backend/docker-compose.yml +22 -0
- package/frigg-cli/templates/backend/index.js +96 -0
- package/frigg-cli/templates/backend/infrastructure.js +12 -0
- package/frigg-cli/templates/backend/jest.config.js +17 -0
- package/frigg-cli/templates/backend/package.json +50 -0
- package/frigg-cli/templates/backend/src/api-modules/.gitkeep +10 -0
- package/frigg-cli/templates/backend/src/base/.gitkeep +7 -0
- package/frigg-cli/templates/backend/src/integrations/.gitkeep +10 -0
- package/frigg-cli/templates/backend/src/integrations/ExampleIntegration.js +65 -0
- package/frigg-cli/templates/backend/src/utils/.gitkeep +7 -0
- package/frigg-cli/templates/backend/test/setup.js +30 -0
- package/frigg-cli/templates/backend/ui-extensions/.gitkeep +0 -0
- package/frigg-cli/templates/backend/ui-extensions/README.md +77 -0
- package/frigg-cli/ui-command/index.js +58 -36
- package/frigg-cli/utils/__tests__/provider-helper.test.js +55 -0
- package/frigg-cli/utils/__tests__/repo-detection.test.js +436 -0
- package/frigg-cli/utils/output.js +382 -0
- package/frigg-cli/utils/provider-helper.js +75 -0
- package/frigg-cli/utils/repo-detection.js +85 -37
- package/frigg-cli/validate-command/__tests__/adapters/validate-command.test.js +205 -0
- package/frigg-cli/validate-command/__tests__/application/validate-app-use-case.test.js +104 -0
- package/frigg-cli/validate-command/__tests__/domain/fix-suggestion.test.js +153 -0
- package/frigg-cli/validate-command/__tests__/domain/validation-error.test.js +162 -0
- package/frigg-cli/validate-command/__tests__/domain/validation-result.test.js +152 -0
- package/frigg-cli/validate-command/__tests__/infrastructure/api-module-validator.test.js +332 -0
- package/frigg-cli/validate-command/__tests__/infrastructure/app-definition-validator.test.js +191 -0
- package/frigg-cli/validate-command/__tests__/infrastructure/integration-class-validator.test.js +146 -0
- package/frigg-cli/validate-command/__tests__/infrastructure/template-validation.test.js +155 -0
- package/frigg-cli/validate-command/adapters/cli/validate-command.js +199 -0
- package/frigg-cli/validate-command/application/use-cases/validate-app-use-case.js +35 -0
- package/frigg-cli/validate-command/domain/entities/validation-result.js +74 -0
- package/frigg-cli/validate-command/domain/value-objects/fix-suggestion.js +74 -0
- package/frigg-cli/validate-command/domain/value-objects/validation-error.js +68 -0
- package/frigg-cli/validate-command/infrastructure/validators/api-module-validator.js +181 -0
- package/frigg-cli/validate-command/infrastructure/validators/app-definition-validator.js +128 -0
- package/frigg-cli/validate-command/infrastructure/validators/integration-class-validator.js +113 -0
- package/infrastructure/create-frigg-infrastructure.js +93 -0
- package/infrastructure/docs/iam-policy-templates.md +1 -1
- package/infrastructure/domains/admin-scripts/admin-script-builder.js +200 -0
- package/infrastructure/domains/admin-scripts/admin-script-builder.test.js +499 -0
- package/infrastructure/domains/admin-scripts/index.js +5 -0
- package/infrastructure/domains/networking/vpc-builder.test.js +2 -4
- package/infrastructure/domains/networking/vpc-resolver.test.js +1 -1
- package/infrastructure/domains/shared/resource-discovery.js +5 -5
- package/infrastructure/domains/shared/types/app-definition.js +21 -0
- package/infrastructure/domains/shared/types/discovery-result.test.js +1 -1
- package/infrastructure/domains/shared/utilities/base-definition-factory.js +10 -1
- package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +2 -2
- package/infrastructure/infrastructure-composer.js +2 -0
- package/infrastructure/infrastructure-composer.test.js +2 -2
- package/infrastructure/jest.config.js +16 -0
- package/management-ui/README.md +245 -109
- package/package.json +8 -7
- package/frigg-cli/install-command/logger.js +0 -12
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RunPreflightChecksUseCase Tests
|
|
3
|
+
* Orchestrates pre-flight checks before starting Frigg
|
|
4
|
+
*
|
|
5
|
+
* Tests follow TDD pattern - written BEFORE implementation
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const { RunPreflightChecksUseCase } = require('../../../../start-command/application/RunPreflightChecksUseCase');
|
|
9
|
+
|
|
10
|
+
describe('RunPreflightChecksUseCase', () => {
|
|
11
|
+
let useCase;
|
|
12
|
+
let mockDockerAdapter;
|
|
13
|
+
let mockDatabaseAdapter;
|
|
14
|
+
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
jest.clearAllMocks();
|
|
17
|
+
|
|
18
|
+
// Reset environment
|
|
19
|
+
delete process.env.DATABASE_URL;
|
|
20
|
+
|
|
21
|
+
mockDockerAdapter = {
|
|
22
|
+
isDockerInstalled: jest.fn(),
|
|
23
|
+
isDockerRunning: jest.fn(),
|
|
24
|
+
findDockerComposeFile: jest.fn(),
|
|
25
|
+
startDockerDesktop: jest.fn(),
|
|
26
|
+
startDockerCompose: jest.fn(),
|
|
27
|
+
waitForDockerReady: jest.fn(),
|
|
28
|
+
waitForLocalStack: jest.fn()
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
mockDatabaseAdapter = {
|
|
32
|
+
getDatabaseType: jest.fn(),
|
|
33
|
+
isDatabaseReachable: jest.fn(),
|
|
34
|
+
getConnectionDetails: jest.fn()
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
useCase = new RunPreflightChecksUseCase({
|
|
38
|
+
dockerAdapter: mockDockerAdapter,
|
|
39
|
+
databaseAdapter: mockDatabaseAdapter
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
describe('execute() - All checks pass', () => {
|
|
44
|
+
beforeEach(() => {
|
|
45
|
+
process.env.DATABASE_URL = 'mongodb://localhost:27017/frigg';
|
|
46
|
+
mockDockerAdapter.isDockerInstalled.mockResolvedValue(true);
|
|
47
|
+
mockDockerAdapter.isDockerRunning.mockResolvedValue(true);
|
|
48
|
+
mockDockerAdapter.findDockerComposeFile.mockResolvedValue('/test/docker-compose.yml');
|
|
49
|
+
mockDockerAdapter.waitForLocalStack.mockResolvedValue({ ready: true });
|
|
50
|
+
mockDatabaseAdapter.getDatabaseType.mockReturnValue('mongodb');
|
|
51
|
+
mockDatabaseAdapter.isDatabaseReachable.mockResolvedValue({ reachable: true });
|
|
52
|
+
mockDatabaseAdapter.getConnectionDetails.mockReturnValue({
|
|
53
|
+
type: 'mongodb',
|
|
54
|
+
host: 'localhost',
|
|
55
|
+
port: 27017,
|
|
56
|
+
database: 'frigg'
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('should return all checks passed when everything is ready', async () => {
|
|
61
|
+
const result = await useCase.execute({ projectPath: '/test/project' });
|
|
62
|
+
|
|
63
|
+
expect(result.allPassed).toBe(true);
|
|
64
|
+
// 5 checks: DATABASE_URL, docker_installed, docker_running, database_reachable, localstack_reachable
|
|
65
|
+
expect(result.checks).toHaveLength(5);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('should include DATABASE_URL check result', async () => {
|
|
69
|
+
const result = await useCase.execute({ projectPath: '/test/project' });
|
|
70
|
+
|
|
71
|
+
const dbUrlCheck = result.checks.find(c => c.name === 'database_url');
|
|
72
|
+
expect(dbUrlCheck.status).toBe('passed');
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('should include Docker installed check result', async () => {
|
|
76
|
+
const result = await useCase.execute({ projectPath: '/test/project' });
|
|
77
|
+
|
|
78
|
+
const dockerCheck = result.checks.find(c => c.name === 'docker_installed');
|
|
79
|
+
expect(dockerCheck.status).toBe('passed');
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('should include Docker running check result', async () => {
|
|
83
|
+
const result = await useCase.execute({ projectPath: '/test/project' });
|
|
84
|
+
|
|
85
|
+
const dockerRunningCheck = result.checks.find(c => c.name === 'docker_running');
|
|
86
|
+
expect(dockerRunningCheck.status).toBe('passed');
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('should include database reachable check result', async () => {
|
|
90
|
+
const result = await useCase.execute({ projectPath: '/test/project' });
|
|
91
|
+
|
|
92
|
+
const dbCheck = result.checks.find(c => c.name === 'database_reachable');
|
|
93
|
+
expect(dbCheck.status).toBe('passed');
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
describe('execute() - DATABASE_URL check', () => {
|
|
98
|
+
it('should fail when DATABASE_URL is not set', async () => {
|
|
99
|
+
delete process.env.DATABASE_URL;
|
|
100
|
+
|
|
101
|
+
const result = await useCase.execute({ projectPath: '/test/project' });
|
|
102
|
+
|
|
103
|
+
expect(result.allPassed).toBe(false);
|
|
104
|
+
const dbUrlCheck = result.checks.find(c => c.name === 'database_url');
|
|
105
|
+
expect(dbUrlCheck.status).toBe('failed');
|
|
106
|
+
expect(dbUrlCheck.message).toContain('DATABASE_URL');
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('should provide resolution option for missing DATABASE_URL', async () => {
|
|
110
|
+
delete process.env.DATABASE_URL;
|
|
111
|
+
|
|
112
|
+
const result = await useCase.execute({ projectPath: '/test/project' });
|
|
113
|
+
|
|
114
|
+
const dbUrlCheck = result.checks.find(c => c.name === 'database_url');
|
|
115
|
+
expect(dbUrlCheck.canResolve).toBe(true);
|
|
116
|
+
expect(dbUrlCheck.resolution.type).toBe('create_env');
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('should pass when DATABASE_URL is set', async () => {
|
|
120
|
+
process.env.DATABASE_URL = 'mongodb://localhost:27017/frigg';
|
|
121
|
+
mockDatabaseAdapter.getDatabaseType.mockReturnValue('mongodb');
|
|
122
|
+
|
|
123
|
+
const result = await useCase.execute({ projectPath: '/test/project' });
|
|
124
|
+
|
|
125
|
+
const dbUrlCheck = result.checks.find(c => c.name === 'database_url');
|
|
126
|
+
expect(dbUrlCheck.status).toBe('passed');
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
describe('execute() - Docker installed check', () => {
|
|
131
|
+
beforeEach(() => {
|
|
132
|
+
process.env.DATABASE_URL = 'mongodb://localhost:27017/frigg';
|
|
133
|
+
mockDatabaseAdapter.getDatabaseType.mockReturnValue('mongodb');
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('should fail when Docker is not installed', async () => {
|
|
137
|
+
mockDockerAdapter.isDockerInstalled.mockResolvedValue(false);
|
|
138
|
+
|
|
139
|
+
const result = await useCase.execute({ projectPath: '/test/project' });
|
|
140
|
+
|
|
141
|
+
const dockerCheck = result.checks.find(c => c.name === 'docker_installed');
|
|
142
|
+
expect(dockerCheck.status).toBe('failed');
|
|
143
|
+
expect(dockerCheck.message).toContain('Docker is not installed');
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it('should not provide auto-resolution for Docker not installed', async () => {
|
|
147
|
+
mockDockerAdapter.isDockerInstalled.mockResolvedValue(false);
|
|
148
|
+
|
|
149
|
+
const result = await useCase.execute({ projectPath: '/test/project' });
|
|
150
|
+
|
|
151
|
+
const dockerCheck = result.checks.find(c => c.name === 'docker_installed');
|
|
152
|
+
expect(dockerCheck.canResolve).toBe(false);
|
|
153
|
+
expect(dockerCheck.resolution.type).toBe('manual');
|
|
154
|
+
expect(dockerCheck.resolution.instructions).toBeDefined();
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it('should pass when Docker is installed', async () => {
|
|
158
|
+
mockDockerAdapter.isDockerInstalled.mockResolvedValue(true);
|
|
159
|
+
mockDockerAdapter.isDockerRunning.mockResolvedValue(true);
|
|
160
|
+
mockDockerAdapter.waitForLocalStack.mockResolvedValue({ ready: true });
|
|
161
|
+
mockDatabaseAdapter.isDatabaseReachable.mockResolvedValue({ reachable: true });
|
|
162
|
+
|
|
163
|
+
const result = await useCase.execute({ projectPath: '/test/project' });
|
|
164
|
+
|
|
165
|
+
const dockerCheck = result.checks.find(c => c.name === 'docker_installed');
|
|
166
|
+
expect(dockerCheck.status).toBe('passed');
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
describe('execute() - Docker running check', () => {
|
|
171
|
+
beforeEach(() => {
|
|
172
|
+
process.env.DATABASE_URL = 'mongodb://localhost:27017/frigg';
|
|
173
|
+
mockDatabaseAdapter.getDatabaseType.mockReturnValue('mongodb');
|
|
174
|
+
mockDockerAdapter.isDockerInstalled.mockResolvedValue(true);
|
|
175
|
+
mockDockerAdapter.waitForLocalStack.mockResolvedValue({ ready: true });
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it('should fail when Docker daemon is not running', async () => {
|
|
179
|
+
mockDockerAdapter.isDockerRunning.mockResolvedValue(false);
|
|
180
|
+
|
|
181
|
+
const result = await useCase.execute({ projectPath: '/test/project' });
|
|
182
|
+
|
|
183
|
+
const dockerRunningCheck = result.checks.find(c => c.name === 'docker_running');
|
|
184
|
+
expect(dockerRunningCheck.status).toBe('failed');
|
|
185
|
+
expect(dockerRunningCheck.message).toContain('Docker is not running');
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it('should provide resolution option to start Docker', async () => {
|
|
189
|
+
mockDockerAdapter.isDockerRunning.mockResolvedValue(false);
|
|
190
|
+
|
|
191
|
+
const result = await useCase.execute({ projectPath: '/test/project' });
|
|
192
|
+
|
|
193
|
+
const dockerRunningCheck = result.checks.find(c => c.name === 'docker_running');
|
|
194
|
+
expect(dockerRunningCheck.canResolve).toBe(true);
|
|
195
|
+
expect(dockerRunningCheck.resolution.type).toBe('start_docker');
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it('should pass when Docker is running', async () => {
|
|
199
|
+
mockDockerAdapter.isDockerRunning.mockResolvedValue(true);
|
|
200
|
+
mockDockerAdapter.waitForLocalStack.mockResolvedValue({ ready: true });
|
|
201
|
+
mockDatabaseAdapter.isDatabaseReachable.mockResolvedValue({ reachable: true });
|
|
202
|
+
|
|
203
|
+
const result = await useCase.execute({ projectPath: '/test/project' });
|
|
204
|
+
|
|
205
|
+
const dockerRunningCheck = result.checks.find(c => c.name === 'docker_running');
|
|
206
|
+
expect(dockerRunningCheck.status).toBe('passed');
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
describe('execute() - Database reachable check', () => {
|
|
211
|
+
beforeEach(() => {
|
|
212
|
+
process.env.DATABASE_URL = 'mongodb://localhost:27017/frigg';
|
|
213
|
+
mockDatabaseAdapter.getDatabaseType.mockReturnValue('mongodb');
|
|
214
|
+
mockDockerAdapter.isDockerInstalled.mockResolvedValue(true);
|
|
215
|
+
mockDockerAdapter.isDockerRunning.mockResolvedValue(true);
|
|
216
|
+
mockDockerAdapter.waitForLocalStack.mockResolvedValue({ ready: true });
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it('should fail when database is not reachable', async () => {
|
|
220
|
+
mockDatabaseAdapter.isDatabaseReachable.mockResolvedValue({
|
|
221
|
+
reachable: false,
|
|
222
|
+
error: 'ECONNREFUSED'
|
|
223
|
+
});
|
|
224
|
+
mockDockerAdapter.findDockerComposeFile.mockResolvedValue('/test/docker-compose.yml');
|
|
225
|
+
|
|
226
|
+
const result = await useCase.execute({ projectPath: '/test/project' });
|
|
227
|
+
|
|
228
|
+
const dbCheck = result.checks.find(c => c.name === 'database_reachable');
|
|
229
|
+
expect(dbCheck.status).toBe('failed');
|
|
230
|
+
expect(dbCheck.message).toContain('Database is not reachable');
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
it('should provide docker-compose resolution when file exists', async () => {
|
|
234
|
+
mockDatabaseAdapter.isDatabaseReachable.mockResolvedValue({
|
|
235
|
+
reachable: false,
|
|
236
|
+
error: 'ECONNREFUSED'
|
|
237
|
+
});
|
|
238
|
+
mockDockerAdapter.findDockerComposeFile.mockResolvedValue('/test/docker-compose.yml');
|
|
239
|
+
|
|
240
|
+
const result = await useCase.execute({ projectPath: '/test/project' });
|
|
241
|
+
|
|
242
|
+
const dbCheck = result.checks.find(c => c.name === 'database_reachable');
|
|
243
|
+
expect(dbCheck.canResolve).toBe(true);
|
|
244
|
+
expect(dbCheck.resolution.type).toBe('start_docker_compose');
|
|
245
|
+
expect(dbCheck.resolution.composePath).toBe('/test/docker-compose.yml');
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
it('should suggest manual setup when no docker-compose exists', async () => {
|
|
249
|
+
mockDatabaseAdapter.isDatabaseReachable.mockResolvedValue({
|
|
250
|
+
reachable: false,
|
|
251
|
+
error: 'ECONNREFUSED'
|
|
252
|
+
});
|
|
253
|
+
mockDockerAdapter.findDockerComposeFile.mockResolvedValue(null);
|
|
254
|
+
|
|
255
|
+
const result = await useCase.execute({ projectPath: '/test/project' });
|
|
256
|
+
|
|
257
|
+
const dbCheck = result.checks.find(c => c.name === 'database_reachable');
|
|
258
|
+
expect(dbCheck.canResolve).toBe(false);
|
|
259
|
+
expect(dbCheck.resolution.type).toBe('manual');
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
it('should pass when database is reachable', async () => {
|
|
263
|
+
mockDatabaseAdapter.isDatabaseReachable.mockResolvedValue({ reachable: true });
|
|
264
|
+
|
|
265
|
+
const result = await useCase.execute({ projectPath: '/test/project' });
|
|
266
|
+
|
|
267
|
+
const dbCheck = result.checks.find(c => c.name === 'database_reachable');
|
|
268
|
+
expect(dbCheck.status).toBe('passed');
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
describe('execute() - LocalStack reachable check', () => {
|
|
273
|
+
beforeEach(() => {
|
|
274
|
+
process.env.DATABASE_URL = 'mongodb://localhost:27017/frigg';
|
|
275
|
+
mockDatabaseAdapter.getDatabaseType.mockReturnValue('mongodb');
|
|
276
|
+
mockDockerAdapter.isDockerInstalled.mockResolvedValue(true);
|
|
277
|
+
mockDockerAdapter.isDockerRunning.mockResolvedValue(true);
|
|
278
|
+
mockDatabaseAdapter.isDatabaseReachable.mockResolvedValue({ reachable: true });
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
it('should fail when LocalStack is not reachable', async () => {
|
|
282
|
+
mockDockerAdapter.waitForLocalStack.mockResolvedValue({ ready: false });
|
|
283
|
+
mockDockerAdapter.findDockerComposeFile.mockResolvedValue('/test/docker-compose.yml');
|
|
284
|
+
|
|
285
|
+
const result = await useCase.execute({ projectPath: '/test/project' });
|
|
286
|
+
|
|
287
|
+
const localstackCheck = result.checks.find(c => c.name === 'localstack_reachable');
|
|
288
|
+
expect(localstackCheck.status).toBe('failed');
|
|
289
|
+
expect(localstackCheck.message).toContain('LocalStack is not reachable');
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
it('should provide docker-compose resolution when LocalStack is not reachable', async () => {
|
|
293
|
+
mockDockerAdapter.waitForLocalStack.mockResolvedValue({ ready: false });
|
|
294
|
+
mockDockerAdapter.findDockerComposeFile.mockResolvedValue('/test/docker-compose.yml');
|
|
295
|
+
|
|
296
|
+
const result = await useCase.execute({ projectPath: '/test/project' });
|
|
297
|
+
|
|
298
|
+
const localstackCheck = result.checks.find(c => c.name === 'localstack_reachable');
|
|
299
|
+
expect(localstackCheck.canResolve).toBe(true);
|
|
300
|
+
expect(localstackCheck.resolution.type).toBe('start_docker_compose');
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
it('should pass when LocalStack is reachable', async () => {
|
|
304
|
+
mockDockerAdapter.waitForLocalStack.mockResolvedValue({ ready: true });
|
|
305
|
+
|
|
306
|
+
const result = await useCase.execute({ projectPath: '/test/project' });
|
|
307
|
+
|
|
308
|
+
const localstackCheck = result.checks.find(c => c.name === 'localstack_reachable');
|
|
309
|
+
expect(localstackCheck.status).toBe('passed');
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
it('should skip LocalStack check when AWS_ENDPOINT points to real AWS', async () => {
|
|
313
|
+
process.env.AWS_ENDPOINT = 'https://sqs.us-east-1.amazonaws.com';
|
|
314
|
+
mockDockerAdapter.waitForLocalStack.mockResolvedValue({ ready: true });
|
|
315
|
+
|
|
316
|
+
const result = await useCase.execute({ projectPath: '/test/project' });
|
|
317
|
+
|
|
318
|
+
// Should not include LocalStack check when using real AWS
|
|
319
|
+
const localstackCheck = result.checks.find(c => c.name === 'localstack_reachable');
|
|
320
|
+
expect(localstackCheck).toBeUndefined();
|
|
321
|
+
|
|
322
|
+
delete process.env.AWS_ENDPOINT;
|
|
323
|
+
});
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
describe('execute() - Short-circuit behavior', () => {
|
|
327
|
+
it('should skip Docker checks if DATABASE_URL is missing', async () => {
|
|
328
|
+
delete process.env.DATABASE_URL;
|
|
329
|
+
|
|
330
|
+
await useCase.execute({ projectPath: '/test/project' });
|
|
331
|
+
|
|
332
|
+
// Docker checks should not be called since DATABASE_URL failed
|
|
333
|
+
expect(mockDockerAdapter.isDockerInstalled).not.toHaveBeenCalled();
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
it('should skip Docker running check if Docker not installed', async () => {
|
|
337
|
+
process.env.DATABASE_URL = 'mongodb://localhost:27017/frigg';
|
|
338
|
+
mockDatabaseAdapter.getDatabaseType.mockReturnValue('mongodb');
|
|
339
|
+
mockDockerAdapter.isDockerInstalled.mockResolvedValue(false);
|
|
340
|
+
|
|
341
|
+
await useCase.execute({ projectPath: '/test/project' });
|
|
342
|
+
|
|
343
|
+
expect(mockDockerAdapter.isDockerRunning).not.toHaveBeenCalled();
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
it('should skip database reachable check if Docker not running', async () => {
|
|
347
|
+
process.env.DATABASE_URL = 'mongodb://localhost:27017/frigg';
|
|
348
|
+
mockDatabaseAdapter.getDatabaseType.mockReturnValue('mongodb');
|
|
349
|
+
mockDockerAdapter.isDockerInstalled.mockResolvedValue(true);
|
|
350
|
+
mockDockerAdapter.isDockerRunning.mockResolvedValue(false);
|
|
351
|
+
|
|
352
|
+
await useCase.execute({ projectPath: '/test/project' });
|
|
353
|
+
|
|
354
|
+
expect(mockDatabaseAdapter.isDatabaseReachable).not.toHaveBeenCalled();
|
|
355
|
+
});
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
describe('getFailedChecks()', () => {
|
|
359
|
+
it('should return only failed checks', async () => {
|
|
360
|
+
process.env.DATABASE_URL = 'mongodb://localhost:27017/frigg';
|
|
361
|
+
mockDatabaseAdapter.getDatabaseType.mockReturnValue('mongodb');
|
|
362
|
+
mockDockerAdapter.isDockerInstalled.mockResolvedValue(true);
|
|
363
|
+
mockDockerAdapter.isDockerRunning.mockResolvedValue(false);
|
|
364
|
+
|
|
365
|
+
const result = await useCase.execute({ projectPath: '/test/project' });
|
|
366
|
+
const failed = useCase.getFailedChecks(result);
|
|
367
|
+
|
|
368
|
+
expect(failed).toHaveLength(1);
|
|
369
|
+
expect(failed[0].name).toBe('docker_running');
|
|
370
|
+
});
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
describe('getResolvableChecks()', () => {
|
|
374
|
+
it('should return only checks that can be auto-resolved', async () => {
|
|
375
|
+
process.env.DATABASE_URL = 'mongodb://localhost:27017/frigg';
|
|
376
|
+
mockDatabaseAdapter.getDatabaseType.mockReturnValue('mongodb');
|
|
377
|
+
mockDockerAdapter.isDockerInstalled.mockResolvedValue(true);
|
|
378
|
+
mockDockerAdapter.isDockerRunning.mockResolvedValue(false);
|
|
379
|
+
|
|
380
|
+
const result = await useCase.execute({ projectPath: '/test/project' });
|
|
381
|
+
const resolvable = useCase.getResolvableChecks(result);
|
|
382
|
+
|
|
383
|
+
expect(resolvable).toHaveLength(1);
|
|
384
|
+
expect(resolvable[0].canResolve).toBe(true);
|
|
385
|
+
});
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
describe('Check result structure', () => {
|
|
389
|
+
it('should include all required fields in check results', async () => {
|
|
390
|
+
delete process.env.DATABASE_URL;
|
|
391
|
+
|
|
392
|
+
const result = await useCase.execute({ projectPath: '/test/project' });
|
|
393
|
+
|
|
394
|
+
const check = result.checks[0];
|
|
395
|
+
expect(check).toHaveProperty('name');
|
|
396
|
+
expect(check).toHaveProperty('status');
|
|
397
|
+
expect(check).toHaveProperty('message');
|
|
398
|
+
expect(check).toHaveProperty('canResolve');
|
|
399
|
+
expect(check).toHaveProperty('resolution');
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
it('should include resolution details for failed checks', async () => {
|
|
403
|
+
delete process.env.DATABASE_URL;
|
|
404
|
+
|
|
405
|
+
const result = await useCase.execute({ projectPath: '/test/project' });
|
|
406
|
+
|
|
407
|
+
const check = result.checks.find(c => c.name === 'database_url');
|
|
408
|
+
expect(check.resolution).toHaveProperty('type');
|
|
409
|
+
});
|
|
410
|
+
});
|
|
411
|
+
});
|