# ๐Ÿงช Test Client Quick Reference ## ๐Ÿš€ Getting Started ### 1. Start Server ```bash npm run dev ``` ### 2. Open Test Client ``` Open test-client.html in your browser ``` ### 3. Connect - **Anonymous:** Leave token field empty โ†’ Click "Connect" - **Authenticated:** Paste JWT token โ†’ Click "Connect" --- ## ๐Ÿ“ก WebSocket Tests ### Basic Tests | Action | Button/Field | Expected Result | |--------|--------------|-----------------| | Connect | "Connect" button | Status: โœ… Connected | | Ping | "Send Ping" button | Receive pong response | | Custom | Edit JSON field + "Send Message" | Custom response | | Disconnect | "Disconnect" button | Status: โŒ Disconnected | ### Custom Message Examples ```json {"type": "ping"} {"type": "custom", "data": {"test": true}} {"type": "subscribe", "channel": "marketplace"} ``` --- ## ๐Ÿ”ฅ Stress Tests ### Gradual Test 1. Set **Number of Messages**: 10-1000 2. Set **Interval (ms)**: 10-5000 3. Click **"๐Ÿš€ Run Stress Test"** 4. Monitor progress in real-time 5. Click **"โน๏ธ Stop Test"** to abort ### Recommended Tests - **Light:** 10 msgs @ 500ms - **Medium:** 100 msgs @ 100ms - **Heavy:** 500 msgs @ 50ms - **Extreme:** 1000 msgs @ 10ms ### Burst Test - Click **"๐Ÿ’ฅ Send Burst (100 msgs)"** - Sends 100 messages instantly - Tests rapid-fire handling --- ## ๐Ÿ›’ Marketplace API Tests ### Prerequisites ``` 1. Login: http://localhost:3000/auth/steam 2. Set trade URL (required for creating listings) 3. Keep WebSocket connected to receive broadcasts ``` ### Get Listings **Fields:** - Game: All / CS2 / Rust - Min Price: (optional) - Max Price: (optional) **Button:** "Get Listings" **Response:** List of marketplace items --- ### Create Listing **Fields:** - Item Name: "AK-47 | Redline" - Game: CS2 / Rust - Price: 45.99 - Description: (optional) **Button:** "Create Listing (Requires Auth)" **Expected:** - โœ… Success response - ๐Ÿ“ก WebSocket broadcast: `new_listing` --- ### Update Price **Fields:** - Listing ID: "listing_123" - New Price: 39.99 **Button:** "Update Price (Requires Auth)" **Expected:** - โœ… Success response - ๐Ÿ“ก WebSocket broadcast: `price_update` --- ### Set Trade URL **Field:** - Steam Trade URL: `https://steamcommunity.com/tradeoffer/new/?partner=...` **Button:** "Set Trade URL (Requires Auth)" **Format:** Must be valid Steam trade offer URL: ``` https://steamcommunity.com/tradeoffer/new/?partner=XXXXXXXXX&token=XXXXXXXX ``` **Expected:** โœ… Trade URL saved **Note:** Both PUT and PATCH methods supported --- ## ๐Ÿ“Š Statistics ### Real-Time Counters - **Messages Received:** Total WebSocket messages received - **Messages Sent:** Total WebSocket messages sent - **Connection Time:** How long connected (updates every second) --- ## ๐Ÿ’ฌ Messages Panel ### Message Types - **๐ŸŸข Received:** Messages from server (green border) - **๐Ÿ”ต Sent:** Messages sent to server (blue border) - **๐Ÿ”ด Error:** Errors and disconnections (red border) ### Message Format ``` [Time] 10:30:45 AM [Type] PING / API / CONNECTION / ERROR [Content] JSON or text content ``` ### Clear Messages Click **"Clear Messages"** button to reset the message log --- ## ๐ŸŽฏ Quick Test Scenarios ### Scenario 1: Basic WebSocket Test (30 seconds) ``` 1. Connect (anonymous) 2. Send Ping 3. Verify pong received 4. Send custom message 5. Disconnect โœ… WebSocket working ``` ### Scenario 2: Stress Test (1 minute) ``` 1. Connect 2. Set: 100 msgs @ 100ms 3. Run Stress Test 4. Verify all received 5. Run Burst Test โœ… Socket stable under load ``` ### Scenario 3: Marketplace Test (2 minutes) ``` 1. Login via Steam 2. Set trade URL 3. Create listing 4. Verify broadcast received 5. Update price 6. Verify broadcast received โœ… Marketplace working ``` ### Scenario 4: Multi-Client Test (3 minutes) ``` 1. Open 2 browser tabs 2. Connect both to WebSocket 3. Tab 1: Create listing 4. Tab 2: Should receive broadcast 5. Tab 1: Update price 6. Tab 2: Should receive update โœ… Broadcasting working ``` --- ## ๐Ÿ” Troubleshooting ### Can't Connect to WebSocket ``` โœ“ Check server is running: curl http://localhost:3000/health โœ“ Verify URL: ws://localhost:3000/ws โœ“ Try anonymous connection first โœ“ Check firewall settings ``` ### CORS Errors ``` โœ“ Server configured to allow file:// protocol โœ“ Restart server if you just updated config โœ“ All localhost ports allowed in development ``` ### 401 Unauthorized ``` โœ“ Login: http://localhost:3000/auth/steam โœ“ Check cookies are enabled โœ“ Clear cookies and login again ``` ### No Broadcasts Received ``` โœ“ Verify WebSocket is connected โœ“ Check you're on the right channel โœ“ Try reconnecting WebSocket โœ“ Check server logs ``` ### Stress Test Connection Drops ``` โœ“ Reduce message count โœ“ Increase interval โœ“ Expected at >500 msgs โœ“ Check server rate limiting ``` --- ## ๐Ÿ”— Quick Links ### Server Endpoints - Health: http://localhost:3000/health - API Info: http://localhost:3000/ - Steam Login: http://localhost:3000/auth/steam - Current User: http://localhost:3000/auth/me - Listings: http://localhost:3000/marketplace/listings ### WebSocket - Connection: ws://localhost:3000/ws - With Token: ws://localhost:3000/ws?token=YOUR_TOKEN --- ## ๐Ÿ“‹ Test Checklist ### Basic Tests - [ ] Anonymous WebSocket connection - [ ] Authenticated WebSocket connection - [ ] Send ping/pong - [ ] Send custom message - [ ] View statistics - [ ] Clear messages ### Stress Tests - [ ] Gradual test (10 msgs) - [ ] Gradual test (100 msgs) - [ ] Burst test (100 msgs) - [ ] Connection stays stable - [ ] All messages received ### Marketplace Tests - [ ] Get all listings - [ ] Filter by game - [ ] Filter by price - [ ] Create listing - [ ] Update price - [ ] Set trade URL - [ ] Receive broadcasts ### Multi-Client Tests - [ ] Open 2 browsers - [ ] Both receive broadcasts - [ ] Create listing in one - [ ] Verify other receives it --- ## ๐Ÿ’ก Tips ### Performance - Clear messages before large tests - Monitor browser console for errors - Check server logs for issues - Document test results ### Authentication - Login via Steam first - Token stored in cookies automatically - Token expires after 15 minutes - Refresh by logging in again ### Broadcasting - Keep WebSocket connected - Multiple clients can connect - Broadcasts are real-time - Check Messages panel for updates ### Stress Testing - Start small (10 messages) - Gradually increase load - Document breaking points - Test reconnection after stress --- ## ๐Ÿ“š Related Documentation - **TESTING_GUIDE.md** - Comprehensive testing guide - **WEBSOCKET_AUTH.md** - Authentication details - **WEBSOCKET_GUIDE.md** - WebSocket features - **NEW_FEATURES.md** - Latest features - **FIXED.md** - Known issues and fixes --- ## ๐ŸŽ“ Keyboard Shortcuts *(Future enhancement)* - `Ctrl+Enter` - Send message - `Ctrl+K` - Clear messages - `Ctrl+R` - Reconnect WebSocket - `Esc` - Stop stress test --- ## ๐Ÿ“ž Need Help? 1. Check browser console (F12) 2. Check server logs 3. See TESTING_GUIDE.md 4. Check FIXED.md for known issues 5. Verify server is running --- **Last Updated:** After Issue #8 (CORS fix for file:// protocol) **Status:** โœ… All features working **Quick Test:** Open test-client.html โ†’ Click Connect โ†’ Click Send Ping โ†’ Verify pong received