Fix jwt-token
This commit is contained in:
@@ -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);
|
||||
});
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user