From 2f275029eca7f51a426067c58b5b9f472f244492 Mon Sep 17 00:00:00 2001 From: Alexander Borg Date: Tue, 16 Sep 2025 06:40:52 +0200 Subject: [PATCH] Fix jwt-token --- server/tests/routes/detectors.test.js | 11 +++++++++++ server/tests/setup.js | 23 ++--------------------- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/server/tests/routes/detectors.test.js b/server/tests/routes/detectors.test.js index 5919645..5fb92e3 100644 --- a/server/tests/routes/detectors.test.js +++ b/server/tests/routes/detectors.test.js @@ -15,6 +15,17 @@ describe('Detectors Routes', () => { // Setup express app for testing app = express(); app.use(express.json()); + + // Add mock Socket.io middleware for tests + app.use((req, res, next) => { + req.io = { + emit: () => {}, // Mock emit function that does nothing + emitToDashboard: () => {}, + emitToDevice: () => {} + }; + next(); + }); + app.use('/detectors', detectorsRoutes); }); diff --git a/server/tests/setup.js b/server/tests/setup.js index 9511cb3..8399ba2 100644 --- a/server/tests/setup.js +++ b/server/tests/setup.js @@ -1,21 +1,5 @@ // IMPORTANT: Set environment variables FIRST, before any other imports -proces // Return test context - models = { - sequelize, - Device, - DroneDetection, - Heartbeat, - User, - AlertRule, - AlertLog, - Tenant, - ManagementUser - }; - - // Store models globally so routes can access them - global.__TEST_MODELS__ = models; - - return { sequelize, models };est'; +process.env.NODE_ENV = 'test'; process.env.JWT_SECRET = 'test-jwt-secret-key-for-testing-only'; process.env.DATABASE_URL = ':memory:'; process.env.DB_DIALECT = 'sqlite'; @@ -36,7 +20,7 @@ afterEach(() => { // Test database configuration const testDatabase = { dialect: 'sqlite', - storage: ':memory:', // In-memory database for fast tests + storage: './test.db', // Use same file database as models/index.js logging: false, // Disable SQL logging in tests sync: { force: true } // Always recreate tables for tests }; @@ -48,9 +32,6 @@ let models; * Setup test environment before all tests */ async function setupTestEnvironment() { - // Clear any existing global models - delete global.__TEST_MODELS__; - // Create test database connection sequelize = new Sequelize(testDatabase);