Skip to content

Commit a86ea71

Browse files
fix: remove conditional logic from Playwright tests for consistent CI behavior
- Playwright webServer always runs in production mode (npm run build && npm run start) - Removed NODE_ENV checks that caused CI failures - Tests now always expect production behavior (redirect to homepage, 403 responses) - All 17 tests passing consistently in both local and CI environments
1 parent 38bc72e commit a86ea71

File tree

1 file changed

+10
-30
lines changed

1 file changed

+10
-30
lines changed

tests/security/auth-protection.spec.ts

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -87,49 +87,29 @@ test.describe('Protected Routes - Authentication Required', () => {
8787
test.describe('Dev Login Protection', () => {
8888

8989
test('Dev login page should not be accessible in production', async ({ page }) => {
90-
// This test assumes NODE_ENV=production
90+
// Playwright webServer runs in production mode (npm run build && npm run start)
9191
// In production, /dev-login should redirect to homepage
9292

93-
// Note: This test needs to be run with NODE_ENV=production
94-
// In development, it will show the dev login page (expected behavior)
93+
await page.goto('/dev-login');
9594

96-
const response = await page.goto('/dev-login');
97-
98-
// Check if we're in production mode by checking environment
99-
// If in production, should redirect to home
100-
// If in development, should show dev login page
101-
102-
const isProduction = process.env.NODE_ENV === 'production';
103-
104-
if (isProduction) {
105-
// Should redirect to homepage in production
106-
expect(page.url()).toBe(new URL('/', page.url()).href);
107-
} else {
108-
// In development, should show dev login page
109-
expect(response?.status()).toBe(200);
110-
await expect(page.locator('h1')).toContainText('Development Login');
111-
}
95+
// Should redirect to homepage in production
96+
expect(page.url()).toBe(new URL('/', page.url()).href);
11297
});
11398

11499
test('Dev session API should return 403 in production', async ({ request }) => {
115-
// This test verifies the API endpoint protection
116-
const isProduction = process.env.NODE_ENV === 'production';
100+
// Playwright webServer runs in production mode (npm run build && npm run start)
101+
// Dev session API should return 403 in production
117102

118103
const response = await request.post('/api/auth/dev-session', {
119104
data: {
120105
121106
}
122107
});
123108

124-
if (isProduction) {
125-
// Should return 403 in production
126-
expect(response.status()).toBe(403);
127-
const data = await response.json();
128-
expect(data.error).toBe('Not available in production');
129-
} else {
130-
// In development, should work
131-
expect(response.status()).toBeLessThan(500);
132-
}
109+
// Should return 403 in production
110+
expect(response.status()).toBe(403);
111+
const data = await response.json();
112+
expect(data.error).toBe('Not available in production');
133113
});
134114
});
135115

0 commit comments

Comments
 (0)