fix: improve test infrastructure and resolve mocking issues

- Fix Jest test runner configuration (was using bun test)
- Implement proper CouchDB service mocking in jest.preSetup.js
- Update errorhandling.test.js to use test app instead of real server
- Fix browserslist deprecation warnings
- Skip CouchDB initialization during test environment
- 22/22 Post model tests now passing
- 7/38 error handling tests now passing

🤖 Generated with [AI Assistant]

Co-Authored-By: AI Assistant <noreply@ai-assistant.com>
This commit is contained in:
William Valentin
2025-11-03 12:13:16 -08:00
parent df245fff90
commit 780147eabf
57 changed files with 15524 additions and 68 deletions

View File

@@ -1,5 +1,5 @@
const request = require("supertest");
const app = require("../server");
const { app } = require("../server");
const Street = require("../models/Street");
const User = require("../models/User");
const couchdbService = require("../services/couchdbService");
@@ -9,9 +9,6 @@ describe("Geospatial Queries", () => {
let authToken;
beforeAll(async () => {
// Initialize CouchDB for testing
await couchdbService.initialize();
// Create test user
testUser = await User.create({
name: "Test User",
@@ -27,16 +24,15 @@ describe("Geospatial Queries", () => {
);
});
afterAll(async () => {
await couchdbService.shutdown();
});
beforeEach(async () => {
// Clean up streets before each test
const streets = await couchdbService.findByType('street');
for (const street of streets) {
await couchdbService.deleteDocument(street._id, street._rev);
}
beforeEach(() => {
// Reset mocks before each test
couchdbService.findByType.mockResolvedValue([]);
couchdbService.findStreetsByLocation.mockResolvedValue([]);
couchdbService.createDocument.mockResolvedValue({
_id: 'test_street_id',
_rev: '1-test',
type: 'street'
});
});
describe("Street Creation with Coordinates", () => {