feat: Migrate Street and Task models from MongoDB to CouchDB

- 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>
This commit is contained in:
William Valentin
2025-11-01 13:12:34 -07:00
parent 2961107136
commit 7c7bc954ef
14 changed files with 1943 additions and 928 deletions

View File

@@ -1,38 +1,53 @@
const { MongoMemoryServer } = require('mongodb-memory-server');
const mongoose = require('mongoose');
let mongoServer;
const couchdbService = require('../services/couchdbService');
// Setup before all tests
beforeAll(async () => {
// Create in-memory MongoDB instance
mongoServer = await MongoMemoryServer.create();
const mongoUri = mongoServer.getUri();
// 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';
// Connect to in-memory database
await mongoose.connect(mongoUri, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
// Initialize CouchDB service
try {
await couchdbService.initialize();
} catch (error) {
console.warn('CouchDB not available for testing, using mocks');
}
});
// Cleanup after each test
afterEach(async () => {
const collections = mongoose.connection.collections;
for (const key in collections) {
await collections[key].deleteMany({});
// 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 () => {
await mongoose.connection.dropDatabase();
await mongoose.connection.close();
await mongoServer.stop();
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