diff --git a/tests/e2e/config/pricing.py b/tests/e2e/config/pricing.py new file mode 100644 index 0000000..35edeea --- /dev/null +++ b/tests/e2e/config/pricing.py @@ -0,0 +1,53 @@ +from dataclasses import dataclass +from typing import Dict, Any + + +@dataclass(frozen=True) +class SurgePricingConfig: + high_threshold: int + surge_multiplier: float + window_size: int # seconds + + def to_dict(self) -> Dict[str, Any]: + return { + "high_threshold": self.high_threshold, + "surge_multiplier": self.surge_multiplier, + "window_size": self.window_size, + } + + +@dataclass(frozen=True) +class SessionAwareConfig: + velocity_threshold: float + view_depth_threshold: int + cart_ratio_threshold: float + agent_multiplier: float + + def to_dict(self) -> Dict[str, Any]: + return { + "velocity_threshold": self.velocity_threshold, + "view_depth_threshold": self.view_depth_threshold, + "cart_ratio_threshold": self.cart_ratio_threshold, + "agent_multiplier": self.agent_multiplier, + } + + +# Test-optimized configurations for deterministic results +AGGRESSIVE_SURGE = SurgePricingConfig( + high_threshold=3, + surge_multiplier=1.5, + window_size=10, +) + +MODERATE_SURGE = SurgePricingConfig( + high_threshold=5, + surge_multiplier=1.3, + window_size=15, +) + +STRICT_SESSION_AWARE = SessionAwareConfig( + velocity_threshold=2.0, # 2 events/sec is agent-like + view_depth_threshold=5, + cart_ratio_threshold=0.8, + agent_multiplier=1.4, +) diff --git a/tests/e2e/config/settings.py b/tests/e2e/config/settings.py new file mode 100644 index 0000000..54ead09 --- /dev/null +++ b/tests/e2e/config/settings.py @@ -0,0 +1,36 @@ +import os +from dataclasses import dataclass +@dataclass(frozen=True) +class ServiceConfig: + web_url: str + backend_url: str + pricing_url: str + kafka_host: str + kafka_port: int + redis_port: int +@dataclass(frozen=True) +class TestConfig: + headless: bool + timeout: int + poll_interval: float + max_retries: int + kafka_consumer_timeout: int + + +def load_service_config() -> ServiceConfig: + return ServiceConfig( + web_url=os.getenv("WEB_URL", "http://localhost:3000"), + backend_url=os.getenv("BACKEND_URL", "http://localhost:5000"), + pricing_url=os.getenv("PRICING_PROVIDER_URL", "http://localhost:5001"), + kafka_host=os.getenv("KAFKA_HOST", "localhost"), + kafka_port=int(os.getenv("KAFKA_PORT", "9092")), + redis_port=int(os.getenv("REDIS_PORT", "6377")), + ) +def load_test_config() -> TestConfig: + return TestConfig( + headless=os.getenv("HEADLESS", "true").lower() == "true", + timeout=int(os.getenv("TEST_TIMEOUT", "30000")), + poll_interval=float(os.getenv("POLL_INTERVAL", "0.5")), + max_retries=int(os.getenv("MAX_RETRIES", "10")), + kafka_consumer_timeout=int(os.getenv("KAFKA_TIMEOUT", "15")), + ) diff --git a/tests/e2e/package.json b/tests/e2e/package.json new file mode 100644 index 0000000..1fd77e3 --- /dev/null +++ b/tests/e2e/package.json @@ -0,0 +1,20 @@ +{ + "name": "e2e", + "version": "1.0.0", + "main": "index.js", + "scripts": { + "test": "playwright test", + "test:ui": "playwright test --ui", + "test:debug": "playwright test --debug" + }, + "keywords": [], + "author": "", + "license": "ISC", + "description": "", + "devDependencies": { + "@playwright/test": "^1.57.0", + "@types/node": "^25.0.6", + "kafka-node": "^5.0.0", + "typescript": "^5.9.3" + } +} diff --git a/tests/e2e/playwright.config.ts b/tests/e2e/playwright.config.ts new file mode 100644 index 0000000..4f364f5 --- /dev/null +++ b/tests/e2e/playwright.config.ts @@ -0,0 +1,25 @@ +import { defineConfig, devices } from '@playwright/test'; + +export default defineConfig({ + testDir: './scenarios', + fullyParallel: false, + forbidOnly: !!process.env.CI, + retries: 0, + workers: 1, + reporter: 'list', + use: { + baseURL: process.env.WEB_URL || 'http://localhost:3000', + trace: 'retain-on-failure', + screenshot: 'only-on-failure', + }, + timeout: 60000, + expect: { + timeout: 10000, + }, + projects: [ + { + name: 'chromium', + use: { ...devices['Desktop Chrome'] }, + }, + ], +}); diff --git a/tests/e2e/tsconfig.json b/tests/e2e/tsconfig.json new file mode 100644 index 0000000..1107d1c --- /dev/null +++ b/tests/e2e/tsconfig.json @@ -0,0 +1,15 @@ +{ + "compilerOptions": { + "target": "ES2022", + "module": "commonjs", + "lib": ["ES2022"], + "strict": true, + "esModuleInterop": true, + "skipLibCheck": true, + "forceConsistentCasingInFileNames": true, + "resolveJsonModule": true, + "types": ["node", "@playwright/test"] + }, + "include": ["**/*.ts"], + "exclude": ["node_modules"] +}