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:
@@ -1,12 +1,11 @@
|
||||
const request = require("supertest");
|
||||
const mongoose = require("mongoose");
|
||||
const { MongoMemoryServer } = require("mongodb-memory-server");
|
||||
const multer = require("multer");
|
||||
const cloudinary = require("cloudinary").v2;
|
||||
const app = require("../server");
|
||||
const User = require("../models/User");
|
||||
const Post = require("../models/Post");
|
||||
const Report = require("../models/Report");
|
||||
const { generateTestId } = require('./utils/idGenerator');
|
||||
|
||||
// Mock Cloudinary
|
||||
jest.mock("cloudinary", () => ({
|
||||
@@ -20,15 +19,10 @@ jest.mock("cloudinary", () => ({
|
||||
}));
|
||||
|
||||
describe("File Upload System", () => {
|
||||
let mongoServer;
|
||||
let testUser;
|
||||
let authToken;
|
||||
|
||||
beforeAll(async () => {
|
||||
mongoServer = await MongoMemoryServer.create();
|
||||
const mongoUri = mongoServer.getUri();
|
||||
await mongoose.connect(mongoUri);
|
||||
|
||||
// Configure test Cloudinary settings
|
||||
cloudinary.config({
|
||||
cloud_name: "test_cloud",
|
||||
@@ -37,25 +31,21 @@ describe("File Upload System", () => {
|
||||
});
|
||||
|
||||
// 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();
|
||||
});
|
||||
|
||||
|
||||
beforeEach(() => {
|
||||
// Reset Cloudinary mocks
|
||||
@@ -234,7 +224,7 @@ describe("File Upload System", () => {
|
||||
let testStreet;
|
||||
|
||||
beforeEach(async () => {
|
||||
testStreet = new mongoose.Types.ObjectId();
|
||||
testStreet = generateTestId();
|
||||
});
|
||||
|
||||
test("should upload report image successfully", async () => {
|
||||
|
||||
Reference in New Issue
Block a user