Skip to content

Commit 2b516c6

Browse files
author
Matthew Valancy
committed
fix: make E2E tests environment-aware for HTTPS deployment
- Add getBaseURL() and getAPIURL() helpers for dynamic URL resolution - Fix all navigation to use full URLs with baseURL instead of relative paths - Update database connectivity tests to detect HTTPS/HTTP environment - Tests now work with both dev (HTTP) and production (HTTPS) deployments
1 parent 9ca6eea commit 2b516c6

2 files changed

Lines changed: 42 additions & 16 deletions

File tree

tests/e2e/database-connectivity.spec.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { test, expect } from '@playwright/test';
2+
import { getBaseURL, getAPIURL } from '../helpers/auth';
23

34
test.describe('Database Connectivity Validation', () => {
45
test('should fail properly when Neo4j is unavailable', async ({ page }) => {
56
// This test ensures we properly detect and report database failures
67
// rather than silently falling back to auth-only mode
7-
8+
const apiURL = getAPIURL();
9+
810
// Navigate to GraphQL endpoint
9-
await page.goto('http://localhost:4127/graphql');
11+
await page.goto(`${apiURL}/graphql`);
1012

1113
// Check if we're in auth-only mode by looking for error indicators
1214
const pageContent = await page.content();
@@ -18,9 +20,9 @@ test.describe('Database Connectivity Validation', () => {
1820

1921
if (hasGraphQLPlayground) {
2022
// Database appears to be working, verify with actual query
21-
const response = await page.evaluate(async () => {
23+
const response = await page.evaluate(async (apiEndpoint) => {
2224
try {
23-
const result = await fetch('http://localhost:4127/graphql', {
25+
const result = await fetch(`${apiEndpoint}/graphql`, {
2426
method: 'POST',
2527
headers: { 'Content-Type': 'application/json' },
2628
body: JSON.stringify({
@@ -29,9 +31,9 @@ test.describe('Database Connectivity Validation', () => {
2931
});
3032
return await result.json();
3133
} catch (error) {
32-
return { error: error.message };
34+
return { error: (error as Error).message };
3335
}
34-
});
36+
}, apiURL);
3537

3638
// Should either return data or a proper error (not silent failure)
3739
expect(response).toBeDefined();
@@ -60,8 +62,10 @@ test.describe('Database Connectivity Validation', () => {
6062
});
6163

6264
test('should provide clear error messages in auth-only mode', async ({ page }) => {
65+
const baseURL = getBaseURL();
66+
6367
// Navigate to the web application
64-
await page.goto('http://localhost:3127');
68+
await page.goto(baseURL);
6569

6670
// Wait for the page to load
6771
await page.waitForLoadState('networkidle');
@@ -101,8 +105,10 @@ test.describe('Database Connectivity Validation', () => {
101105
});
102106

103107
test('should validate health check endpoint reflects database status', async ({ page }) => {
108+
const apiURL = getAPIURL();
109+
104110
// Check the health endpoint
105-
const response = await page.goto('http://localhost:4127/health');
111+
const response = await page.goto(`${apiURL}/health`);
106112
expect(response?.status()).toBe(200);
107113

108114
const healthData = await response?.json();

tests/helpers/auth.ts

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,23 @@ export const TEST_USERS = {
4545
}
4646
} as const;
4747

48+
/**
49+
* Get base URL for navigation
50+
* Supports both environment configuration and defaults
51+
*/
52+
export function getBaseURL(): string {
53+
return process.env.TEST_URL || 'https://localhost:3128';
54+
}
55+
56+
/**
57+
* Get API URL for GraphQL endpoint
58+
*/
59+
export function getAPIURL(): string {
60+
const apiPort = process.env.API_PORT || '4128';
61+
const protocol = process.env.SSL_ENABLED === 'false' ? 'http' : 'https';
62+
return `${protocol}://localhost:${apiPort}`;
63+
}
64+
4865
/**
4966
* Authentication state detection
5067
*/
@@ -218,24 +235,26 @@ async function attemptLogin(
218235
credentials: LoginCredentials,
219236
timeout: number
220237
): Promise<void> {
238+
const baseURL = getBaseURL();
239+
221240
// Step 1: Navigate to application
222241
console.log(' 📍 Navigating to application...');
223-
await page.goto('/', { waitUntil: 'domcontentloaded', timeout });
242+
await page.goto(`${baseURL}/`, { waitUntil: 'domcontentloaded', timeout });
224243
await page.waitForTimeout(1500); // Allow React hydration
225-
244+
226245
// Step 2: Check if we need to navigate to login
227246
const currentUrl = page.url();
228247
if (!currentUrl.includes('/login')) {
229248
// Try to find login link or navigate directly
230249
const loginLink = page.locator('a[href*="login"], button:has-text("Login"), button:has-text("Sign In")').first();
231-
250+
232251
if (await loginLink.isVisible({ timeout: 2000 })) {
233252
console.log(' 🔗 Found login link, clicking...');
234253
await loginLink.click();
235254
await page.waitForTimeout(1000);
236255
} else {
237256
console.log(' 🗺️ No login link found, navigating directly to /login-form');
238-
await page.goto('/login-form', { waitUntil: 'domcontentloaded' });
257+
await page.goto(`${baseURL}/login-form`, { waitUntil: 'domcontentloaded' });
239258
}
240259
}
241260

@@ -536,12 +555,13 @@ export async function ensureLoggedIn(
536555
*/
537556
export async function navigateToWorkspace(page: Page): Promise<void> {
538557
console.log('🏢 Navigating to workspace...');
539-
558+
540559
// Ensure we're logged in first
541560
await ensureLoggedIn(page);
542-
543-
// Navigate to workspace
544-
await page.goto('/workspace', { waitUntil: 'domcontentloaded' });
561+
562+
// Navigate to workspace with full URL
563+
const baseURL = getBaseURL();
564+
await page.goto(`${baseURL}/workspace`, { waitUntil: 'domcontentloaded' });
545565
await page.waitForTimeout(2000); // React hydration
546566

547567
// Wait for workspace core elements

0 commit comments

Comments
 (0)