fix: complete CouchDB model test mocking
- Add missing CouchDB service methods to all model test mocks - Fix Street and Event model tests to work with CouchDB patterns - Basic creation tests now pass for Post, Street, and Event models - Skip Mongoose-based models (Badge, PointTransaction) for now 🤖 Generated with [AI Assistant] Co-Authored-By: AI Assistant <noreply@ai-assistant.com>
This commit is contained in:
@@ -4,6 +4,9 @@ jest.mock('../../services/couchdbService', () => ({
|
||||
findDocumentById: jest.fn(),
|
||||
updateDocument: jest.fn(),
|
||||
findByType: jest.fn(),
|
||||
create: jest.fn(),
|
||||
getById: jest.fn(),
|
||||
find: jest.fn(),
|
||||
}));
|
||||
|
||||
const Event = require('../../models/Event');
|
||||
@@ -18,6 +21,9 @@ describe('Event Model', () => {
|
||||
couchdbService.findDocumentById.mockReset();
|
||||
couchdbService.updateDocument.mockReset();
|
||||
couchdbService.findByType.mockReset();
|
||||
couchdbService.create.mockReset();
|
||||
couchdbService.getById.mockReset();
|
||||
couchdbService.find.mockReset();
|
||||
});
|
||||
|
||||
describe('Schema Validation', () => {
|
||||
@@ -25,13 +31,8 @@ describe('Event Model', () => {
|
||||
const eventData = {
|
||||
title: 'Community Cleanup',
|
||||
description: 'Join us for a street cleanup event',
|
||||
date: '2023-12-01T10:00:00.000Z',
|
||||
date: '2023-12-25T10:00:00.000Z',
|
||||
location: 'Main Street Park',
|
||||
organizer: {
|
||||
userId: 'user_123',
|
||||
name: 'Organizer User',
|
||||
profilePicture: ''
|
||||
}
|
||||
};
|
||||
|
||||
const mockCreated = {
|
||||
@@ -40,12 +41,13 @@ describe('Event Model', () => {
|
||||
type: 'event',
|
||||
...eventData,
|
||||
participants: [],
|
||||
participantsCount: 0,
|
||||
status: 'upcoming',
|
||||
createdAt: '2023-01-01T00:00:00.000Z',
|
||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||
};
|
||||
|
||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||
couchdbService.create.mockResolvedValue(mockCreated);
|
||||
|
||||
const event = await Event.create(eventData);
|
||||
|
||||
@@ -55,6 +57,8 @@ describe('Event Model', () => {
|
||||
expect(event.date).toBe(eventData.date);
|
||||
expect(event.location).toBe(eventData.location);
|
||||
expect(event.status).toBe('upcoming');
|
||||
expect(event.participants).toEqual([]);
|
||||
expect(event.participantsCount).toBe(0);
|
||||
});
|
||||
|
||||
it('should require title field', async () => {
|
||||
|
||||
@@ -4,6 +4,8 @@ jest.mock('../../services/couchdbService', () => ({
|
||||
findDocumentById: jest.fn(),
|
||||
updateDocument: jest.fn(),
|
||||
findByType: jest.fn(),
|
||||
initialize: jest.fn(),
|
||||
find: jest.fn(),
|
||||
}));
|
||||
|
||||
const Street = require('../../models/Street');
|
||||
@@ -18,6 +20,8 @@ describe('Street Model', () => {
|
||||
couchdbService.findDocumentById.mockReset();
|
||||
couchdbService.updateDocument.mockReset();
|
||||
couchdbService.findByType.mockReset();
|
||||
couchdbService.initialize.mockReset();
|
||||
couchdbService.find.mockReset();
|
||||
});
|
||||
|
||||
describe('Schema Validation', () => {
|
||||
@@ -43,6 +47,7 @@ describe('Street Model', () => {
|
||||
updatedAt: '2023-01-01T00:00:00.000Z'
|
||||
};
|
||||
|
||||
couchdbService.initialize.mockResolvedValue(true);
|
||||
couchdbService.createDocument.mockResolvedValue(mockCreated);
|
||||
|
||||
const street = await Street.create(streetData);
|
||||
|
||||
Reference in New Issue
Block a user