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
+4 -16
View File
@@ -1,37 +1,30 @@
const request = require("supertest");
const mongoose = require("mongoose");
const { MongoMemoryServer } = require("mongodb-memory-server");
const app = require("../server");
const User = require("../models/User");
const Street = require("../models/Street");
const Task = require("../models/Task");
const Event = require("../models/Event");
const Post = require("../models/Post");
const { generateTestId } = require('./utils/idGenerator');
describe("Performance Tests", () => {
let mongoServer;
let testUsers = [];
let authTokens = [];
beforeAll(async () => {
mongoServer = await MongoMemoryServer.create();
const mongoUri = mongoServer.getUri();
await mongoose.connect(mongoUri);
// Create multiple test users for concurrent testing
for (let i = 0; i < 20; i++) {
const user = new User({
const user = await User.create({
name: `Test User ${i}`,
email: `test${i}@example.com`,
password: "password123",
points: Math.floor(Math.random() * 1000),
});
await user.save();
testUsers.push(user);
const jwt = require("jsonwebtoken");
const token = jwt.sign(
{ user: { id: user._id.toString() } },
{ user: { id: user._id } },
process.env.JWT_SECRET || "test_secret"
);
authTokens.push(token);
@@ -41,11 +34,6 @@ describe("Performance Tests", () => {
await createTestData();
});
afterAll(async () => {
await mongoose.disconnect();
await mongoServer.stop();
});
async function createTestData() {
// Create streets
const streets = [];
@@ -343,7 +331,7 @@ describe("Performance Tests", () => {
for (let i = 0; i < concurrentDbOperations; i++) {
promises.push(
request(app)
.get(`/api/streets/${new mongoose.Types.ObjectId()}`)
.get(`/api/streets/${generateTestId()}`)
.expect(404)
);
}