#!/usr/bin/env bash # NoteLett Docker compose E2E seed. # # Idempotent setup for scripts/e2e-docker-test.sh and for manual UI testing: # 1. Register the `notelett` product with the running platform-service. # 2. Register one admin test user (admin@notelett.app). # 3. Register one read-only test user (user@notelett.app). # # Re-running is safe: each step skips if the resource already exists. # # Prerequisites: # - platform-service is reachable at http://localhost:4003 # - NoteLett backend is reachable at http://localhost:4016 (or run # `docker compose up -d` first) # # Usage: # bash scripts/e2e-docker-seed.sh set -e PLATFORM="${PLATFORM:-http://localhost:4003}" ADMIN_EMAIL="admin@notelett.app" ADMIN_PASS="Notelett!Test#2026" USER_EMAIL="user@notelett.app" USER_PASS="Notelett!Test#2026" step() { echo ""; echo "── $* ──"; } ok() { echo "✓ $*"; } skip() { echo "↷ $*"; } fail() { echo "✗ $*" >&2; exit 1; } step "1. Register product 'notelett' with platform-service" EXISTING=$(curl -sS "$PLATFORM/api/products/notelett" -o /dev/null -w "%{http_code}") if [[ "$EXISTING" == "200" ]]; then skip "product 'notelett' already exists" else RESP=$(curl -sS -X POST "$PLATFORM/api/products" -H "Content-Type: application/json" \ -d '{ "productId": "notelett", "displayName": "NoteLett", "licensePrefix": "NL", "packageName": "@notelett/web", "defaultPlan": "free", "trialDays": 14, "websiteUrl": "https://notelett.app", "status": "active" }') echo "$RESP" | python3 -c "import json,sys; d=json.load(sys.stdin); print(f' id={d.get(\"id\")} status={d.get(\"status\")}')" \ || fail "product create failed: $RESP" ok "product created" fi step "2. Register admin test user ($ADMIN_EMAIL)" LOGIN_PROBE=$(curl -sS -X POST "$PLATFORM/api/auth/login" -H "Content-Type: application/json" \ -d "{\"email\":\"$ADMIN_EMAIL\",\"password\":\"$ADMIN_PASS\",\"productId\":\"notelett\"}") if echo "$LOGIN_PROBE" | grep -q "accessToken"; then skip "admin user already registered + login works" else REG=$(curl -sS -X POST "$PLATFORM/api/auth/register" -H "Content-Type: application/json" \ -d "{ \"email\":\"$ADMIN_EMAIL\", \"password\":\"$ADMIN_PASS\", \"displayName\":\"Admin User\", \"role\":\"admin\", \"productId\":\"notelett\" }") echo "$REG" | python3 -c "import json,sys; d=json.load(sys.stdin); u=d.get('user',{}); print(f' email={u.get(\"email\")} role={u.get(\"role\")}')" \ || fail "admin register failed: $REG" ok "admin user created" fi step "3. Register read-only test user ($USER_EMAIL)" LOGIN_PROBE=$(curl -sS -X POST "$PLATFORM/api/auth/login" -H "Content-Type: application/json" \ -d "{\"email\":\"$USER_EMAIL\",\"password\":\"$USER_PASS\",\"productId\":\"notelett\"}") if echo "$LOGIN_PROBE" | grep -q "accessToken"; then skip "user already registered + login works" else REG=$(curl -sS -X POST "$PLATFORM/api/auth/register" -H "Content-Type: application/json" \ -d "{ \"email\":\"$USER_EMAIL\", \"password\":\"$USER_PASS\", \"displayName\":\"Read-only User\", \"role\":\"user\", \"productId\":\"notelett\" }") echo "$REG" | python3 -c "import json,sys; d=json.load(sys.stdin); u=d.get('user',{}); print(f' email={u.get(\"email\")} role={u.get(\"role\")}')" \ || fail "user register failed: $REG" ok "user created" fi echo "" echo "🟢 Seed complete." echo "" echo "Test credentials:" echo " Admin (read+write): $ADMIN_EMAIL / $ADMIN_PASS" echo " Read-only: $USER_EMAIL / $USER_PASS" echo "" echo "Next: bash scripts/e2e-docker-test.sh" echo "Or open the web app: http://localhost:3050/login"