feat(test): add project seeding utilities for localhost testing

- Add seed-test-projects.js utility script
  - Generates test project data matching API schema
  - Creates projects with handleIds, jwtIds, planSummary, previousClaim
  - Supports export, seed, and generate commands
  - Can seed projects to localhost API server

- Add test-api-server-with-seed.js
  - Standalone Express server for localhost testing
  - Auto-seeds test projects on startup
  - Implements /api/v2/report/plansLastUpdatedBetween endpoint
  - Includes debugging endpoints (/api/test/projects, /api/test/health)
  - Ready to use immediately without database setup

- Update localhost testing guide
  - Add seeding instructions and examples
  - Document test API server usage
  - Explain how to integrate with existing API servers

This enables testing prefetch functionality even when your localhost
API has no project data. The test server can be started immediately
and provides 5 seeded test projects ready for prefetch queries.
This commit is contained in:
Matthew Raymer
2025-10-29 12:13:59 +00:00
parent 1bf39fd1f7
commit f5dca34e84
3 changed files with 491 additions and 7 deletions

View File

@@ -24,15 +24,39 @@ On Android emulator, `localhost` (127.0.0.1) refers to the **emulator itself**,
### 1. Start Your Local Development Server
Start your TimeSafari API server on your host machine:
You have two options:
#### Option A: Use the Test API Server (Recommended for Quick Testing)
The plugin includes a ready-to-use test API server with automatic project seeding:
```bash
# Example: If using Node.js/Express
cd /path/to/timesafari-api
npm start
# Server starts on http://localhost:3000
cd /home/matthew/projects/timesafari/daily-notification-plugin
node scripts/test-api-server-with-seed.js [port]
# Default port: 3000
# Starts on http://localhost:3000
```
This server:
- ✅ Automatically seeds test projects on startup
- ✅ Implements the `/api/v2/report/plansLastUpdatedBetween` endpoint
- ✅ Ready to use immediately with test-project-1, test_project_2, etc.
- ✅ Provides debugging endpoints to view seeded projects
#### Option B: Use Your Existing TimeSafari API Server
If you have your own localhost API server, seed test projects into it:
```bash
# Seed projects to your existing API server
node scripts/seed-test-projects.js seed http://localhost:3000
# Or export projects as JSON for manual import
node scripts/seed-test-projects.js export test-projects.json
```
Then ensure your server implements the endpoint as described in the "Localhost API Server Requirements" section below.
### 2. Configure Test App for Localhost
Edit `test-apps/daily-notification-test/src/config/test-user-zero.ts`:
@@ -160,9 +184,48 @@ Your localhost API server must implement:
- `Content-Type: application/json`
- `User-Agent: TimeSafari-DailyNotificationPlugin/1.0.0`
## Quick Test Script
## Seeding Test Projects
Create a minimal localhost API server for testing:
If your localhost API has no projects, you can seed test data using the included scripts:
### Generate Test Projects
```bash
# Generate test projects and display as JSON
node scripts/seed-test-projects.js generate
# Export projects to JSON file
node scripts/seed-test-projects.js export test-projects.json
# Seed projects directly to your API server
node scripts/seed-test-projects.js seed http://localhost:3000
# Use custom project IDs
node scripts/seed-test-projects.js seed http://localhost:3000 "project_1,project_2,project_3"
```
The seed script generates test projects matching the structure expected by the plugin, including:
- `handleId` (from your config)
- `jwtId` (timestamp-based for pagination)
- `planSummary` (name, description, dates, location)
- `previousClaim` (for change detection)
### Using the Test API Server (Includes Seeding)
The easiest way is to use the included test API server:
```bash
node scripts/test-api-server-with-seed.js
```
This server:
1. Seeds 5 test projects automatically on startup
2. Provides the prefetch endpoint ready to use
3. Includes debugging endpoints
## Quick Test Script (Alternative)
If you want to create your own minimal localhost API server:
```javascript
// test-api-server.js
@@ -217,6 +280,8 @@ Run with:
node test-api-server.js
```
**Note**: The included `scripts/test-api-server-with-seed.js` provides the same functionality plus automatic seeding, so you may prefer to use that instead.
## Troubleshooting
### Prefetch Not Executing