@friggframework/devtools 2.0.0--canary.546.74db90f.0 → 2.0.0--canary.545.e7becd9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/frigg-cli/README.md +1 -1
- package/frigg-cli/__tests__/application/use-cases/AddApiModuleToIntegrationUseCase.test.js +326 -0
- package/frigg-cli/__tests__/application/use-cases/CreateApiModuleUseCase.test.js +337 -0
- package/frigg-cli/__tests__/domain/entities/ApiModule.test.js +373 -0
- package/frigg-cli/__tests__/domain/entities/AppDefinition.test.js +313 -0
- package/frigg-cli/__tests__/domain/services/IntegrationValidator.test.js +269 -0
- package/frigg-cli/__tests__/domain/value-objects/IntegrationName.test.js +82 -0
- package/frigg-cli/__tests__/infrastructure/adapters/IntegrationJsUpdater.test.js +408 -0
- package/frigg-cli/__tests__/infrastructure/repositories/FileSystemApiModuleRepository.test.js +583 -0
- package/frigg-cli/__tests__/infrastructure/repositories/FileSystemAppDefinitionRepository.test.js +314 -0
- package/frigg-cli/__tests__/infrastructure/repositories/FileSystemIntegrationRepository.test.js +383 -0
- package/frigg-cli/__tests__/unit/commands/build.test.js +1 -1
- package/frigg-cli/__tests__/unit/commands/doctor.test.js +0 -2
- package/frigg-cli/__tests__/unit/commands/init.test.js +406 -0
- package/frigg-cli/__tests__/unit/commands/install.test.js +23 -19
- package/frigg-cli/__tests__/unit/commands/provider-dispatch.test.js +383 -0
- package/frigg-cli/__tests__/unit/commands/repair.test.js +275 -0
- package/frigg-cli/__tests__/unit/dependencies.test.js +2 -2
- package/frigg-cli/__tests__/unit/start-command/application/RunPreflightChecksUseCase.test.js +411 -0
- package/frigg-cli/__tests__/unit/start-command/infrastructure/DatabaseAdapter.test.js +405 -0
- package/frigg-cli/__tests__/unit/start-command/infrastructure/DockerAdapter.test.js +496 -0
- package/frigg-cli/__tests__/unit/start-command/presentation/InteractivePromptAdapter.test.js +474 -0
- package/frigg-cli/__tests__/unit/utils/output.test.js +196 -0
- package/frigg-cli/application/use-cases/AddApiModuleToIntegrationUseCase.js +93 -0
- package/frigg-cli/application/use-cases/CreateApiModuleUseCase.js +93 -0
- package/frigg-cli/application/use-cases/CreateIntegrationUseCase.js +103 -0
- package/frigg-cli/build-command/index.js +123 -11
- package/frigg-cli/container.js +172 -0
- package/frigg-cli/deploy-command/index.js +83 -1
- package/frigg-cli/docs/OUTPUT_MIGRATION_GUIDE.md +286 -0
- package/frigg-cli/doctor-command/index.js +37 -16
- package/frigg-cli/domain/entities/ApiModule.js +272 -0
- package/frigg-cli/domain/entities/AppDefinition.js +227 -0
- package/frigg-cli/domain/entities/Integration.js +198 -0
- package/frigg-cli/domain/exceptions/DomainException.js +24 -0
- package/frigg-cli/domain/ports/IApiModuleRepository.js +53 -0
- package/frigg-cli/domain/ports/IAppDefinitionRepository.js +43 -0
- package/frigg-cli/domain/ports/IIntegrationRepository.js +61 -0
- package/frigg-cli/domain/services/IntegrationValidator.js +185 -0
- package/frigg-cli/domain/value-objects/IntegrationId.js +42 -0
- package/frigg-cli/domain/value-objects/IntegrationName.js +60 -0
- package/frigg-cli/domain/value-objects/SemanticVersion.js +70 -0
- package/frigg-cli/generate-iam-command.js +21 -1
- package/frigg-cli/index.js +21 -6
- package/frigg-cli/index.test.js +7 -2
- package/frigg-cli/infrastructure/UnitOfWork.js +46 -0
- package/frigg-cli/infrastructure/adapters/BackendJsUpdater.js +197 -0
- package/frigg-cli/infrastructure/adapters/FileSystemAdapter.js +224 -0
- package/frigg-cli/infrastructure/adapters/IntegrationJsUpdater.js +249 -0
- package/frigg-cli/infrastructure/adapters/SchemaValidator.js +92 -0
- package/frigg-cli/infrastructure/repositories/FileSystemApiModuleRepository.js +373 -0
- package/frigg-cli/infrastructure/repositories/FileSystemAppDefinitionRepository.js +116 -0
- package/frigg-cli/infrastructure/repositories/FileSystemIntegrationRepository.js +277 -0
- package/frigg-cli/init-command/backend-first-handler.js +124 -42
- package/frigg-cli/init-command/index.js +2 -1
- package/frigg-cli/init-command/template-handler.js +13 -3
- package/frigg-cli/install-command/backend-js.js +3 -3
- package/frigg-cli/install-command/environment-variables.js +16 -19
- package/frigg-cli/install-command/environment-variables.test.js +12 -13
- package/frigg-cli/install-command/index.js +14 -9
- package/frigg-cli/install-command/integration-file.js +3 -3
- package/frigg-cli/install-command/validate-package.js +5 -9
- package/frigg-cli/jest.config.js +4 -1
- package/frigg-cli/package-lock.json +16226 -0
- package/frigg-cli/repair-command/index.js +121 -128
- package/frigg-cli/start-command/application/RunPreflightChecksUseCase.js +376 -0
- package/frigg-cli/start-command/index.js +324 -2
- package/frigg-cli/start-command/infrastructure/DatabaseAdapter.js +591 -0
- package/frigg-cli/start-command/infrastructure/DockerAdapter.js +306 -0
- package/frigg-cli/start-command/presentation/InteractivePromptAdapter.js +329 -0
- package/frigg-cli/templates/backend/.env.example +62 -0
- package/frigg-cli/templates/backend/.eslintrc.json +12 -0
- package/frigg-cli/templates/backend/.prettierrc +6 -0
- package/frigg-cli/templates/backend/docker-compose.yml +22 -0
- package/frigg-cli/templates/backend/index.js +96 -0
- package/frigg-cli/templates/backend/infrastructure.js +12 -0
- package/frigg-cli/templates/backend/jest.config.js +17 -0
- package/frigg-cli/templates/backend/package.json +50 -0
- package/frigg-cli/templates/backend/src/api-modules/.gitkeep +10 -0
- package/frigg-cli/templates/backend/src/base/.gitkeep +7 -0
- package/frigg-cli/templates/backend/src/integrations/.gitkeep +10 -0
- package/frigg-cli/templates/backend/src/integrations/ExampleIntegration.js +65 -0
- package/frigg-cli/templates/backend/src/utils/.gitkeep +7 -0
- package/frigg-cli/templates/backend/test/setup.js +30 -0
- package/frigg-cli/templates/backend/ui-extensions/.gitkeep +0 -0
- package/frigg-cli/templates/backend/ui-extensions/README.md +77 -0
- package/frigg-cli/ui-command/index.js +58 -36
- package/frigg-cli/utils/__tests__/provider-helper.test.js +55 -0
- package/frigg-cli/utils/__tests__/repo-detection.test.js +436 -0
- package/frigg-cli/utils/output.js +382 -0
- package/frigg-cli/utils/provider-helper.js +75 -0
- package/frigg-cli/utils/repo-detection.js +85 -37
- package/frigg-cli/validate-command/__tests__/adapters/validate-command.test.js +205 -0
- package/frigg-cli/validate-command/__tests__/application/validate-app-use-case.test.js +104 -0
- package/frigg-cli/validate-command/__tests__/domain/fix-suggestion.test.js +153 -0
- package/frigg-cli/validate-command/__tests__/domain/validation-error.test.js +162 -0
- package/frigg-cli/validate-command/__tests__/domain/validation-result.test.js +152 -0
- package/frigg-cli/validate-command/__tests__/infrastructure/api-module-validator.test.js +332 -0
- package/frigg-cli/validate-command/__tests__/infrastructure/app-definition-validator.test.js +191 -0
- package/frigg-cli/validate-command/__tests__/infrastructure/integration-class-validator.test.js +146 -0
- package/frigg-cli/validate-command/__tests__/infrastructure/template-validation.test.js +155 -0
- package/frigg-cli/validate-command/adapters/cli/validate-command.js +199 -0
- package/frigg-cli/validate-command/application/use-cases/validate-app-use-case.js +35 -0
- package/frigg-cli/validate-command/domain/entities/validation-result.js +74 -0
- package/frigg-cli/validate-command/domain/value-objects/fix-suggestion.js +74 -0
- package/frigg-cli/validate-command/domain/value-objects/validation-error.js +68 -0
- package/frigg-cli/validate-command/infrastructure/validators/api-module-validator.js +181 -0
- package/frigg-cli/validate-command/infrastructure/validators/app-definition-validator.js +128 -0
- package/frigg-cli/validate-command/infrastructure/validators/integration-class-validator.js +113 -0
- package/infrastructure/create-frigg-infrastructure.js +93 -0
- package/infrastructure/docs/iam-policy-templates.md +1 -1
- package/infrastructure/domains/admin-scripts/admin-script-builder.js +200 -0
- package/infrastructure/domains/admin-scripts/admin-script-builder.test.js +499 -0
- package/infrastructure/domains/admin-scripts/index.js +5 -0
- package/infrastructure/domains/networking/vpc-builder.test.js +2 -4
- package/infrastructure/domains/networking/vpc-resolver.test.js +1 -1
- package/infrastructure/domains/shared/cloudformation-discovery.test.js +4 -7
- package/infrastructure/domains/shared/resource-discovery.js +5 -5
- package/infrastructure/domains/shared/types/app-definition.js +21 -0
- package/infrastructure/domains/shared/types/discovery-result.test.js +1 -1
- package/infrastructure/domains/shared/utilities/base-definition-factory.js +10 -1
- package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +2 -2
- package/infrastructure/infrastructure-composer.js +2 -0
- package/infrastructure/infrastructure-composer.test.js +2 -2
- package/infrastructure/jest.config.js +16 -0
- package/management-ui/README.md +245 -109
- package/package.json +8 -7
- package/frigg-cli/install-command/logger.js +0 -12
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DatabaseAdapter Tests
|
|
3
|
+
* Infrastructure adapter for database connectivity checks
|
|
4
|
+
*
|
|
5
|
+
* Tests follow TDD pattern - written BEFORE implementation
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// Mock net module for TCP connection testing
|
|
9
|
+
jest.mock('net', () => ({
|
|
10
|
+
createConnection: jest.fn()
|
|
11
|
+
}));
|
|
12
|
+
|
|
13
|
+
const net = require('net');
|
|
14
|
+
|
|
15
|
+
// Import after mocks
|
|
16
|
+
const { DatabaseAdapter } = require('../../../../start-command/infrastructure/DatabaseAdapter');
|
|
17
|
+
|
|
18
|
+
describe('DatabaseAdapter', () => {
|
|
19
|
+
let adapter;
|
|
20
|
+
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
jest.clearAllMocks();
|
|
23
|
+
adapter = new DatabaseAdapter();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe('parseConnectionString()', () => {
|
|
27
|
+
describe('MongoDB connection strings', () => {
|
|
28
|
+
it('should parse mongodb:// connection string', () => {
|
|
29
|
+
const url = 'mongodb://localhost:27017/frigg';
|
|
30
|
+
const result = adapter.parseConnectionString(url);
|
|
31
|
+
|
|
32
|
+
expect(result.type).toBe('mongodb');
|
|
33
|
+
expect(result.host).toBe('localhost');
|
|
34
|
+
expect(result.port).toBe(27017);
|
|
35
|
+
expect(result.database).toBe('frigg');
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('should parse mongodb+srv:// connection string', () => {
|
|
39
|
+
const url = 'mongodb+srv://cluster.mongodb.net/frigg';
|
|
40
|
+
const result = adapter.parseConnectionString(url);
|
|
41
|
+
|
|
42
|
+
expect(result.type).toBe('mongodb');
|
|
43
|
+
expect(result.host).toBe('cluster.mongodb.net');
|
|
44
|
+
expect(result.port).toBe(27017); // Default MongoDB port
|
|
45
|
+
expect(result.database).toBe('frigg');
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('should parse mongodb connection with authentication', () => {
|
|
49
|
+
const url = 'mongodb://user:password@localhost:27017/frigg?authSource=admin';
|
|
50
|
+
const result = adapter.parseConnectionString(url);
|
|
51
|
+
|
|
52
|
+
expect(result.type).toBe('mongodb');
|
|
53
|
+
expect(result.host).toBe('localhost');
|
|
54
|
+
expect(result.port).toBe(27017);
|
|
55
|
+
expect(result.database).toBe('frigg');
|
|
56
|
+
expect(result.user).toBe('user');
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('should use default port 27017 for mongodb without port', () => {
|
|
60
|
+
const url = 'mongodb://localhost/frigg';
|
|
61
|
+
const result = adapter.parseConnectionString(url);
|
|
62
|
+
|
|
63
|
+
expect(result.port).toBe(27017);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('should handle replica set connection string', () => {
|
|
67
|
+
const url = 'mongodb://mongo1:27017,mongo2:27017,mongo3:27017/frigg?replicaSet=rs0';
|
|
68
|
+
const result = adapter.parseConnectionString(url);
|
|
69
|
+
|
|
70
|
+
expect(result.type).toBe('mongodb');
|
|
71
|
+
expect(result.host).toBe('mongo1'); // First host
|
|
72
|
+
expect(result.port).toBe(27017);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
describe('PostgreSQL connection strings', () => {
|
|
77
|
+
it('should parse postgresql:// connection string', () => {
|
|
78
|
+
const url = 'postgresql://localhost:5432/frigg';
|
|
79
|
+
const result = adapter.parseConnectionString(url);
|
|
80
|
+
|
|
81
|
+
expect(result.type).toBe('postgresql');
|
|
82
|
+
expect(result.host).toBe('localhost');
|
|
83
|
+
expect(result.port).toBe(5432);
|
|
84
|
+
expect(result.database).toBe('frigg');
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('should parse postgres:// connection string (alias)', () => {
|
|
88
|
+
const url = 'postgres://localhost:5432/frigg';
|
|
89
|
+
const result = adapter.parseConnectionString(url);
|
|
90
|
+
|
|
91
|
+
expect(result.type).toBe('postgresql');
|
|
92
|
+
expect(result.host).toBe('localhost');
|
|
93
|
+
expect(result.port).toBe(5432);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('should parse postgresql connection with authentication', () => {
|
|
97
|
+
const url = 'postgresql://user:password@localhost:5432/frigg?schema=public';
|
|
98
|
+
const result = adapter.parseConnectionString(url);
|
|
99
|
+
|
|
100
|
+
expect(result.type).toBe('postgresql');
|
|
101
|
+
expect(result.host).toBe('localhost');
|
|
102
|
+
expect(result.port).toBe(5432);
|
|
103
|
+
expect(result.user).toBe('user');
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('should use default port 5432 for postgresql without port', () => {
|
|
107
|
+
const url = 'postgresql://localhost/frigg';
|
|
108
|
+
const result = adapter.parseConnectionString(url);
|
|
109
|
+
|
|
110
|
+
expect(result.port).toBe(5432);
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
describe('Invalid connection strings', () => {
|
|
115
|
+
it('should return error for unknown protocol', () => {
|
|
116
|
+
const url = 'mysql://localhost:3306/frigg';
|
|
117
|
+
const result = adapter.parseConnectionString(url);
|
|
118
|
+
|
|
119
|
+
expect(result.error).toBeDefined();
|
|
120
|
+
expect(result.error).toContain('Unsupported database type');
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('should return error for malformed URL', () => {
|
|
124
|
+
const url = 'not-a-valid-url';
|
|
125
|
+
const result = adapter.parseConnectionString(url);
|
|
126
|
+
|
|
127
|
+
expect(result.error).toBeDefined();
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it('should return error for empty string', () => {
|
|
131
|
+
const result = adapter.parseConnectionString('');
|
|
132
|
+
|
|
133
|
+
expect(result.error).toBeDefined();
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('should return error for null', () => {
|
|
137
|
+
const result = adapter.parseConnectionString(null);
|
|
138
|
+
|
|
139
|
+
expect(result.error).toBeDefined();
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
describe('getDatabaseType()', () => {
|
|
145
|
+
it('should return mongodb for mongodb:// URLs', () => {
|
|
146
|
+
const url = 'mongodb://localhost:27017/frigg';
|
|
147
|
+
const result = adapter.getDatabaseType(url);
|
|
148
|
+
|
|
149
|
+
expect(result).toBe('mongodb');
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it('should return mongodb for mongodb+srv:// URLs', () => {
|
|
153
|
+
const url = 'mongodb+srv://cluster.mongodb.net/frigg';
|
|
154
|
+
const result = adapter.getDatabaseType(url);
|
|
155
|
+
|
|
156
|
+
expect(result).toBe('mongodb');
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it('should return postgresql for postgresql:// URLs', () => {
|
|
160
|
+
const url = 'postgresql://localhost:5432/frigg';
|
|
161
|
+
const result = adapter.getDatabaseType(url);
|
|
162
|
+
|
|
163
|
+
expect(result).toBe('postgresql');
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it('should return postgresql for postgres:// URLs', () => {
|
|
167
|
+
const url = 'postgres://localhost:5432/frigg';
|
|
168
|
+
const result = adapter.getDatabaseType(url);
|
|
169
|
+
|
|
170
|
+
expect(result).toBe('postgresql');
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it('should return null for unknown database types', () => {
|
|
174
|
+
const url = 'mysql://localhost:3306/frigg';
|
|
175
|
+
const result = adapter.getDatabaseType(url);
|
|
176
|
+
|
|
177
|
+
expect(result).toBeNull();
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
describe('isPortReachable()', () => {
|
|
182
|
+
let mockSocket;
|
|
183
|
+
|
|
184
|
+
beforeEach(() => {
|
|
185
|
+
mockSocket = {
|
|
186
|
+
on: jest.fn(),
|
|
187
|
+
destroy: jest.fn(),
|
|
188
|
+
setTimeout: jest.fn()
|
|
189
|
+
};
|
|
190
|
+
net.createConnection.mockReturnValue(mockSocket);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it('should return true when port is reachable', async () => {
|
|
194
|
+
// Simulate successful connection
|
|
195
|
+
mockSocket.on.mockImplementation((event, callback) => {
|
|
196
|
+
if (event === 'connect') {
|
|
197
|
+
setTimeout(() => callback(), 10);
|
|
198
|
+
}
|
|
199
|
+
return mockSocket;
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
const result = await adapter.isPortReachable('localhost', 27017);
|
|
203
|
+
|
|
204
|
+
expect(result).toBe(true);
|
|
205
|
+
expect(mockSocket.destroy).toHaveBeenCalled();
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
it('should return false when connection is refused', async () => {
|
|
209
|
+
// Simulate connection refused
|
|
210
|
+
mockSocket.on.mockImplementation((event, callback) => {
|
|
211
|
+
if (event === 'error') {
|
|
212
|
+
setTimeout(() => callback(new Error('ECONNREFUSED')), 10);
|
|
213
|
+
}
|
|
214
|
+
return mockSocket;
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
const result = await adapter.isPortReachable('localhost', 27017);
|
|
218
|
+
|
|
219
|
+
expect(result).toBe(false);
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
it('should return false when connection times out', async () => {
|
|
223
|
+
// Simulate timeout
|
|
224
|
+
mockSocket.on.mockImplementation((event, callback) => {
|
|
225
|
+
if (event === 'timeout') {
|
|
226
|
+
setTimeout(() => callback(), 10);
|
|
227
|
+
}
|
|
228
|
+
return mockSocket;
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
const result = await adapter.isPortReachable('localhost', 27017, 100);
|
|
232
|
+
|
|
233
|
+
expect(result).toBe(false);
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
it('should use custom timeout value', async () => {
|
|
237
|
+
mockSocket.on.mockImplementation((event, callback) => {
|
|
238
|
+
if (event === 'connect') {
|
|
239
|
+
setTimeout(() => callback(), 10);
|
|
240
|
+
}
|
|
241
|
+
return mockSocket;
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
await adapter.isPortReachable('localhost', 27017, 5000);
|
|
245
|
+
|
|
246
|
+
expect(mockSocket.setTimeout).toHaveBeenCalledWith(5000);
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
it('should use default timeout of 3000ms', async () => {
|
|
250
|
+
mockSocket.on.mockImplementation((event, callback) => {
|
|
251
|
+
if (event === 'connect') {
|
|
252
|
+
setTimeout(() => callback(), 10);
|
|
253
|
+
}
|
|
254
|
+
return mockSocket;
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
await adapter.isPortReachable('localhost', 27017);
|
|
258
|
+
|
|
259
|
+
expect(mockSocket.setTimeout).toHaveBeenCalledWith(3000);
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
describe('isDatabaseReachable()', () => {
|
|
264
|
+
let mockSocket;
|
|
265
|
+
|
|
266
|
+
beforeEach(() => {
|
|
267
|
+
mockSocket = {
|
|
268
|
+
on: jest.fn(),
|
|
269
|
+
destroy: jest.fn(),
|
|
270
|
+
setTimeout: jest.fn()
|
|
271
|
+
};
|
|
272
|
+
net.createConnection.mockReturnValue(mockSocket);
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
it('should return reachable: true when database port is open', async () => {
|
|
276
|
+
// Simulate successful connection
|
|
277
|
+
mockSocket.on.mockImplementation((event, callback) => {
|
|
278
|
+
if (event === 'connect') {
|
|
279
|
+
setTimeout(() => callback(), 10);
|
|
280
|
+
}
|
|
281
|
+
return mockSocket;
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
const result = await adapter.isDatabaseReachable('mongodb://localhost:27017/frigg');
|
|
285
|
+
|
|
286
|
+
expect(result.reachable).toBe(true);
|
|
287
|
+
expect(result.host).toBe('localhost');
|
|
288
|
+
expect(result.port).toBe(27017);
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
it('should return reachable: false when database port is closed', async () => {
|
|
292
|
+
mockSocket.on.mockImplementation((event, callback) => {
|
|
293
|
+
if (event === 'error') {
|
|
294
|
+
setTimeout(() => callback(new Error('ECONNREFUSED')), 10);
|
|
295
|
+
}
|
|
296
|
+
return mockSocket;
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
const result = await adapter.isDatabaseReachable('mongodb://localhost:27017/frigg');
|
|
300
|
+
|
|
301
|
+
expect(result.reachable).toBe(false);
|
|
302
|
+
expect(result.error).toContain('ECONNREFUSED');
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
it('should return error for invalid connection string', async () => {
|
|
306
|
+
const result = await adapter.isDatabaseReachable('not-valid');
|
|
307
|
+
|
|
308
|
+
expect(result.reachable).toBe(false);
|
|
309
|
+
expect(result.error).toBeDefined();
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
it('should include database type in result', async () => {
|
|
313
|
+
mockSocket.on.mockImplementation((event, callback) => {
|
|
314
|
+
if (event === 'connect') {
|
|
315
|
+
setTimeout(() => callback(), 10);
|
|
316
|
+
}
|
|
317
|
+
return mockSocket;
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
const result = await adapter.isDatabaseReachable('postgresql://localhost:5432/frigg');
|
|
321
|
+
|
|
322
|
+
expect(result.type).toBe('postgresql');
|
|
323
|
+
});
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
describe('getConnectionDetails()', () => {
|
|
327
|
+
it('should extract all connection details from MongoDB URL', () => {
|
|
328
|
+
const url = 'mongodb://user:pass@localhost:27017/frigg?replicaSet=rs0';
|
|
329
|
+
const result = adapter.getConnectionDetails(url);
|
|
330
|
+
|
|
331
|
+
expect(result).toEqual({
|
|
332
|
+
type: 'mongodb',
|
|
333
|
+
host: 'localhost',
|
|
334
|
+
port: 27017,
|
|
335
|
+
database: 'frigg',
|
|
336
|
+
user: 'user',
|
|
337
|
+
hasCredentials: true
|
|
338
|
+
});
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
it('should extract all connection details from PostgreSQL URL', () => {
|
|
342
|
+
const url = 'postgresql://user:pass@localhost:5432/frigg?schema=public';
|
|
343
|
+
const result = adapter.getConnectionDetails(url);
|
|
344
|
+
|
|
345
|
+
expect(result).toEqual({
|
|
346
|
+
type: 'postgresql',
|
|
347
|
+
host: 'localhost',
|
|
348
|
+
port: 5432,
|
|
349
|
+
database: 'frigg',
|
|
350
|
+
user: 'user',
|
|
351
|
+
hasCredentials: true
|
|
352
|
+
});
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
it('should indicate no credentials when not provided', () => {
|
|
356
|
+
const url = 'mongodb://localhost:27017/frigg';
|
|
357
|
+
const result = adapter.getConnectionDetails(url);
|
|
358
|
+
|
|
359
|
+
expect(result.hasCredentials).toBe(false);
|
|
360
|
+
expect(result.user).toBeUndefined();
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
it('should return error object for invalid URL', () => {
|
|
364
|
+
const result = adapter.getConnectionDetails('invalid');
|
|
365
|
+
|
|
366
|
+
expect(result.error).toBeDefined();
|
|
367
|
+
});
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
describe('suggestDockerService()', () => {
|
|
371
|
+
it('should suggest mongodb service for MongoDB database', () => {
|
|
372
|
+
const result = adapter.suggestDockerService('mongodb');
|
|
373
|
+
|
|
374
|
+
expect(result).toEqual({
|
|
375
|
+
serviceName: 'mongodb',
|
|
376
|
+
image: 'mongo:7',
|
|
377
|
+
port: 27017,
|
|
378
|
+
envVars: expect.objectContaining({
|
|
379
|
+
MONGO_INITDB_DATABASE: 'frigg'
|
|
380
|
+
})
|
|
381
|
+
});
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
it('should suggest postgres service for PostgreSQL database', () => {
|
|
385
|
+
const result = adapter.suggestDockerService('postgresql');
|
|
386
|
+
|
|
387
|
+
expect(result).toEqual({
|
|
388
|
+
serviceName: 'postgres',
|
|
389
|
+
image: 'postgres:16',
|
|
390
|
+
port: 5432,
|
|
391
|
+
envVars: expect.objectContaining({
|
|
392
|
+
POSTGRES_DB: 'frigg',
|
|
393
|
+
POSTGRES_USER: expect.any(String),
|
|
394
|
+
POSTGRES_PASSWORD: expect.any(String)
|
|
395
|
+
})
|
|
396
|
+
});
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
it('should return null for unknown database type', () => {
|
|
400
|
+
const result = adapter.suggestDockerService('mysql');
|
|
401
|
+
|
|
402
|
+
expect(result).toBeNull();
|
|
403
|
+
});
|
|
404
|
+
});
|
|
405
|
+
});
|