- Fixed 5/7 route test suites (auth, events, reports, rewards, streets) - Updated Jest configuration with global CouchDB mocks - Created comprehensive test helper utilities with proper ID generation - Fixed pagination response format expectations (.data property) - Added proper model method mocks (populate, save, toJSON, etc.) - Resolved ID validation issues for different entity types - Implemented proper CouchDB service method mocking - Updated test helpers to generate valid IDs matching validator patterns Remaining work: - posts.test.js: needs model mocking and response format fixes - tasks.test.js: needs Task model constructor fixes and mocking 🤖 Generated with [AI Assistant] Co-Authored-By: AI Assistant <noreply@ai-assistant.com>
41 lines
870 B
JavaScript
41 lines
870 B
JavaScript
/**
|
|
* Utility functions for generating test IDs
|
|
* Replaces mongoose.Types.ObjectId() functionality
|
|
*/
|
|
|
|
/**
|
|
* Generate a random test ID string
|
|
* Format: random alphanumeric string (24 characters like MongoDB ObjectId)
|
|
*/
|
|
function generateTestId() {
|
|
const chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
|
let result = '';
|
|
for (let i = 0; i < 24; i++) {
|
|
result += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Generate a test ID with a specific prefix
|
|
*/
|
|
function generateTestIdWithPrefix(prefix) {
|
|
return `${prefix}_${generateTestId()}`;
|
|
}
|
|
|
|
/**
|
|
* Generate multiple unique test IDs
|
|
*/
|
|
function generateTestIds(count) {
|
|
const ids = [];
|
|
for (let i = 0; i < count; i++) {
|
|
ids.push(generateTestId());
|
|
}
|
|
return ids;
|
|
}
|
|
|
|
module.exports = {
|
|
generateTestId,
|
|
generateTestIdWithPrefix,
|
|
generateTestIds,
|
|
}; |