fixed skipped tests
This commit is contained in:
@@ -46,18 +46,18 @@ jest.mock('sequelize', () => ({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
jest.mock('../../../middleware/auth', () => ({
|
jest.mock('../../../middleware/auth', () => ({
|
||||||
authenticateToken: (req, res, next) => {
|
authenticateToken: jest.fn((req, res, next) => {
|
||||||
req.user = { id: 'user-123', role: 'user', isVerified: true };
|
req.user = { id: 'user-123', role: 'user', isVerified: true };
|
||||||
next();
|
next();
|
||||||
},
|
}),
|
||||||
requireAdmin: (req, res, next) => {
|
requireAdmin: jest.fn((req, res, next) => {
|
||||||
if (req.user && req.user.role === 'admin') {
|
if (req.user && req.user.role === 'admin') {
|
||||||
next();
|
next();
|
||||||
} else {
|
} else {
|
||||||
res.status(403).json({ error: 'Admin access required' });
|
res.status(403).json({ error: 'Admin access required' });
|
||||||
}
|
}
|
||||||
},
|
}),
|
||||||
optionalAuth: (req, res, next) => next(),
|
optionalAuth: jest.fn((req, res, next) => next()),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
jest.mock('../../../utils/logger', () => ({
|
jest.mock('../../../utils/logger', () => ({
|
||||||
@@ -97,6 +97,7 @@ jest.mock('../../../config/imageLimits', () => ({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
const { ForumPost, ForumComment, PostTag, User } = require('../../../models');
|
const { ForumPost, ForumComment, PostTag, User } = require('../../../models');
|
||||||
|
const { authenticateToken } = require('../../../middleware/auth');
|
||||||
const forumRoutes = require('../../../routes/forum');
|
const forumRoutes = require('../../../routes/forum');
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
@@ -1072,32 +1073,22 @@ describe('Forum Routes', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Admin routes tests - skipped due to complex mock requirements
|
describe('Forum Admin Routes', () => {
|
||||||
describe.skip('Forum Admin Routes', () => {
|
|
||||||
let adminApp;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
|
|
||||||
// Create app with admin user
|
// Override auth mock to use admin user
|
||||||
adminApp = express();
|
authenticateToken.mockImplementation((req, res, next) => {
|
||||||
adminApp.use(express.json());
|
req.user = { id: 'admin-123', role: 'admin', isVerified: true };
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// Override auth middleware to set admin user
|
afterEach(() => {
|
||||||
jest.resetModules();
|
// Reset back to regular user for other test suites
|
||||||
jest.doMock('../../../middleware/auth', () => ({
|
authenticateToken.mockImplementation((req, res, next) => {
|
||||||
authenticateToken: (req, res, next) => {
|
req.user = { id: 'user-123', role: 'user', isVerified: true };
|
||||||
req.user = { id: 'admin-123', role: 'admin', isVerified: true };
|
next();
|
||||||
next();
|
|
||||||
},
|
|
||||||
requireAdmin: (req, res, next) => next(),
|
|
||||||
optionalAuth: (req, res, next) => next(),
|
|
||||||
}));
|
|
||||||
|
|
||||||
const forumRoutesAdmin = require('../../../routes/forum');
|
|
||||||
adminApp.use('/forum', forumRoutesAdmin);
|
|
||||||
adminApp.use((err, req, res, next) => {
|
|
||||||
res.status(500).json({ error: err.message });
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1114,7 +1105,7 @@ describe.skip('Forum Admin Routes', () => {
|
|||||||
ForumPost.findByPk.mockResolvedValue(mockPost);
|
ForumPost.findByPk.mockResolvedValue(mockPost);
|
||||||
User.findByPk.mockResolvedValue({ id: 'admin-123', firstName: 'Admin' });
|
User.findByPk.mockResolvedValue({ id: 'admin-123', firstName: 'Admin' });
|
||||||
|
|
||||||
const response = await request(adminApp)
|
const response = await request(app)
|
||||||
.delete('/forum/admin/posts/post-1')
|
.delete('/forum/admin/posts/post-1')
|
||||||
.send({ reason: 'Violates community guidelines' });
|
.send({ reason: 'Violates community guidelines' });
|
||||||
|
|
||||||
@@ -1127,7 +1118,7 @@ describe.skip('Forum Admin Routes', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should return 400 when reason not provided', async () => {
|
it('should return 400 when reason not provided', async () => {
|
||||||
const response = await request(adminApp)
|
const response = await request(app)
|
||||||
.delete('/forum/admin/posts/post-1')
|
.delete('/forum/admin/posts/post-1')
|
||||||
.send({});
|
.send({});
|
||||||
|
|
||||||
@@ -1138,7 +1129,7 @@ describe.skip('Forum Admin Routes', () => {
|
|||||||
it('should return 404 for non-existent post', async () => {
|
it('should return 404 for non-existent post', async () => {
|
||||||
ForumPost.findByPk.mockResolvedValue(null);
|
ForumPost.findByPk.mockResolvedValue(null);
|
||||||
|
|
||||||
const response = await request(adminApp)
|
const response = await request(app)
|
||||||
.delete('/forum/admin/posts/non-existent')
|
.delete('/forum/admin/posts/non-existent')
|
||||||
.send({ reason: 'Test reason' });
|
.send({ reason: 'Test reason' });
|
||||||
|
|
||||||
@@ -1153,7 +1144,7 @@ describe.skip('Forum Admin Routes', () => {
|
|||||||
|
|
||||||
ForumPost.findByPk.mockResolvedValue(mockPost);
|
ForumPost.findByPk.mockResolvedValue(mockPost);
|
||||||
|
|
||||||
const response = await request(adminApp)
|
const response = await request(app)
|
||||||
.delete('/forum/admin/posts/post-1')
|
.delete('/forum/admin/posts/post-1')
|
||||||
.send({ reason: 'Test reason' });
|
.send({ reason: 'Test reason' });
|
||||||
|
|
||||||
@@ -1173,7 +1164,7 @@ describe.skip('Forum Admin Routes', () => {
|
|||||||
|
|
||||||
ForumPost.findByPk.mockResolvedValue(mockPost);
|
ForumPost.findByPk.mockResolvedValue(mockPost);
|
||||||
|
|
||||||
const response = await request(adminApp)
|
const response = await request(app)
|
||||||
.patch('/forum/admin/posts/post-1/restore');
|
.patch('/forum/admin/posts/post-1/restore');
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
@@ -1188,7 +1179,7 @@ describe.skip('Forum Admin Routes', () => {
|
|||||||
it('should return 404 for non-existent post', async () => {
|
it('should return 404 for non-existent post', async () => {
|
||||||
ForumPost.findByPk.mockResolvedValue(null);
|
ForumPost.findByPk.mockResolvedValue(null);
|
||||||
|
|
||||||
const response = await request(adminApp)
|
const response = await request(app)
|
||||||
.patch('/forum/admin/posts/non-existent/restore');
|
.patch('/forum/admin/posts/non-existent/restore');
|
||||||
|
|
||||||
expect(response.status).toBe(404);
|
expect(response.status).toBe(404);
|
||||||
@@ -1202,7 +1193,7 @@ describe.skip('Forum Admin Routes', () => {
|
|||||||
|
|
||||||
ForumPost.findByPk.mockResolvedValue(mockPost);
|
ForumPost.findByPk.mockResolvedValue(mockPost);
|
||||||
|
|
||||||
const response = await request(adminApp)
|
const response = await request(app)
|
||||||
.patch('/forum/admin/posts/post-1/restore');
|
.patch('/forum/admin/posts/post-1/restore');
|
||||||
|
|
||||||
expect(response.status).toBe(400);
|
expect(response.status).toBe(400);
|
||||||
@@ -1232,7 +1223,7 @@ describe.skip('Forum Admin Routes', () => {
|
|||||||
ForumPost.findByPk.mockResolvedValue(mockPost);
|
ForumPost.findByPk.mockResolvedValue(mockPost);
|
||||||
User.findByPk.mockResolvedValue({ id: 'admin-123', firstName: 'Admin' });
|
User.findByPk.mockResolvedValue({ id: 'admin-123', firstName: 'Admin' });
|
||||||
|
|
||||||
const response = await request(adminApp)
|
const response = await request(app)
|
||||||
.delete('/forum/admin/comments/comment-1')
|
.delete('/forum/admin/comments/comment-1')
|
||||||
.send({ reason: 'Inappropriate content' });
|
.send({ reason: 'Inappropriate content' });
|
||||||
|
|
||||||
@@ -1246,7 +1237,7 @@ describe.skip('Forum Admin Routes', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should return 400 when reason not provided', async () => {
|
it('should return 400 when reason not provided', async () => {
|
||||||
const response = await request(adminApp)
|
const response = await request(app)
|
||||||
.delete('/forum/admin/comments/comment-1')
|
.delete('/forum/admin/comments/comment-1')
|
||||||
.send({});
|
.send({});
|
||||||
|
|
||||||
@@ -1257,7 +1248,7 @@ describe.skip('Forum Admin Routes', () => {
|
|||||||
it('should return 404 for non-existent comment', async () => {
|
it('should return 404 for non-existent comment', async () => {
|
||||||
ForumComment.findByPk.mockResolvedValue(null);
|
ForumComment.findByPk.mockResolvedValue(null);
|
||||||
|
|
||||||
const response = await request(adminApp)
|
const response = await request(app)
|
||||||
.delete('/forum/admin/comments/non-existent')
|
.delete('/forum/admin/comments/non-existent')
|
||||||
.send({ reason: 'Test reason' });
|
.send({ reason: 'Test reason' });
|
||||||
|
|
||||||
@@ -1272,7 +1263,7 @@ describe.skip('Forum Admin Routes', () => {
|
|||||||
|
|
||||||
ForumComment.findByPk.mockResolvedValue(mockComment);
|
ForumComment.findByPk.mockResolvedValue(mockComment);
|
||||||
|
|
||||||
const response = await request(adminApp)
|
const response = await request(app)
|
||||||
.delete('/forum/admin/comments/comment-1')
|
.delete('/forum/admin/comments/comment-1')
|
||||||
.send({ reason: 'Test reason' });
|
.send({ reason: 'Test reason' });
|
||||||
|
|
||||||
@@ -1299,7 +1290,7 @@ describe.skip('Forum Admin Routes', () => {
|
|||||||
ForumComment.findByPk.mockResolvedValue(mockComment);
|
ForumComment.findByPk.mockResolvedValue(mockComment);
|
||||||
ForumPost.findByPk.mockResolvedValue(mockPost);
|
ForumPost.findByPk.mockResolvedValue(mockPost);
|
||||||
|
|
||||||
const response = await request(adminApp)
|
const response = await request(app)
|
||||||
.patch('/forum/admin/comments/comment-1/restore');
|
.patch('/forum/admin/comments/comment-1/restore');
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
@@ -1315,7 +1306,7 @@ describe.skip('Forum Admin Routes', () => {
|
|||||||
it('should return 404 for non-existent comment', async () => {
|
it('should return 404 for non-existent comment', async () => {
|
||||||
ForumComment.findByPk.mockResolvedValue(null);
|
ForumComment.findByPk.mockResolvedValue(null);
|
||||||
|
|
||||||
const response = await request(adminApp)
|
const response = await request(app)
|
||||||
.patch('/forum/admin/comments/non-existent/restore');
|
.patch('/forum/admin/comments/non-existent/restore');
|
||||||
|
|
||||||
expect(response.status).toBe(404);
|
expect(response.status).toBe(404);
|
||||||
@@ -1329,7 +1320,7 @@ describe.skip('Forum Admin Routes', () => {
|
|||||||
|
|
||||||
ForumComment.findByPk.mockResolvedValue(mockComment);
|
ForumComment.findByPk.mockResolvedValue(mockComment);
|
||||||
|
|
||||||
const response = await request(adminApp)
|
const response = await request(app)
|
||||||
.patch('/forum/admin/comments/comment-1/restore');
|
.patch('/forum/admin/comments/comment-1/restore');
|
||||||
|
|
||||||
expect(response.status).toBe(400);
|
expect(response.status).toBe(400);
|
||||||
@@ -1351,7 +1342,7 @@ describe.skip('Forum Admin Routes', () => {
|
|||||||
ForumComment.findAll.mockResolvedValue([]);
|
ForumComment.findAll.mockResolvedValue([]);
|
||||||
User.findByPk.mockResolvedValue({ id: 'admin-123', firstName: 'Admin' });
|
User.findByPk.mockResolvedValue({ id: 'admin-123', firstName: 'Admin' });
|
||||||
|
|
||||||
const response = await request(adminApp)
|
const response = await request(app)
|
||||||
.patch('/forum/admin/posts/post-1/close');
|
.patch('/forum/admin/posts/post-1/close');
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
@@ -1364,7 +1355,7 @@ describe.skip('Forum Admin Routes', () => {
|
|||||||
it('should return 404 for non-existent post', async () => {
|
it('should return 404 for non-existent post', async () => {
|
||||||
ForumPost.findByPk.mockResolvedValue(null);
|
ForumPost.findByPk.mockResolvedValue(null);
|
||||||
|
|
||||||
const response = await request(adminApp)
|
const response = await request(app)
|
||||||
.patch('/forum/admin/posts/non-existent/close');
|
.patch('/forum/admin/posts/non-existent/close');
|
||||||
|
|
||||||
expect(response.status).toBe(404);
|
expect(response.status).toBe(404);
|
||||||
@@ -1378,7 +1369,7 @@ describe.skip('Forum Admin Routes', () => {
|
|||||||
|
|
||||||
ForumPost.findByPk.mockResolvedValue(mockPost);
|
ForumPost.findByPk.mockResolvedValue(mockPost);
|
||||||
|
|
||||||
const response = await request(adminApp)
|
const response = await request(app)
|
||||||
.patch('/forum/admin/posts/post-1/close');
|
.patch('/forum/admin/posts/post-1/close');
|
||||||
|
|
||||||
expect(response.status).toBe(400);
|
expect(response.status).toBe(400);
|
||||||
@@ -1397,7 +1388,7 @@ describe.skip('Forum Admin Routes', () => {
|
|||||||
|
|
||||||
ForumPost.findByPk.mockResolvedValue(mockPost);
|
ForumPost.findByPk.mockResolvedValue(mockPost);
|
||||||
|
|
||||||
const response = await request(adminApp)
|
const response = await request(app)
|
||||||
.patch('/forum/admin/posts/post-1/reopen');
|
.patch('/forum/admin/posts/post-1/reopen');
|
||||||
|
|
||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
@@ -1411,7 +1402,7 @@ describe.skip('Forum Admin Routes', () => {
|
|||||||
it('should return 404 for non-existent post', async () => {
|
it('should return 404 for non-existent post', async () => {
|
||||||
ForumPost.findByPk.mockResolvedValue(null);
|
ForumPost.findByPk.mockResolvedValue(null);
|
||||||
|
|
||||||
const response = await request(adminApp)
|
const response = await request(app)
|
||||||
.patch('/forum/admin/posts/non-existent/reopen');
|
.patch('/forum/admin/posts/non-existent/reopen');
|
||||||
|
|
||||||
expect(response.status).toBe(404);
|
expect(response.status).toBe(404);
|
||||||
@@ -1425,7 +1416,7 @@ describe.skip('Forum Admin Routes', () => {
|
|||||||
|
|
||||||
ForumPost.findByPk.mockResolvedValue(mockPost);
|
ForumPost.findByPk.mockResolvedValue(mockPost);
|
||||||
|
|
||||||
const response = await request(adminApp)
|
const response = await request(app)
|
||||||
.patch('/forum/admin/posts/post-1/reopen');
|
.patch('/forum/admin/posts/post-1/reopen');
|
||||||
|
|
||||||
expect(response.status).toBe(400);
|
expect(response.status).toBe(400);
|
||||||
|
|||||||
Reference in New Issue
Block a user