-
Notifications
You must be signed in to change notification settings - Fork 129
Expand file tree
/
Copy pathdatabase.spec.ts
More file actions
427 lines (353 loc) · 18.2 KB
/
database.spec.ts
File metadata and controls
427 lines (353 loc) · 18.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
import { test, expect } from '@playwright/test';
import { getBaseUrl, getTestDatabases } from '../config/urls';
import { HomePage } from '../logic/pom/homePage';
import BrowserWrapper from '../infra/ui/browserWrapper';
import ApiCalls from '../logic/api/apiCalls';
// Database connection tests - uses authenticated storageState from auth.setup
test.describe('Database Connection Tests', () => {
let browser: BrowserWrapper;
let apiCall: ApiCalls;
test.beforeEach(async ({ request }) => {
browser = new BrowserWrapper();
apiCall = new ApiCalls(request);
});
test.afterEach(async () => {
await browser.closeBrowser();
});
test('connect PostgreSQL via API -> verify in UI', { tag: '@requires-ai' }, async () => {
test.setTimeout(120000); // Allow extra time for schema loading in CI
const homePage = await browser.createNewPage(HomePage, getBaseUrl(), 'e2e/.auth/user.json');
await browser.setPageToFullScreen();
const { postgres: postgresUrl } = getTestDatabases();
// Connect via API - response is streaming (retry on transient errors)
const messages = await apiCall.connectDatabaseWithRetry(postgresUrl);
// Verify final message indicates success
expect(messages.length).toBeGreaterThan(0);
const finalMessage = messages[messages.length - 1];
if (finalMessage.type !== 'final_result') {
console.log(`[PostgreSQL API connect] unexpected final message: ${JSON.stringify(finalMessage)}`);
}
expect(finalMessage.type).toBe('final_result');
expect(finalMessage.success).toBeTruthy();
// Get the list of databases to find the connected database
const graphsList = await apiCall.waitForGraphs(
(graphs) => graphs.some((id) => id === 'testdb' || id.endsWith('_testdb')),
30000
);
expect(graphsList).toBeDefined();
expect(Array.isArray(graphsList)).toBeTruthy();
expect(graphsList.length).toBeGreaterThan(0);
console.log(`[PostgreSQL API connect] graphs after connection: ${JSON.stringify(graphsList)}`);
// Find the testdb database (not testdb_delete) - could be 'testdb' or 'userId_testdb'
const graphId = graphsList.find(id => id === 'testdb' || id.endsWith('_testdb'));
expect(graphId).toBeTruthy();
// Wait for UI to reflect the connection (schema loading completes)
const connectionEstablished = await homePage.waitForDatabaseConnection(90000);
expect(connectionEstablished).toBeTruthy();
// Verify connection appears in UI - check database status badge
const isConnected = await homePage.isDatabaseConnected();
expect(isConnected).toBeTruthy();
// Verify the selected database name matches the graph ID
const selectedDatabaseName = await homePage.getSelectedDatabaseName();
expect(selectedDatabaseName).toBe(graphId);
// Open database selector dropdown to verify the specific database appears in the list
await homePage.clickOnDatabaseSelector();
// Verify the specific database option is visible in the dropdown
const isDatabaseVisible = await homePage.isDatabaseInList(graphId!);
expect(isDatabaseVisible).toBeTruthy();
});
test('connect MySQL via API -> verify in UI', { tag: '@requires-ai' }, async () => {
test.setTimeout(120000); // Allow extra time for schema loading in CI
const homePage = await browser.createNewPage(HomePage, getBaseUrl(), 'e2e/.auth/user.json');
await browser.setPageToFullScreen();
const { mysql: mysqlUrl } = getTestDatabases();
// Connect via API - response is streaming (retry on transient errors)
const messages = await apiCall.connectDatabaseWithRetry(mysqlUrl);
// Verify final message indicates success
expect(messages.length).toBeGreaterThan(0);
const finalMessage = messages[messages.length - 1];
if (finalMessage.type !== 'final_result') {
console.log(`[MySQL API connect] unexpected final message: ${JSON.stringify(finalMessage)}`);
}
expect(finalMessage.type).toBe('final_result');
expect(finalMessage.success).toBeTruthy();
// Get the list of databases to find the connected database
const graphsList = await apiCall.waitForGraphs(
(graphs) => graphs.some((id) => id === 'testdb' || id.endsWith('_testdb')),
30000
);
expect(graphsList).toBeDefined();
expect(Array.isArray(graphsList)).toBeTruthy();
expect(graphsList.length).toBeGreaterThan(0);
console.log(`[MySQL API connect] graphs after connection: ${JSON.stringify(graphsList)}`);
// Find the testdb database (not testdb_delete) - could be 'testdb' or 'userId_testdb'
const graphId = graphsList.find(id => id === 'testdb' || id.endsWith('_testdb'));
expect(graphId).toBeTruthy();
// Wait for UI to reflect the connection (schema loading completes)
const connectionEstablished = await homePage.waitForDatabaseConnection(90000);
expect(connectionEstablished).toBeTruthy();
// Verify connection appears in UI - check database status badge
const isConnected = await homePage.isDatabaseConnected();
expect(isConnected).toBeTruthy();
// Verify the selected database name matches the graph ID
const selectedDatabaseName = await homePage.getSelectedDatabaseName();
expect(selectedDatabaseName).toBe(graphId);
// Open database selector dropdown to verify the specific database appears in the list
await homePage.clickOnDatabaseSelector();
// Verify the specific database option is visible in the dropdown
const isDatabaseVisible = await homePage.isDatabaseInList(graphId!);
expect(isDatabaseVisible).toBeTruthy();
});
test('connect PostgreSQL via UI (URL) -> verify via API', { tag: '@requires-ai' }, async () => {
test.setTimeout(120000); // Allow extra time for schema loading in CI
const homePage = await browser.createNewPage(HomePage, getBaseUrl(), 'e2e/.auth/user.json');
await browser.setPageToFullScreen();
const { postgres: postgresUrl } = getTestDatabases();
// Connect via UI using URL mode
await homePage.clickOnConnectDatabase();
await homePage.selectDatabaseType('postgresql');
await homePage.selectConnectionModeUrl();
await homePage.enterConnectionUrl(postgresUrl);
await homePage.clickOnDatabaseModalConnect();
// Wait for UI to reflect the connection (schema loading completes)
const connectionEstablished = await homePage.waitForDatabaseConnection(90000);
if (!connectionEstablished) {
console.log('[PostgreSQL URL connect] waitForDatabaseConnection timed out');
}
expect(connectionEstablished).toBeTruthy();
// Verify via API - poll until the expected testdb graph appears
const graphsList = await apiCall.waitForGraphs(
(graphs) => graphs.some((id) => id === 'testdb' || id.endsWith('_testdb')),
30000
);
expect(graphsList).toBeDefined();
expect(Array.isArray(graphsList)).toBeTruthy();
expect(graphsList.length).toBeGreaterThan(0);
console.log(`[PostgreSQL URL connect] graphs after connection: ${JSON.stringify(graphsList)}`);
// Get the connected database ID
const graphId = graphsList.find((id) => id === 'testdb' || id.endsWith('_testdb'));
expect(graphId).toBeTruthy();
// Verify connection appears in UI
const isConnected = await homePage.isDatabaseConnected();
expect(isConnected).toBeTruthy();
});
test('connect MySQL via UI (URL) -> verify via API', { tag: '@requires-ai' }, async () => {
test.setTimeout(120000); // Allow extra time for schema loading in CI
const homePage = await browser.createNewPage(HomePage, getBaseUrl(), 'e2e/.auth/user.json');
await browser.setPageToFullScreen();
const { mysql: mysqlUrl } = getTestDatabases();
// Connect via UI using URL mode
await homePage.clickOnConnectDatabase();
await homePage.selectDatabaseType('mysql');
await homePage.selectConnectionModeUrl();
await homePage.enterConnectionUrl(mysqlUrl);
await homePage.clickOnDatabaseModalConnect();
// Wait for UI to reflect the connection (schema loading completes)
const connectionEstablished = await homePage.waitForDatabaseConnection(90000);
if (!connectionEstablished) {
console.log('[MySQL URL connect] waitForDatabaseConnection timed out');
}
expect(connectionEstablished).toBeTruthy();
// Verify via API - poll until the expected testdb graph appears
const graphsList = await apiCall.waitForGraphs(
(graphs) => graphs.some((id) => id === 'testdb' || id.endsWith('_testdb')),
30000
);
expect(graphsList).toBeDefined();
expect(Array.isArray(graphsList)).toBeTruthy();
expect(graphsList.length).toBeGreaterThan(0);
console.log(`[MySQL URL connect] graphs after connection: ${JSON.stringify(graphsList)}`);
// Get the connected database ID
const graphId = graphsList.find((id) => id === 'testdb' || id.endsWith('_testdb'));
expect(graphId).toBeTruthy();
// Verify connection appears in UI
const isConnected = await homePage.isDatabaseConnected();
expect(isConnected).toBeTruthy();
});
test('connect PostgreSQL via UI (Manual Entry) -> verify via API', { tag: '@requires-ai' }, async () => {
test.setTimeout(120000); // Allow extra time for schema loading in CI
const homePage = await browser.createNewPage(HomePage, getBaseUrl(), 'e2e/.auth/user.json');
await browser.setPageToFullScreen();
// Connect via UI using manual entry mode
await homePage.clickOnConnectDatabase();
await homePage.selectDatabaseType('postgresql');
await homePage.selectConnectionModeManual();
await homePage.enterConnectionDetails(
'localhost',
'5432',
'testdb',
'postgres',
'postgres'
);
await homePage.clickOnDatabaseModalConnect();
// Wait for UI to reflect the connection (schema loading completes)
const connectionEstablished = await homePage.waitForDatabaseConnection(90000);
if (!connectionEstablished) {
console.log('[PostgreSQL Manual connect] waitForDatabaseConnection timed out');
}
expect(connectionEstablished).toBeTruthy();
// Verify via API - poll until the expected testdb graph appears
const graphsList = await apiCall.waitForGraphs(
(graphs) => graphs.some((id) => id === 'testdb' || id.endsWith('_testdb')),
30000
);
expect(graphsList).toBeDefined();
expect(Array.isArray(graphsList)).toBeTruthy();
expect(graphsList.length).toBeGreaterThan(0);
console.log(`[PostgreSQL Manual connect] graphs after connection: ${JSON.stringify(graphsList)}`);
// Get the connected database ID
const graphId = graphsList.find((id) => id === 'testdb' || id.endsWith('_testdb'));
expect(graphId).toBeTruthy();
// Verify connection appears in UI
const isConnected = await homePage.isDatabaseConnected();
expect(isConnected).toBeTruthy();
});
test('connect MySQL via UI (Manual Entry) -> verify via API', { tag: '@requires-ai' }, async () => {
test.setTimeout(120000); // Allow extra time for schema loading in CI
const homePage = await browser.createNewPage(HomePage, getBaseUrl(), 'e2e/.auth/user.json');
await browser.setPageToFullScreen();
// Connect via UI using manual entry mode
await homePage.clickOnConnectDatabase();
await homePage.selectDatabaseType('mysql');
await homePage.selectConnectionModeManual();
await homePage.enterConnectionDetails(
'localhost',
'3306',
'testdb',
'root',
'password'
);
await homePage.clickOnDatabaseModalConnect();
// Wait for UI to reflect the connection (schema loading completes)
const connectionEstablished = await homePage.waitForDatabaseConnection(90000);
if (!connectionEstablished) {
console.log('[MySQL Manual connect] waitForDatabaseConnection timed out');
}
expect(connectionEstablished).toBeTruthy();
// Verify via API - poll until the expected testdb graph appears
const graphsList = await apiCall.waitForGraphs(
(graphs) => graphs.some((id) => id === 'testdb' || id.endsWith('_testdb')),
30000
);
expect(graphsList).toBeDefined();
expect(Array.isArray(graphsList)).toBeTruthy();
expect(graphsList.length).toBeGreaterThan(0);
console.log(`[MySQL Manual connect] graphs after connection: ${JSON.stringify(graphsList)}`);
// Get the connected database ID
const graphId = graphsList.find((id) => id === 'testdb' || id.endsWith('_testdb'));
expect(graphId).toBeTruthy();
// Verify connection appears in UI
const isConnected = await homePage.isDatabaseConnected();
expect(isConnected).toBeTruthy();
});
test('invalid connection string -> shows error', async () => {
const homePage = await browser.createNewPage(HomePage, getBaseUrl(), 'e2e/.auth/user.json');
await browser.setPageToFullScreen();
const invalidUrl = 'invalid://connection:string';
// Attempt connection via UI
await homePage.clickOnConnectDatabase();
// Select database type (PostgreSQL)
await homePage.selectDatabaseType('postgresql');
// Select URL connection mode
await homePage.selectConnectionModeUrl();
// Enter invalid connection URL
await homePage.enterConnectionUrl(invalidUrl);
// Click connect button
await homePage.clickOnDatabaseModalConnect();
// Verify the invalid database does not appear in the dropdown
// Get the list of databases to verify nothing was connected
const graphsList = await apiCall.getGraphs();
expect(graphsList).not.toContain(invalidUrl);
});
// Delete tests run serially to avoid conflicts
test.describe.serial('Database Deletion Tests', () => {
test('delete PostgreSQL database via UI -> verify removed via API', { tag: '@requires-ai' }, async () => {
test.setTimeout(180000); // Allow extra time: schema loading + UI interaction
// Use the separate postgres delete container on port 5433
const postgresDeleteUrl = 'postgresql://postgres:postgres@localhost:5433/testdb_delete';
// Connect database via API (retry on transient errors)
const connectMessages = await apiCall.connectDatabaseWithRetry(postgresDeleteUrl);
expect(connectMessages.length).toBeGreaterThan(0);
const finalMessage = connectMessages[connectMessages.length - 1];
if (finalMessage.type !== 'final_result') {
console.log(`[PostgreSQL delete connect] unexpected final message: ${JSON.stringify(finalMessage)}`);
}
expect(finalMessage.type).toBe('final_result');
expect(finalMessage.success).toBeTruthy();
// Poll until the graph appears in the API
let graphsList = await apiCall.waitForGraphs(
(graphs) => graphs.some((id) => id === 'testdb_delete' || id.endsWith('_testdb_delete')),
30000
);
expect(graphsList.length).toBeGreaterThan(0);
// Find the graph that is 'testdb_delete' or '{userId}_testdb_delete'
const graphId = graphsList.find(id => id === 'testdb_delete' || id.endsWith('_testdb_delete'));
if (!graphId) {
console.log('[PostgreSQL delete] Available graphs:', graphsList);
console.log('[PostgreSQL delete] Looking for graph containing: testdb_delete');
}
expect(graphId).toBeTruthy();
const initialCount = graphsList.length;
// Create new page and open it
const homePage = await browser.createNewPage(HomePage, getBaseUrl(), 'e2e/.auth/user.json');
await browser.setPageToFullScreen();
// Delete via UI - open dropdown, click delete, confirm
await homePage.clickOnDatabaseSelector();
await homePage.clickOnDeleteGraph(graphId!);
await homePage.clickOnDeleteModalConfirm();
// Wait for deletion to complete - poll until graphId is absent (up to 30s)
graphsList = await apiCall.waitForGraphs(
(graphs) => !graphs.some((id) => id === graphId),
30000
);
expect(graphsList.length).toBe(initialCount - 1);
expect(graphsList).not.toContain(graphId);
});
test('delete MySQL database via UI -> verify removed via API', { tag: '@requires-ai' }, async () => {
test.setTimeout(180000); // Allow extra time: schema loading + UI interaction
// Use the separate mysql delete container on port 3307
const mysqlDeleteUrl = 'mysql://root:password@localhost:3307/testdb_delete';
// Connect database via API (retry on transient errors)
const connectMessages = await apiCall.connectDatabaseWithRetry(mysqlDeleteUrl);
expect(connectMessages.length).toBeGreaterThan(0);
const finalMessage = connectMessages[connectMessages.length - 1];
if (finalMessage.type !== 'final_result') {
console.log(`[MySQL delete connect] unexpected final message: ${JSON.stringify(finalMessage)}`);
}
expect(finalMessage.type).toBe('final_result');
expect(finalMessage.success).toBeTruthy();
// Poll until the graph appears in the API
let graphsList = await apiCall.waitForGraphs(
(graphs) => graphs.some((id) => id === 'testdb_delete' || id.endsWith('_testdb_delete')),
30000
);
expect(graphsList.length).toBeGreaterThan(0);
const graphId = graphsList.find(id => id === 'testdb_delete' || id.endsWith('_testdb_delete'));
if (!graphId) {
console.log('[MySQL delete] Available graphs:', graphsList);
console.log('[MySQL delete] Looking for graph containing: testdb_delete');
}
expect(graphId).toBeTruthy();
const initialCount = graphsList.length;
const homePage = await browser.createNewPage(HomePage, getBaseUrl(), 'e2e/.auth/user.json');
await browser.setPageToFullScreen();
// Wait for UI to reflect the connection (increased timeout for schema loading)
const connectionEstablished = await homePage.waitForDatabaseConnection(90000);
if (!connectionEstablished) {
console.log('[MySQL delete] waitForDatabaseConnection timed out');
}
expect(connectionEstablished).toBeTruthy();
// Delete via UI - open dropdown, click delete, confirm
await homePage.clickOnDatabaseSelector();
await homePage.clickOnDeleteGraph(graphId!);
await homePage.clickOnDeleteModalConfirm();
// Wait for deletion to complete - poll until graphId is absent (up to 30s)
graphsList = await apiCall.waitForGraphs(
(graphs) => !graphs.some((id) => id === graphId),
30000
);
expect(graphsList.length).toBe(initialCount - 1);
expect(graphsList).not.toContain(graphId);
});
});
});