-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.errors.test.js
More file actions
32 lines (28 loc) · 1.13 KB
/
Copy pathserver.errors.test.js
File metadata and controls
32 lines (28 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { jest } from '@jest/globals';
describe('500 Error Handling', () => {
let request;
let app;
beforeAll(async () => {
jest.unstable_mockModule('./services/ai.js', () => ({
analyzeJournal: jest.fn().mockRejectedValue(new Error('Simulated AI failure')),
chatWithAI: jest.fn().mockResolvedValue({ reply: 'Test fallback reply', provider: 'test' }),
analyzeWithGemini: jest.fn(),
callOpenRouter: jest.fn(),
analyzeWithOpenRouter: jest.fn(),
getFallbackAnalysis: jest.fn(),
}));
const supertest = await import('supertest');
const server = await import('./server.js');
request = supertest.default;
app = server.default;
}, 30000);
test('POST /api/analyze-journal should return 500 on AI service failure', async () => {
const res = await request(app)
.post('/api/analyze-journal')
.send({ entry: 'This is a test entry for error handling simulation purposes.', exam: 'NEET' });
expect(res.status).toBe(500);
expect(res.body.error).toBeDefined();
expect(typeof res.body.error).toBe('string');
expect(res.body.error.length).toBeGreaterThan(0);
}, 30000);
});