# BaoLife Testing Guide

Testing runbook for backend (`server/`) and event-system v2 platform migrations.

## Quick Start

```bash
# Backend
cd server
npm install
npm run build
npm test

# iOS
cd ../ios
xcodebuild -project lichunWebsocket.xcodeproj -scheme BaoLife -configuration Debug build

# Android
cd ../android
./gradlew test lint
```

## Event System v2 Targeted Suites

Run these first when changing event protocol/runtime code.

### Backend (v2 runtime guards and dispatch)

```bash
cd server
npm test -- tests/handlers/events.v2.dispatch.test.ts
npm test -- tests/handlers/events.dispatch.regression.test.ts
npm test -- tests/events-v2/protocol.schema.test.ts
npm test -- tests/events-v2/legacy-removal.guard.test.ts
npm test -- tests/events-v2/no-legacy-runtime.test.ts
```

### iOS (v2 protocol + rendering)

```bash
cd ios
xcodebuild test -project lichunWebsocket.xcodeproj -scheme BaoLife -destination 'platform=iOS Simulator,name=iPhone 15' -only-testing:lichunWebsocketTests/EventV2DecodingTests
xcodebuild test -project lichunWebsocket.xcodeproj -scheme BaoLife -destination 'platform=iOS Simulator,name=iPhone 15' -only-testing:lichunWebsocketTests/EventV2ResponseTests
xcodebuild test -project lichunWebsocket.xcodeproj -scheme BaoLife -destination 'platform=iOS Simulator,name=iPhone 15' -only-testing:lichunWebsocketTests/EventV2RenderingTests
```

### Android (v2 protocol + rendering)

```bash
cd android
./gradlew testDebugUnitTest --tests com.craigvg.lichun_android.network.EventV2ParsingTest
./gradlew testDebugUnitTest --tests com.craigvg.lichun_android.network.EventV2ResponsePayloadTest
./gradlew testDebugUnitTest --tests com.craigvg.lichun_android.ui.EventV2RenderTest
```

## Protocol Contract Checks

### Valid response payload shape (client -> server)

```json
{
  "type": "eventResponse",
  "message": {
    "eventId": "event_id_here",
    "choiceId": "choice_id_here"
  }
}
```

### Legacy payloads that should be rejected

- `questionEvent` answer payloads without `_callbackData`
- fallback generic command dispatch that depended on `allEvents`

## Full Verification Matrix

### Backend

```bash
cd server
npm run build
npm test
npm run test:coverage
```

### iOS

```bash
cd ios
xcodebuild -project lichunWebsocket.xcodeproj -scheme BaoLife -configuration Debug build
xcodebuild test -project lichunWebsocket.xcodeproj -scheme BaoLife -destination 'platform=iOS Simulator,name=iPhone 15'
```

### Android

```bash
cd android
./gradlew assembleDebug
./gradlew test
./gradlew lint
```

## Notes

- Integration tests may be skipped when a live local server is not available.
- If `npm test` in `server/` is resource-heavy on local machines, run targeted v2 suites first, then broader suites.
- See `docs/EVENT_SYSTEM_V2.md` for event protocol and runtime details.
