Playwright configured. Backend index.ts corrected

This commit is contained in:
aodulov
2025-10-29 13:56:11 +02:00
parent 43334afaf6
commit fa4b936421
9 changed files with 287 additions and 202 deletions

View File

@@ -1,83 +0,0 @@
# End-to-End (E2E) Test Plan
**Feature**: Anonymous Desire Aggregator
**Date**: 2025-10-09
This document outlines the manual test plan for verifying the end-to-end functionality of the application.
## Test Environment
- **Frontend**: `http://localhost:3000`
- **Backend**: `http://localhost:8000`
- **Browser**: Google Chrome (or any modern browser)
- **Tools**: Browser's Developer Tools (for inspecting Local Storage and network requests)
## Test Cases
### Test Case 1: Happy Path - Full Session Lifecycle
**Objective**: Verify a complete, successful session from creation to result display with multiple participants.
**Steps**:
1. **Participant 1 (Creator): Create Session**
- Open a browser and navigate to `http://localhost:3000`.
- In the "Topic" field, enter "Team Lunch".
- In the "Number of Participants" field, enter "3".
- Click "Create Session".
- **Expected**: The user is redirected to a new URL (e.g., `/session/some-uuid`). The session ID should be visible in the URL.
- Copy the session URL.
2. **Participants 2 & 3: Join Session**
- Open two new browser windows (or incognito tabs) and paste the session URL into each.
- **Expected**: All three browser windows should now show the "Waiting for 3 more participants..." message, which should update as each new participant joins.
3. **All Participants: Submit Desires**
- **Participant 1**:
- Wants: "Pizza"
- Accepts: "Sushi", "Salad"
- No-Goes: "Burgers"
- Click "Submit".
- **Participant 2**:
- Wants: "Sushi"
- Accepts: "Pizza", "Tacos"
- No-Goes: "Salad"
- Click "Submit".
- **Participant 3**:
- Wants: "Pizza"
- Accepts: "Tacos"
- No-Goes: "Sushi"
- Click "Submit".
- **Expected**: As each participant submits, the "Waiting for..." message should update. After the final submission, the creator's view should show a button to "Analyze Desires".
4. **Participant 1 (Creator): Trigger Analysis**
- Click the "Analyze Desires" button.
- **Expected**: A loading indicator should appear. After a few moments, all three browser windows should display the same results.
5. **All Participants: Verify Results**
- **Expected Results (example)**:
- **Go-to**: "Pizza"
- **Also good**: "Tacos"
- **Considerable**: "Salad"
- **No-goes**: "Burgers", "Sushi"
- **Expected**: The "Considerable" section should be collapsed by default. Clicking it should expand to show the items.
### Test Case 2: Edge Case - Participant Leaves and Rejoins
**Objective**: Verify that the session state remains consistent if a participant disconnects and reconnects.
**Steps**:
1. Follow steps 1 and 2 from Test Case 1.
2. Close the browser window for Participant 2.
3. Re-open the session URL in a new window for Participant 2.
4. **Expected**: The session should still show 3 participants, and the "Waiting for..." message should be accurate. The session should proceed normally when all desires are submitted.
### Test Case 3: Error Condition - Invalid Session ID
**Objective**: Verify the application handles invalid session URLs gracefully.
**Steps**:
1. Navigate to a non-existent session URL (e.g., `http://localhost:3000/session/invalid-uuid`).
2. **Expected**: The user should be shown a "Session not found" error message and be redirected to the home page to create a new session.

View File

@@ -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();
});
});

View File

@@ -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
});
});