Skip to content

Commit 5f2e715

Browse files
committed
Fix issues with tests
1 parent 9d91801 commit 5f2e715

File tree

4 files changed

+36
-4
lines changed

4 files changed

+36
-4
lines changed

api/__tests__/api.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ describe('API Integration Tests', () => {
214214
nock.cleanAll();
215215
nock('http://ollama:11434')
216216
.post('/api/chat')
217-
.delay(125000) // Longer than our 120 second timeout
218-
.reply(200, { message: { content: 'Response' } });
217+
.delay(2000) // Short delay that won't timeout but will test timeout handling
218+
.replyWithError({ code: 'ECONNABORTED', message: 'timeout of 120000ms exceeded' });
219219

220220
const response = await request(app)
221221
.post('/chat/default')

api/__tests__/e2e.test.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,39 @@ const nock = require('nock');
33
const path = require('path');
44
const fs = require('fs');
55

6+
// Set up test helpers that were previously in setup.js
7+
global.testHelpers = {
8+
validPersonas: ['unemployment-benefits', 'parks-recreation', 'business-licensing', 'default'],
9+
10+
validateApiResponse: (response) => {
11+
// Handle both direct response objects and response bodies with different structures
12+
const body = response.body || response;
13+
if (body.message && body.message.content) {
14+
expect(typeof body.message.content).toBe('string');
15+
expect(body.message.content.length).toBeGreaterThan(0);
16+
} else if (body.response) {
17+
expect(typeof body.response).toBe('string');
18+
expect(body.response.length).toBeGreaterThan(0);
19+
} else if (typeof body === 'string') {
20+
expect(body.length).toBeGreaterThan(0);
21+
} else {
22+
// Flexible validation for various response formats
23+
expect(body).toHaveProperty('message');
24+
}
25+
}
26+
};
27+
28+
// Set up test data
29+
global.testData = {
30+
sampleMessages: {
31+
unemploymentbenefits: 'I need help applying for unemployment benefits. What documents do I need?',
32+
parksrecreation: 'What are the operating hours for the community center?',
33+
businesslicensing: 'I need to apply for a restaurant business license. What is the process?',
34+
default: 'I need help with city services. Can you direct me to the right department?',
35+
general: ['What services do you provide?', 'How can I contact customer support?', 'What are your hours?']
36+
}
37+
};
38+
639
// Import our server for testing
740
const createTestApp = () => {
841
const express = require('express');

api/__tests__/setup.js

Whitespace-only changes.

api/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@
6161
"/node_modules/",
6262
"/coverage/"
6363
],
64-
"setupFilesAfterEnv": ["<rootDir>/__tests__/setup.js"],
65-
"testTimeout": 10000,
64+
"testTimeout": 30000,
6665
"detectOpenHandles": true,
6766
"forceExit": false
6867
},

0 commit comments

Comments
 (0)