Playwright configured. Backend index.ts corrected
This commit is contained in:
@@ -1,47 +0,0 @@
|
||||
// tests/e2e/auth.e2e.test.ts
|
||||
import { test, expect } from '@playwright/test';
|
||||
|
||||
test.describe('Authentication End-to-End Tests', () => {
|
||||
test('should allow successful SPA access after correct passphrase entry', async ({ page }) => {
|
||||
// Assuming the app is running on http://localhost:3000
|
||||
await page.goto('http://localhost:3000');
|
||||
|
||||
// Expect to be on the login page
|
||||
await expect(page.locator('h1', { hasText: 'Enter Passphrase' })).toBeVisible();
|
||||
|
||||
// Fill in the passphrase (replace with actual passphrase from .env)
|
||||
await page.fill('#passphrase', 'YOUR_PASSPHRASE_HERE'); // Placeholder
|
||||
|
||||
// Click the submit button
|
||||
await page.click('button[type="submit"]');
|
||||
|
||||
// Expect to be redirected to the SPA content (e.g., CreateSession page)
|
||||
await expect(page.locator('h1', { hasText: 'Create New Session' })).toBeVisible();
|
||||
|
||||
// Verify session token is stored (e.g., in local storage)
|
||||
const sessionToken = await page.evaluate(() => localStorage.getItem('sessionToken'));
|
||||
expect(sessionToken).not.toBeNull();
|
||||
expect(sessionToken).not.toBe('');
|
||||
});
|
||||
|
||||
test('should deny SPA access and show error for incorrect passphrase entry', async ({ page }) => {
|
||||
await page.goto('http://localhost:3000');
|
||||
|
||||
// Expect to be on the login page
|
||||
await expect(page.locator('h1', { hasText: 'Enter Passphrase' })).toBeVisible();
|
||||
|
||||
// Fill in an incorrect passphrase
|
||||
await page.fill('#passphrase', 'incorrect-passphrase');
|
||||
|
||||
// Click the submit button
|
||||
await page.click('button[type="submit"]');
|
||||
|
||||
// Expect to remain on the login page and see an error message
|
||||
await expect(page.locator('h1', { hasText: 'Enter Passphrase' })).toBeVisible();
|
||||
await expect(page.locator('.MuiAlert-message', { hasText: 'Authentication failed' })).toBeVisible(); // Assuming the error message is "Authentication failed"
|
||||
|
||||
// Verify session token is NOT stored
|
||||
const sessionToken = await page.evaluate(() => localStorage.getItem('sessionToken'));
|
||||
expect(sessionToken).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -1,48 +0,0 @@
|
||||
// tests/e2e/deployment.e2e.test.ts
|
||||
import { test, expect } from '@playwright/test';
|
||||
|
||||
test.describe('Deployment End-to-End Tests', () => {
|
||||
|
||||
// This test requires a special setup that runs the application with specific
|
||||
// environment variables for the frontend and backend to simulate a real deployment.
|
||||
// The test would be executed against the deployed environment.
|
||||
|
||||
test('should load the application on a custom domain without CORS errors', async ({ page }) => {
|
||||
// Step 1: Before running this test, the application must be started
|
||||
// with docker-compose, using .env files that point to the custom domains.
|
||||
// For example:
|
||||
// In frontend/.env: REACT_APP_API_URL=http://backend.unisono.test
|
||||
// In backend/.env: CORS_ORIGIN=http://frontend.unisono.test
|
||||
// And the local machine must resolve these domains (e.g., via /etc/hosts).
|
||||
|
||||
const frontendUrl = 'http://frontend.unisono.test:3000'; // Example URL
|
||||
|
||||
// Step 2: Capture console errors, specifically looking for CORS issues.
|
||||
const consoleErrors: string[] = [];
|
||||
page.on('console', msg => {
|
||||
if (msg.type() === 'error') {
|
||||
consoleErrors.push(msg.text());
|
||||
}
|
||||
});
|
||||
|
||||
// Step 3: Navigate to the frontend URL.
|
||||
await page.goto(frontendUrl);
|
||||
|
||||
// Step 4: Interact with the page to trigger API calls.
|
||||
// In this case, just loading the login page should be enough to
|
||||
// confirm the frontend can potentially connect to the backend.
|
||||
// We will check for the login page content.
|
||||
await expect(page.locator('h1', { hasText: 'Enter Passphrase' })).toBeVisible();
|
||||
|
||||
// Step 5: Assert that no CORS errors were logged to the console.
|
||||
const corsError = consoleErrors.find(error => error.includes('Cross-Origin Resource Sharing') || error.includes('CORS'));
|
||||
expect(corsError).toBeUndefined();
|
||||
|
||||
// Optional: Further interaction to test a real API call after login.
|
||||
// This would require a valid passphrase for the test environment.
|
||||
// await page.fill('#passphrase', process.env.TEST_AUTH_PASSPHRASE);
|
||||
// await page.click('button[type="submit"]');
|
||||
// await expect(page.locator('h1', { hasText: 'Create New Session' })).toBeVisible();
|
||||
// expect(corsError).toBeUndefined(); // Re-assert after API calls
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user