feat: Complete CouchDB test infrastructure migration for route tests

- 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>
This commit is contained in:
William Valentin
2025-11-02 22:57:08 -08:00
parent d9b7b78b0d
commit 6070474404
19 changed files with 1141 additions and 394 deletions

View File

@@ -1,49 +1,42 @@
const request = require("supertest");
const mongoose = require("mongoose");
const { MongoMemoryServer } = require("mongodb-memory-server");
const app = require("../server");
const Street = require("../models/Street");
const User = require("../models/User");
const couchdbService = require("../services/couchdbService");
describe("Geospatial Queries", () => {
let mongoServer;
let testUser;
let authToken;
beforeAll(async () => {
mongoServer = await MongoMemoryServer.create();
const mongoUri = mongoServer.getUri();
await mongoose.connect(mongoUri);
// Initialize CouchDB for testing
await couchdbService.initialize();
// Create test user
testUser = new User({
testUser = await User.create({
name: "Test User",
email: "test@example.com",
password: "password123",
});
await testUser.save();
// Generate auth token
const jwt = require("jsonwebtoken");
authToken = jwt.sign(
{ user: { id: testUser._id.toString() } },
{ user: { id: testUser._id } },
process.env.JWT_SECRET || "test_secret"
);
});
afterAll(async () => {
await mongoose.disconnect();
await mongoServer.stop();
await couchdbService.shutdown();
});
beforeEach(async () => {
// Clean up streets before each test
await Street.deleteMany({});
const streets = await couchdbService.findByType('street');
for (const street of streets) {
await couchdbService.deleteDocument(street._id, street._rev);
}
});
describe("Street Creation with Coordinates", () => {