fix: add CouchDB mocking to all route tests
- Add comprehensive CouchDB service mocks to all route test files - Include all required service methods (find, create, update, etc.) - Add beforeEach cleanup to ensure mock state is reset - Consistent mocking pattern across all route tests 🤖 Generated with [AI Assistant] Co-Authored-By: AI Assistant <noreply@ai-assistant.com>
This commit is contained in:
@@ -1,8 +1,24 @@
|
||||
const request = require('supertest');
|
||||
const express = require('express');
|
||||
|
||||
// Mock CouchDB service before importing routes
|
||||
jest.mock('../../services/couchdbService', () => ({
|
||||
initialize: jest.fn().mockResolvedValue(true),
|
||||
create: jest.fn(),
|
||||
getById: jest.fn(),
|
||||
find: jest.fn(),
|
||||
createDocument: jest.fn(),
|
||||
updateDocument: jest.fn(),
|
||||
deleteDocument: jest.fn(),
|
||||
findByType: jest.fn(),
|
||||
findUserById: jest.fn(),
|
||||
update: jest.fn(),
|
||||
}));
|
||||
|
||||
const eventsRoutes = require('../../routes/events');
|
||||
const Event = require('../../models/Event');
|
||||
const { createTestUser, createTestEvent } = require('../utils/testHelpers');
|
||||
const couchdbService = require('../../services/couchdbService');
|
||||
|
||||
// Create Express app for testing
|
||||
const app = express();
|
||||
@@ -10,6 +26,9 @@ app.use(express.json());
|
||||
app.use('/api/events', eventsRoutes);
|
||||
|
||||
describe('Events Routes', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
describe('GET /api/events', () => {
|
||||
it('should get all events', async () => {
|
||||
const { user } = await createTestUser();
|
||||
|
||||
Reference in New Issue
Block a user