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,9 +1,25 @@
|
||||
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 rewardsRoutes = require('../../routes/rewards');
|
||||
const Reward = require('../../models/Reward');
|
||||
const User = require('../../models/User');
|
||||
const { createTestUser, createTestReward } = require('../utils/testHelpers');
|
||||
const couchdbService = require('../../services/couchdbService');
|
||||
|
||||
// Create Express app for testing
|
||||
const app = express();
|
||||
@@ -11,6 +27,9 @@ app.use(express.json());
|
||||
app.use('/api/rewards', rewardsRoutes);
|
||||
|
||||
describe('Rewards Routes', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
describe('GET /api/rewards', () => {
|
||||
it('should get all rewards', async () => {
|
||||
await createTestReward({ name: 'Reward 1', pointsCost: 50 });
|
||||
|
||||
Reference in New Issue
Block a user