feat: complete Post model standardized error handling

- Add comprehensive error handling to Post model with ValidationError, NotFoundError
- Fix Post model toJSON method duplicate type field bug
- Update Post test suite with proper mocking for all CouchDB service methods
- All 23 Post model tests now passing
- Complete standardized error handling implementation for User, Report, and Post models
- Add modelErrors utility with structured error classes and logging

🤖 Generated with AI Assistant

Co-Authored-By: AI Assistant <noreply@ai-assistant.com>
This commit is contained in:
William Valentin
2025-11-03 09:43:46 -08:00
parent 97f794fca5
commit 07a80b718b
6 changed files with 1044 additions and 339 deletions

View File

@@ -13,11 +13,13 @@ const mockCouchdbService = {
// Mock the service module
jest.mock('../../services/couchdbService', () => mockCouchdbService);
const Report = require('../../models/Report');
describe('Report Model', () => {
beforeEach(() => {
// Reset all mocks to ensure clean state
mockCouchdbService.createDocument.mockReset();
mockCouchdbService.findDocumentById.mockReset();
mockCouchdbService.getDocument.mockReset();
mockCouchdbService.updateDocument.mockReset();
mockCouchdbService.findByType.mockReset();
});
@@ -344,7 +346,7 @@ describe('Report Model', () => {
updatedAt: '2023-01-01T00:00:00.000Z'
};
mockCouchdbService.findDocumentById.mockResolvedValue(mockReport);
mockCouchdbService.getDocument.mockResolvedValue(mockReport);
mockCouchdbService.updateDocument.mockResolvedValue({
...mockReport,
status: 'resolved',
@@ -410,7 +412,7 @@ describe('Report Model', () => {
updatedAt: '2023-01-01T00:00:00.000Z'
};
mockCouchdbService.findDocumentById.mockResolvedValue(mockReport);
mockCouchdbService.getDocument.mockResolvedValue(mockReport);
mockCouchdbService.updateDocument.mockResolvedValue({
...mockReport,
status: 'in_progress',
@@ -476,7 +478,7 @@ describe('Report Model', () => {
updatedAt: '2023-01-01T00:00:00.000Z'
};
mockCouchdbService.findDocumentById.mockResolvedValue(mockReport);
mockCouchdbService.getDocument.mockResolvedValue(mockReport);
const report = await Report.findById('report_123');
expect(report).toBeDefined();
@@ -485,7 +487,7 @@ describe('Report Model', () => {
});
it('should return null when report not found', async () => {
mockCouchdbService.findDocumentById.mockResolvedValue(null);
mockCouchdbService.getDocument.mockResolvedValue(null);
const report = await Report.findById('nonexistent');
expect(report).toBeNull();