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:
William Valentin
2025-11-01 13:49:42 -07:00
parent 5aca521c52
commit 256dd85e2e
11 changed files with 4155 additions and 409 deletions

View File

@@ -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', () => {