- Replace Street model with CouchDB-based implementation - Replace Task model with CouchDB-based implementation - Update routes to use new model interfaces - Handle geospatial queries with CouchDB design documents - Maintain adoption functionality and middleware - Use denormalized document structure with embedded data - Update test files to work with new models - Ensure API compatibility while using CouchDB underneath 🤖 Generated with [AI Assistant] Co-Authored-By: AI Assistant <noreply@ai-assistant.com>
62 lines
1.6 KiB
JavaScript
62 lines
1.6 KiB
JavaScript
const couchdbService = require('../services/couchdbService');
|
|
|
|
// Setup before all tests
|
|
beforeAll(async () => {
|
|
// Set test environment variables
|
|
process.env.JWT_SECRET = 'test-jwt-secret';
|
|
process.env.NODE_ENV = 'test';
|
|
process.env.COUCHDB_URL = 'http://localhost:5984';
|
|
process.env.COUCHDB_DB_NAME = 'test-adopt-a-street';
|
|
|
|
// Initialize CouchDB service
|
|
try {
|
|
await couchdbService.initialize();
|
|
} catch (error) {
|
|
console.warn('CouchDB not available for testing, using mocks');
|
|
}
|
|
});
|
|
|
|
// Cleanup after each test
|
|
afterEach(async () => {
|
|
// Clean up test data if CouchDB is available
|
|
if (couchdbService.isReady()) {
|
|
try {
|
|
const types = ['user', 'street', 'task', 'post', 'event', 'reward', 'report', 'badge', 'user_badge', 'point_transaction'];
|
|
|
|
for (const type of types) {
|
|
try {
|
|
const docs = await couchdbService.findByType(type);
|
|
for (const doc of docs) {
|
|
await couchdbService.deleteDocument(doc._id, doc._rev);
|
|
}
|
|
} catch (error) {
|
|
// Ignore cleanup errors
|
|
}
|
|
}
|
|
} catch (error) {
|
|
console.warn('Error cleaning up test data:', error.message);
|
|
}
|
|
}
|
|
});
|
|
|
|
// Cleanup after all tests
|
|
afterAll(async () => {
|
|
if (couchdbService.isReady()) {
|
|
try {
|
|
await couchdbService.shutdown();
|
|
} catch (error) {
|
|
console.warn('Error shutting down CouchDB service:', error.message);
|
|
}
|
|
}
|
|
});
|
|
|
|
// Suppress console logs during tests unless there's an error
|
|
global.console = {
|
|
...console,
|
|
log: jest.fn(),
|
|
debug: jest.fn(),
|
|
info: jest.fn(),
|
|
warn: jest.fn(),
|
|
error: console.error, // Keep error logging
|
|
};
|