# Kraken Player End-to-End Test Guide

This guide covers a full clean-slate test: API + Web + Player.

## Prereqs
- Postgres is reachable (fresh DB ok).
- API env vars set: `DATABASE_URL`, `JWT_SECRET`, `DEVICE_JWT_SECRET`, `SPACES_*`.
- Web env: `NEXT_PUBLIC_API_URL`.
- Go installed for player builds (or use CI to build an artifact).

## 1) Database + API (clean slate)
1. Apply migrations:
   - `npx prisma migrate deploy`
2. Seed (dev/staging only):
   - Set `RUN_SEED=true` and `SEED_ADMIN_PASSWORD=...`
   - Run: `npm run seed`
3. Start API:
   - `npm run dev`
4. Check health:
   - `GET /health` should return `ok: true`.

## 2) Web app
1. Set `NEXT_PUBLIC_API_URL` (staging or local API).
2. Start web:
   - `npm run dev`
3. Login as `admin@whitecore.ai` (or `SEED_ADMIN_EMAIL`) with `SEED_ADMIN_PASSWORD`.

## 3) Create company + site + license
1. Go to `Users` and create a Company.
2. Go to `Licensing`:
   - Create a Site for the Company.
   - Create a License (plan + seats + AI add-on if needed).

## 4) Player install package (no manual config)

Create a package:
1. Build a package with defaults baked in:
   - `./scripts/package.sh dev`    # → api.dev.whitecore.ai
   - `./scripts/package.sh app1 windows-amd64` # → api1.dev.whitecore.ai
   - `./scripts/package.sh prod`   # → api.whitecore.ai
2. Send the `.tgz` to the client from `dist/`.

Install on device:
1. Copy the package to the Pi and extract it.
2. Run: `sudo ./install.sh`
3. Verify service:
   - `sudo systemctl status kraken-player`
   - `sudo journalctl -u kraken-player -f`

Optional overrides (no config edit):
```bash
API_BASE_URL="https://api.dev.whitecore.ai" DEVICE_NAME="Lobby Screen" sudo ./install.sh
```

## 5) Pairing flow (device-first)
1. On the device, note the pairing code shown in logs (pair status polls every ~15s).
2. In Web -> `Screens` -> `Pair Screen`:
   - Enter pairing code.
   - Select Company (super admin only) and Site.
   - Click `Approve Pairing`.
3. Screen should appear and become ONLINE once heartbeat starts.

## 6) Media upload
1. Go to `Media`.
2. Upload images/videos (or use Canva import if PRIME/NEXUS).

## 7) Presentation creation
1. Go to `Presentations`.
2. Create a presentation, add media widgets, save.

## 8) Playlist + assignment
1. Create a playlist and add presentations.
2. Assign the playlist to the paired screen.

## 9) Playback verification
1. Player logs should show playlist/layout/media fetch.
2. The screen should render the presentation fullscreen.

## 10) Scheduling (optional)
1. Create a schedule for the screen.
2. Confirm playlist changes based on schedule window.

## 11) Device control
1. Go to `Device Control`.
2. Send commands (volume, restart player, reboot).
3. Confirm command status updates and device behavior.

## 12) Vision AI triggers (config validation only)
1. Ensure the tenant has Vision AI enabled.
2. Add AI Triggers in a presentation.
3. Verify `/players/:id/ai-triggers` returns rules.
4. Note: real AI event evaluation is not implemented on the player yet.

## Troubleshooting
- Pairing code expired: restart player to re-issue, then approve again.
- Device already paired: revoke device in `Licensing` then retry pairing.
- No licenses available: create/add more seats.
- Media playback fails: verify `SPACES_*` env vars and Spaces access.
