# TestSprite and E2E runs

## 2026-04-02 (documentation)

- **`PRD_v2_WhatsApp_Ticketing_System.md`** → **v2.2**: contact detail, company linking (`PATCH /contacts/:id`), companies API/UI, portal notes, schema updates (`companies`, `contacts.company_id`, `users.display_name` / roles).
- **TestSprite**: [`testsprite_tests/standard_prd.json`](../testsprite_tests/standard_prd.json) and [`testsprite_tests/testsprite_frontend_test_plan.json`](../testsprite_tests/testsprite_frontend_test_plan.json) updated (new routes + **TC030–TC033**). Summary in [`testsprite_tests/testsprite-mcp-test-report.md`](../testsprite_tests/testsprite-mcp-test-report.md).
- For MCP runs, optionally refresh `testsprite_tests/tmp/code_summary.yaml` via TestSprite **generate code summary** after route changes.

## 2026-04-02

### TestSprite (cloud)

- **Command**: TestSprite MCP `testsprite_generate_code_and_execute`, then `node scripts/run-testsprite-execute.mjs` with Docker **frontend** on **:3000** and **api** on **:3001**.
- **Local CLI**: Logged `checkPortListening tcp timeout: 3000 localhost`, tunnel `503` on first probe, then many connection timeouts — execution still **completed** and refreshed `testsprite_tests/tmp/raw_report.md`.
- **Outcome (raw report)**: ~**79.31%** passed (**23**/29). **Failed**: TC008 (no ticket date-range UI), TC011 (timeout on channel AI/templates flow), TC013 (empty template save without validation), TC022 (role change not reflected in UI per agent), TC025 (no audit “actor” filter), TC029 (non-admin login used invalid placeholder credentials).
- **Committed summary**: [testsprite_tests/testsprite-mcp-test-report.md](../testsprite_tests/testsprite-mcp-test-report.md). Full per-case links remain under **gitignored** `testsprite_tests/tmp/`.

## 2026-03-31

### TestSprite (cloud)

- **Bootstrap / plan**: `testsprite_tests/tmp/code_summary.yaml`, `testsprite_tests/testsprite_frontend_test_plan.json`, and `testsprite_tests/standard_prd.json` were generated.
- **Execution**: The CLI reported `AUTH_FAILED` / “Please create a new API_KEY” when posting results to TestSprite’s backend (HTTP 401), even after tunnel connectivity succeeded. **Action**: In the TestSprite product UI, create or rotate an API key and configure the Cursor TestSprite MCP with that key. Optionally set `TESTSPRITE_API_KEY` in the environment and run `node scripts/run-testsprite-execute.mjs` (the script prefers `TESTSPRITE_API_KEY`, then `API_KEY`, then the value in `testsprite_tests/tmp/config.json` if present).
- **Local helper**: [scripts/run-testsprite-execute.mjs](../scripts/run-testsprite-execute.mjs) runs `npx @testsprite/testsprite-mcp generateCodeAndExecute` with credentials.
- **Git**: `testsprite_tests/tmp/` is listed in `.gitignore` so tunnel config and logs are not committed.

### Playwright (local smoke)

With Docker (or any stack) serving **http://localhost:3000** and API **http://localhost:3001**:

```bash
npm install
npm run build --workspace=@wa-ticketing/shared
npx playwright install
npm run test:e2e
```

Default admin login in tests: `admin@example.com` / `Admin123!` (override with `E2E_ADMIN_EMAIL` / `E2E_ADMIN_PASSWORD`).

**Result (2026-03-31)**: All 3 smoke tests passed (login success, login failure message, channels → channel detail).

### Fixes made while validating

1. **401 on login failure**: The global axios interceptor redirected to `/login` on every 401, including failed `POST /auth/login`, so the inline error never appeared. **Fix**: Skip redirect when the request URL includes `/auth/login` ([apps/frontend/src/lib/api.ts](../apps/frontend/src/lib/api.ts)).
2. **API container crash (`ERR_UNKNOWN_FILE_EXTENSION` for `.ts`)**: Runtime imports from `@wa-ticketing/shared` pointed at TypeScript sources. **Fix**: Compile `packages/shared` to `dist/` via `tsc` and set `main`/`exports` to `./dist/types.js`; Dockerfiles run `npm run build --workspace=@wa-ticketing/shared` before building API/frontend.
3. **Existing Postgres volume without new columns**: If `channels.settings` / `tickets.intake` are missing, the API returns 500. Apply migration SQL (as a superuser/owner if `postgres` is not table owner), e.g.:

```bash
docker compose exec -T db psql -U supabase_admin -d postgres -c "ALTER TABLE public.channels ADD COLUMN IF NOT EXISTS settings JSONB NOT NULL DEFAULT '{}'; ALTER TABLE public.tickets ADD COLUMN IF NOT EXISTS intake JSONB NOT NULL DEFAULT '{}';"
```
