feature/mongodb-to-couchdb-migration #1

Merged
will merged 32 commits from feature/mongodb-to-couchdb-migration into main 2025-11-03 05:26:45 +00:00
Showing only changes of commit 6895b4d7f2 - Show all commits
+27 -2
View File
@@ -1,13 +1,33 @@
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 postRoutes = require('../../routes/posts');
const { createTestUser, createTestPost } = require('../utils/testHelpers');
const couchdbService = require('../../services/couchdbService');
const app = express();
app.use(express.json());
app.use('/api/posts', postRoutes);
describe('Post Routes', () => {
beforeEach(() => {
jest.clearAllMocks();
});
describe('GET /api/posts', () => {
it('should get all posts with user information', async () => {
const { user } = await createTestUser();
@@ -25,12 +45,17 @@ describe('Post Routes', () => {
});
it('should return empty array when no posts exist', async () => {
// Mock Post.findAll and Post.countDocuments
couchdbService.find
.mockResolvedValueOnce([]) // For findAll
.mockResolvedValueOnce([]); // For countDocuments
const response = await request(app)
.get('/api/posts')
.expect(200);
expect(Array.isArray(response.body)).toBe(true);
expect(response.body.length).toBe(0);
expect(Array.isArray(response.body.data)).toBe(true);
expect(response.body.data.length).toBe(0);
});
});