From 78325cddfa713c4552c92db73fd6c1d57568c48f Mon Sep 17 00:00:00 2001 From: MartinBraquet Date: Tue, 17 Feb 2026 17:27:45 +0100 Subject: [PATCH] Fix --- docs/TESTING.md | 15 +++++++-------- package.json | 5 +++-- scripts/e2e-dev.sh | 2 +- scripts/e2e.sh | 14 ++++---------- scripts/e2e_services.sh | 18 ++++++++++++++++++ scripts/seed-test-data.ts | 37 ++++++++++++++++++++++++++++++++----- scripts/seed.sh | 18 ++++++++++++++++++ 7 files changed, 83 insertions(+), 26 deletions(-) create mode 100755 scripts/e2e_services.sh create mode 100755 scripts/seed.sh diff --git a/docs/TESTING.md b/docs/TESTING.md index ba233c09..18f42ca3 100644 --- a/docs/TESTING.md +++ b/docs/TESTING.md @@ -563,15 +563,14 @@ yarn test:e2e:dev --debug tests/e2e/web/specs/signUp.spec.ts ### 1. Start services once ```bash -yarn e2e:services +yarn test:e2e:services ``` This starts Firebase emulators, the backend API, and Next.js in one terminal. In a separate terminal, start Supabase: ```bash -npx supabase start -npx supabase db reset # Apply migrations + seed +yarn test:db:reset # Restart and apply migrations + seed ``` ### 2. Open Playwright UI @@ -598,7 +597,7 @@ No restart needed for test file changes. If your tests leave dirty state or you need a fresh DB: ```bash -npx supabase db reset # Drops and re-applies all migrations + seed +yarn test:db:reset # Drops and re-applies all migrations + seed ``` --- @@ -610,8 +609,8 @@ npx supabase db reset # Drops and re-applies all migrations + seed | Edit test file | Just re-run in Playwright UI | | Edit app code (Next.js) | Next.js hot reloads automatically | | Edit API code | API dev server hot reloads automatically | -| Database schema change | `npx supabase db reset` | -| Seed data change | `npx supabase db reset` | +| Database schema change | `yarn test:db:reset` | +| Seed data change | `yarn test:db:reset` | | Change `playwright.config.ts` | Restart Playwright UI | | Change env variables | Restart affected service | @@ -709,7 +708,7 @@ test.describe('Authentication', () => { ### Test accounts -These are seeded automatically by `npx supabase db reset`: +These are seeded automatically by `yarn test:db:seed`: | Email | Password | |---------------------|---------------| @@ -756,7 +755,7 @@ curl http://localhost:3000 # Next.js ### Database is in a bad state ```bash -npx supabase db reset # Full reset - drops everything and reseeds +yarn test:db:reset # Full reset - drops everything and reseeds ``` ### Firebase auth warning in CI diff --git a/package.json b/package.json index 7aa7aef8..a60fc2c3 100644 --- a/package.json +++ b/package.json @@ -30,10 +30,11 @@ "test:e2e:dev": "./scripts/e2e-dev.sh", "test:e2e:ui": "./scripts/e2e.sh --ui", "test:e2e:debug": "./scripts/e2e.sh --debug", - "test:e2e:services": "concurrently --names 'firebase,api,web' 'yarn emulate' 'yarn --cwd=backend/api dev' 'yarn --cwd=web dev'", - "test:db:reset": "npx supabase start && ./scripts/combine-migrations.sh && npx supabase db reset", + "test:e2e:services": "./scripts/e2e_services.sh", + "test:db:reset": "npx supabase start && ./scripts/combine-migrations.sh && npx supabase db reset && yarn test:db:seed", "test:db:reset-postgres": "docker compose -f scripts/docker-compose.test.yml down -v && docker compose -f scripts/docker-compose.test.yml up -d", "test:db:migrate": "./scripts/test_db_migration.sh", + "test:db:seed": "./scripts/seed.sh", "playwright": "playwright test", "playwright:ui": "playwright test --ui", "playwright:debug": "playwright test --debug", diff --git a/scripts/e2e-dev.sh b/scripts/e2e-dev.sh index d4aa7a7b..7b80b36e 100755 --- a/scripts/e2e-dev.sh +++ b/scripts/e2e-dev.sh @@ -38,7 +38,7 @@ check_services() { if [ $missing -eq 1 ]; then echo "" - echo "Start everything with: yarn e2e:services" + echo "Start everything with: yarn test:e2e:services" echo "Or start full clean run: yarn test:e2e" exit 1 fi diff --git a/scripts/e2e.sh b/scripts/e2e.sh index 1ea59729..eaf07b1e 100755 --- a/scripts/e2e.sh +++ b/scripts/e2e.sh @@ -59,8 +59,8 @@ print_status "Killing any stale processes..." supabase stop --no-backup 2>/dev/null || true sleep 2 # Give ports time to free up -# Start Supabase (includes Postgres, Auth, Storage, etc.) and Apply migrations -yarn test:db:reset +# Build backend (required?) +./scripts/build_api.sh # Get connection details export NEXT_PUBLIC_SUPABASE_URL=$(supabase status --output json | jq -r '.API_URL') @@ -87,14 +87,8 @@ npx wait-on \ http-get://127.0.0.1:9099 \ --timeout 30000 -# Build backend (required?) -./scripts/build_api.sh - -# Seed test data if script exists -if [ -f "scripts/seed-test-data.ts" ]; then - print_status "Seeding test data..." - npx tsx scripts/seed-test-data.ts -fi +# Start Supabase (includes Postgres, Auth, Storage, etc.) and Apply migrations and seed (needs firebase emulator running) +yarn test:db:reset # Start backend API print_status "Starting backend API..." diff --git a/scripts/e2e_services.sh b/scripts/e2e_services.sh new file mode 100755 index 00000000..8b6ec138 --- /dev/null +++ b/scripts/e2e_services.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +set -euo pipefail + +# Change to project root +cd "$(dirname "$0")"/.. + +export $(cat .env.test | grep -v '^#' | xargs) + +# Get connection details +export NEXT_PUBLIC_SUPABASE_URL=$(supabase status --output json | jq -r '.API_URL') +export NEXT_PUBLIC_SUPABASE_ANON_KEY=$(supabase status --output json | jq -r '.ANON_KEY') +export DATABASE_URL=$(supabase status --output json | jq -r '.DB_URL') + +# Build backend (required?) +./scripts/build_api.sh + +concurrently --names 'firebase,api,web' 'yarn emulate' 'yarn --cwd=backend/api dev' 'yarn --cwd=web dev' diff --git a/scripts/seed-test-data.ts b/scripts/seed-test-data.ts index c5fb1216..8fcaaa54 100644 --- a/scripts/seed-test-data.ts +++ b/scripts/seed-test-data.ts @@ -6,15 +6,25 @@ import {seedDatabase} from "../tests/e2e/utils/seedDatabase"; import axios from 'axios'; import {config} from '../tests/e2e/web/SPEC_CONFIG.js'; +import {tryCatch} from "common/lib/util/try-catch"; +import {insert} from "shared/lib/supabase/utils"; async function createAuth(email: string, password: string) { const base = 'http://localhost:9099/identitytoolkit.googleapis.com/v1'; - await axios.post(`${base}/accounts:signUp?key=fake-api-key`, { - email: email, - password: password, - returnSecureToken: true - }); + try { + await axios.post(`${base}/accounts:signUp?key=fake-api-key`, { + email: email, + password: password, + returnSecureToken: true + }) + } catch (err: any) { + if (err.response?.status === 400 || err.response?.data?.error?.message?.includes('EMAIL_EXISTS')) { + return; + } + if (err.code === 'ECONNREFUSED') throw Error('Firebase emulator not running. Start with:\n yarn test:e2e:services\n') + console.log(err); + } console.log('Auth created', config.USERS.DEV_1.EMAIL) @@ -27,12 +37,28 @@ async function createAuth(email: string, password: string) { // Can remove this later once we update tests/e2e/web/fixtures/signInFixture.ts createAuth(config.USERS.DEV_1.EMAIL, config.USERS.DEV_1.PASSWORD) +async function seedCompatibilityPrompts(pg: any, userId: string = null) { + // Need some prompts to prevent the onboarding from stopping once it reaches them (just after profile creation) + const question = "What is your favorite color?" + const multiple_choice_options = {"Blue": 0, "Green": 1, "Red": 2} + const {data, error} = await tryCatch( + insert(pg, 'compatibility_prompts', { + creator_id: userId, + question, + answer_type: 'compatibility_multiple_choice', + multiple_choice_options, + }) + ) + console.log('Compatibility prompts created', {data, error}) +} type ProfileType = 'basic' | 'medium' | 'full' (async () => { const pg = createSupabaseDirectClient() + await seedCompatibilityPrompts(pg) + //Edit the count seedConfig to specify the amount of each profiles to create const seedConfig = [ {count: 1, profileType: 'basic' as ProfileType}, @@ -52,5 +78,6 @@ type ProfileType = 'basic' | 'medium' | 'full' await seedDatabase(pg, userInfo, profileType) } } + process.exit(0) })() \ No newline at end of file diff --git a/scripts/seed.sh b/scripts/seed.sh new file mode 100755 index 00000000..34276e58 --- /dev/null +++ b/scripts/seed.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +set -euo pipefail + +# Change to project root +cd "$(dirname "$0")"/.. + +export $(cat .env.test | grep -v '^#' | xargs) + +# Get connection details +export NEXT_PUBLIC_SUPABASE_URL=$(supabase status --output json | jq -r '.API_URL') +export NEXT_PUBLIC_SUPABASE_ANON_KEY=$(supabase status --output json | jq -r '.ANON_KEY') +export DATABASE_URL=$(supabase status --output json | jq -r '.DB_URL') + +# Build backend (required?) +./scripts/build_api.sh + +npx tsx scripts/seed-test-data.ts