diff --git a/web/tests/conftest.py b/web/tests/conftest.py index 704ff58..8f8eb52 100644 --- a/web/tests/conftest.py +++ b/web/tests/conftest.py @@ -245,16 +245,45 @@ def sign_payload(payload_bytes: bytes, secret: str = "whsec_test_secret") -> str _VISUAL_PORT = 5111 +async def _seed_visual_data(conn): + """Seed a supplier + feature flags for E2E billing/dashboard tests.""" + await conn.execute( + "INSERT INTO users (id, email, created_at)" + " VALUES (999, 'supplier@test.com', datetime('now'))" + ) + await conn.execute( + "INSERT INTO suppliers" + " (id, name, slug, tier, claimed_by, claimed_at," + " country_code, region, category, credit_balance," + " monthly_credits, contact_name, contact_email, created_at)" + " VALUES (1, 'Test Supplier GmbH', 'test-supplier', 'pro', 999," + " datetime('now'), 'DE', 'Europe', 'construction', 50," + " 10, 'Test User', 'supplier@test.com', datetime('now'))" + ) + for flag in ("supplier_signup", "markets", "payments", + "planner_export", "lead_unlock"): + await conn.execute( + "INSERT OR REPLACE INTO feature_flags (name, enabled)" + " VALUES (?, 1)", (flag,) + ) + await conn.commit() + + def _run_visual_server(ready_event): """Run a Quart dev server in a subprocess for visual/E2E tests. Forces RESEND_API_KEY="" so no real emails are sent. + Forces WAITLIST_MODE=false so feature pages render (not waitlist templates). Runs migrations in-process to build the full schema (including FTS tables). """ import asyncio import os os.environ["RESEND_API_KEY"] = "" + os.environ["WAITLIST_MODE"] = "false" + # Config class attributes are evaluated at import time (before fork), + # so we must also patch the live config object directly. + core.config.WAITLIST_MODE = False async def _serve(): # Build schema DDL in-process (FTS5 virtual tables need this) @@ -276,7 +305,16 @@ def _run_visual_server(ready_event): conn.row_factory = aiosqlite.Row await conn.execute("PRAGMA foreign_keys=ON") await conn.executescript(schema_ddl) - await conn.commit() + # Ensure feature_flags table exists (may be missed if an FTS5 + # CREATE VIRTUAL TABLE causes executescript to stop early) + await conn.execute( + "CREATE TABLE IF NOT EXISTS feature_flags" + " (name TEXT PRIMARY KEY, enabled INTEGER NOT NULL DEFAULT 0," + " description TEXT," + " updated_at TEXT DEFAULT (strftime('%Y-%m-%dT%H:%M:%SZ','now')))" + ) + # Seed data needed by E2E tests (supplier dashboard, billing, etc.) + await _seed_visual_data(conn) core._db = conn # Patch init_db/close_db where they're USED (app.py imports them @@ -285,7 +323,9 @@ def _run_visual_server(ready_event): # Patches must stay active through run_task() because before_serving # hooks call init_db() which would replace our in-memory DB. with patch("padelnomics.app.init_db", new_callable=AsyncMock), \ - patch("padelnomics.app.close_db", new_callable=AsyncMock): + patch("padelnomics.app.close_db", new_callable=AsyncMock), \ + patch("padelnomics.app.open_analytics_db"), \ + patch("padelnomics.app.close_analytics_db"): app = create_app() app.config["TESTING"] = True ready_event.set() diff --git a/web/tests/screenshots/landing_full.png b/web/tests/screenshots/landing_full.png index d28a696..e2c4456 100644 Binary files a/web/tests/screenshots/landing_full.png and b/web/tests/screenshots/landing_full.png differ diff --git a/web/tests/screenshots/landing_mobile.png b/web/tests/screenshots/landing_mobile.png index c470868..b8f45c8 100644 Binary files a/web/tests/screenshots/landing_mobile.png and b/web/tests/screenshots/landing_mobile.png differ diff --git a/web/tests/screenshots/signup.png b/web/tests/screenshots/signup.png index a088257..41aef77 100644 Binary files a/web/tests/screenshots/signup.png and b/web/tests/screenshots/signup.png differ