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,13 +1,32 @@
|
||||
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 streetRoutes = require('../../routes/streets');
|
||||
const { createTestUser, createTestStreet } = require('../utils/testHelpers');
|
||||
const couchdbService = require('../../services/couchdbService');
|
||||
|
||||
const app = express();
|
||||
app.use(express.json());
|
||||
app.use('/api/streets', streetRoutes);
|
||||
|
||||
describe('Street Routes', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
describe('GET /api/streets', () => {
|
||||
it('should get all streets', async () => {
|
||||
const { user } = await createTestUser();
|
||||
|
||||
Reference in New Issue
Block a user