fix(test): use valid URI format for plan handle IDs

- Update plan handle ID format to match TimeSafari specification
  - Default format: https://endorser.ch/entity/{26-char-ULID}
  - ULID: 26 characters, Crockford base32 encoded
  - Validates RFC 3986 URI format

- Add ULID generation functions
  - generateULID() creates 26-character Crockford base32 strings
  - generateValidPlanHandleId() creates full URI format IDs
  - Auto-generates valid IDs for testing

- Update DEFAULT_TEST_PROJECT_IDS
  - Now generates valid URI format IDs automatically
  - Removes placeholder warnings (IDs are now valid format)

- Add URI validation to seed scripts
  - Validates plan IDs match RFC 3986 URI format
  - Error messages with format examples
  - Blocks seeding with invalid formats

- Update test-user-zero.ts config
  - Auto-generates valid URI format plan IDs
  - Clear documentation of required format
  - Note that real IDs from database should replace test IDs

- Update documentation
  - Document default URI format specification
  - Explain ULID structure and encoding
  - Show examples of valid formats

This ensures all test project IDs match the actual TimeSafari plan
handle ID format, preventing validation errors during prefetch testing.
This commit is contained in:
Matthew Raymer
2025-10-29 12:20:55 +00:00
parent 7a19a56ea2
commit 848387b532
4 changed files with 128 additions and 73 deletions

View File

@@ -38,33 +38,34 @@ app.use((req, res, next) => {
* Seed test projects on startup
*/
function seedProjects(projectIds = DEFAULT_TEST_PROJECT_IDS) {
// Check if using placeholder IDs
if (projectIds.some(id => id.startsWith('PLACEHOLDER'))) {
console.warn('');
console.warn('⚠️ WARNING: Using placeholder plan handle IDs!');
console.warn(' The test server will work, but you need to:');
console.warn(' 1. Get valid plan handle IDs from your TimeSafari database');
console.warn(' 2. Update test-user-zero.ts with real plan IDs');
console.warn(' 3. Or provide valid IDs via command line:');
console.warn(' node scripts/test-api-server-with-seed.js [port] "id1,id2,id3"');
console.warn('');
console.warn(' For now, the server will use placeholder IDs for testing structure only.');
console.warn('');
// Validate plan IDs are valid URIs
const invalidIds = projectIds.filter(id => !id.match(/^[A-Za-z][A-Za-z0-9+.-]+:/));
if (invalidIds.length > 0) {
console.error('');
console.error('❌ ERROR: Invalid plan handle ID format!');
console.error(' Plan handle IDs must be valid URIs (RFC 3986).');
console.error(' Expected format: https://endorser.ch/entity/{ULID}');
console.error(` Invalid IDs: ${invalidIds.join(', ')}`);
console.error('');
console.error(' Valid examples:');
console.error(' https://endorser.ch/entity/01GQBE7Q0RQQAGJMEEW6RSGKTF');
console.error(' http://example.com/project/123');
console.error(' did:ethr:0x1234...');
console.error('');
process.exit(1);
}
seededProjects = generateAllTestProjects(projectIds);
console.log(`🌱 Seeded ${seededProjects.length} test projects:`);
console.log(`🌱 Seeded ${seededProjects.length} test projects with valid URI format:`);
seededProjects.forEach((project, index) => {
console.log(` ${index + 1}. ${project.planSummary.handleId} - ${project.planSummary.name}`);
});
if (projectIds.some(id => id.startsWith('PLACEHOLDER'))) {
console.log('');
console.log('📝 To use real plan IDs, update:');
console.log(' test-apps/daily-notification-test/src/config/test-user-zero.ts');
console.log(' starredProjects.planIds = ["your", "real", "plan", "ids"]');
console.log('');
}
console.log('');
console.log('📝 Note: These are auto-generated test IDs.');
console.log(' For testing with real projects, use IDs from your TimeSafari database.');
console.log(' Update: test-apps/daily-notification-test/src/config/test-user-zero.ts');
console.log('');
}
/**