fix: update model test mocking for CouchDB compatibility
- Replace jest.mock with proper hoisted mocks for Jest compatibility - Add missing CouchDB service methods to mocks (findUserById, create, getById, update) - Update Post model tests to work with static class methods instead of constructor validation - Fix mock service references throughout all model test files 🤖 Generated with [AI Assistant] Co-Authored-By: AI Assistant <noreply@ai-assistant.com>
This commit is contained in:
@@ -1,17 +1,29 @@
|
||||
const User = require('../../models/User');
|
||||
const couchdbService = require('../../services/couchdbService');
|
||||
|
||||
// Mock CouchDB service for testing
|
||||
jest.mock('../../services/couchdbService');
|
||||
const mockCouchdbService = {
|
||||
findUserByEmail: jest.fn(),
|
||||
findUserById: jest.fn(),
|
||||
createDocument: jest.fn(),
|
||||
updateDocument: jest.fn(),
|
||||
findByType: jest.fn(),
|
||||
deleteDocument: jest.fn(),
|
||||
initialize: jest.fn(),
|
||||
isReady: jest.fn().mockReturnValue(true),
|
||||
shutdown: jest.fn()
|
||||
};
|
||||
|
||||
// Mock the service module
|
||||
jest.mock('../../services/couchdbService', () => mockCouchdbService);
|
||||
|
||||
describe('User Model', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
// Reset all mocks to ensure clean state
|
||||
couchdbService.findUserByEmail.mockReset();
|
||||
couchdbService.findUserById.mockReset();
|
||||
couchdbService.createDocument.mockReset();
|
||||
couchdbService.updateDocument.mockReset();
|
||||
mockCouchdbService.findUserByEmail.mockReset();
|
||||
mockCouchdbService.findUserById.mockReset();
|
||||
mockCouchdbService.createDocument.mockReset();
|
||||
mockCouchdbService.updateDocument.mockReset();
|
||||
});
|
||||
|
||||
describe('Schema Validation', () => {
|
||||
|
||||
Reference in New Issue
Block a user