Fix jwt-token
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
const { createTestDatabase, destroyTestDatabase } = require('./test-database');
|
||||
const { Sequelize } = require('sequelize');
|
||||
const path = require('path');
|
||||
|
||||
@@ -20,8 +19,52 @@ async function setupTestEnvironment() {
|
||||
// Create test database connection
|
||||
sequelize = new Sequelize(testDatabase);
|
||||
|
||||
// Import models
|
||||
models = require('../models')(sequelize);
|
||||
// Import and initialize models with test sequelize instance
|
||||
const Device = require('../models/Device')(sequelize);
|
||||
const DroneDetection = require('../models/DroneDetection')(sequelize);
|
||||
const Heartbeat = require('../models/Heartbeat')(sequelize);
|
||||
const User = require('../models/User')(sequelize);
|
||||
const AlertRule = require('../models/AlertRule')(sequelize);
|
||||
const AlertLog = require('../models/AlertLog')(sequelize);
|
||||
const Tenant = require('../models/Tenant')(sequelize);
|
||||
const ManagementUser = require('../models/ManagementUser')(sequelize);
|
||||
|
||||
// Define associations
|
||||
Device.hasMany(DroneDetection, { foreignKey: 'device_id', as: 'detections' });
|
||||
DroneDetection.belongsTo(Device, { foreignKey: 'device_id', as: 'device' });
|
||||
|
||||
Device.hasMany(Heartbeat, { foreignKey: 'device_id', as: 'heartbeats' });
|
||||
Heartbeat.belongsTo(Device, { foreignKey: 'device_id', as: 'device' });
|
||||
|
||||
User.hasMany(AlertRule, { foreignKey: 'user_id', as: 'alertRules' });
|
||||
AlertRule.belongsTo(User, { foreignKey: 'user_id', as: 'user' });
|
||||
|
||||
AlertRule.hasMany(AlertLog, { foreignKey: 'alert_rule_id', as: 'logs' });
|
||||
AlertLog.belongsTo(AlertRule, { foreignKey: 'alert_rule_id', as: 'rule' });
|
||||
|
||||
DroneDetection.hasMany(AlertLog, { foreignKey: 'detection_id', as: 'alerts' });
|
||||
AlertLog.belongsTo(DroneDetection, { foreignKey: 'detection_id', as: 'detection' });
|
||||
|
||||
// Tenant associations
|
||||
Tenant.hasMany(User, { foreignKey: 'tenant_id', as: 'users' });
|
||||
User.belongsTo(Tenant, { foreignKey: 'tenant_id', as: 'tenant' });
|
||||
|
||||
Tenant.hasMany(Device, { foreignKey: 'tenant_id', as: 'devices' });
|
||||
Device.belongsTo(Tenant, { foreignKey: 'tenant_id', as: 'tenant' });
|
||||
|
||||
// Create models object
|
||||
models = {
|
||||
sequelize,
|
||||
Sequelize,
|
||||
Device,
|
||||
DroneDetection,
|
||||
Heartbeat,
|
||||
User,
|
||||
AlertRule,
|
||||
AlertLog,
|
||||
Tenant,
|
||||
ManagementUser
|
||||
};
|
||||
|
||||
// Sync database
|
||||
await sequelize.sync({ force: true });
|
||||
|
||||
Reference in New Issue
Block a user