From 039edb592808aa84487bb84ecd27e18d4c97228b Mon Sep 17 00:00:00 2001 From: Alexander Borg Date: Mon, 15 Sep 2025 15:08:49 +0200 Subject: [PATCH] Fix jwt-token --- server/routes/health.js | 5 +++- server/tests/models/models.test.js | 42 ++++++++++++------------------ 2 files changed, 21 insertions(+), 26 deletions(-) diff --git a/server/routes/health.js b/server/routes/health.js index a5652ed..4c97bd5 100644 --- a/server/routes/health.js +++ b/server/routes/health.js @@ -4,16 +4,19 @@ const router = express.Router(); // Health check endpoint router.get('/', (req, res) => { const healthcheck = { + status: 'ok', uptime: process.uptime(), message: 'OK', timestamp: Date.now(), environment: process.env.NODE_ENV || 'development', - version: process.env.npm_package_version || '1.0.0' + version: process.env.npm_package_version || '1.0.0', + service: 'UAM-ILS Drone Detection System' }; try { res.status(200).json(healthcheck); } catch (error) { + healthcheck.status = 'error'; healthcheck.message = error; res.status(503).json(healthcheck); } diff --git a/server/tests/models/models.test.js b/server/tests/models/models.test.js index 14ee299..0e9f7b1 100644 --- a/server/tests/models/models.test.js +++ b/server/tests/models/models.test.js @@ -1,6 +1,6 @@ const { describe, it, beforeEach, afterEach, before, after } = require('mocha'); const { expect } = require('chai'); -const { setupTestEnvironment, teardownTestEnvironment, cleanDatabase, createTestTenant, createTestUser } = require('../setup'); +const { setupTestEnvironment, teardownTestEnvironment, cleanDatabase, createTestTenant } = require('../setup'); describe('Models', () => { let models, sequelize; @@ -23,7 +23,7 @@ describe('Models', () => { const userData = { username: 'testuser', email: 'test@example.com', - password_hash: '$2b$10$example.hash.for.testing.purposes.only', + password: 'hashedpassword', role: 'admin', tenant_id: tenant.id }; @@ -42,7 +42,7 @@ describe('Models', () => { const userData = { username: 'testuser', email: 'test@example.com', - password_hash: '\\\.hash.for.testing.purposes.only', + password: 'hashedpassword', tenant_id: tenant.id }; @@ -67,14 +67,14 @@ describe('Models', () => { const user1 = await models.User.create({ username: 'testuser', email: 'test1@example.com', - password_hash: '\\\.hash.for.testing.purposes.only', + password: 'hashedpassword', tenant_id: tenant1.id }); const user2 = await models.User.create({ username: 'testuser', email: 'test2@example.com', - password_hash: '\\\.hash.for.testing.purposes.only', + password: 'hashedpassword', tenant_id: tenant2.id }); @@ -89,7 +89,7 @@ describe('Models', () => { await models.User.create({ username: 'testuser', email: 'invalid-email', - password_hash: '\\\.hash.for.testing.purposes.only', + password: 'hashedpassword', tenant_id: tenant.id }); expect.fail('Should have thrown validation error'); @@ -105,7 +105,7 @@ describe('Models', () => { await models.User.create({ username: 'testuser', email: 'test@example.com', - password_hash: '\\\.hash.for.testing.purposes.only', + password: 'hashedpassword', role: 'invalid_role', tenant_id: tenant.id }); @@ -120,7 +120,7 @@ describe('Models', () => { const user = await models.User.create({ username: 'testuser', email: 'test@example.com', - password_hash: '\\\.hash.for.testing.purposes.only', + password: 'hashedpassword', tenant_id: tenant.id }); @@ -135,7 +135,7 @@ describe('Models', () => { const user = await models.User.create({ username: 'testuser', email: 'test@example.com', - password_hash: '\\\.hash.for.testing.purposes.only', + password: 'hashedpassword', tenant_id: tenant.id }); @@ -267,11 +267,11 @@ describe('Models', () => { }); const deviceWithTenant = await models.Device.findByPk(device.id, { - include: [models.Tenant] + include: [{ model: models.Tenant, as: 'tenant' }] }); - expect(deviceWithTenant.Tenant).to.exist; - expect(deviceWithTenant.Tenant.id).to.equal(tenant.id); + expect(deviceWithTenant.tenant).to.exist; + expect(deviceWithTenant.tenant.id).to.equal(tenant.id); }); it('should enforce unique device ID per tenant', async () => { @@ -404,10 +404,8 @@ describe('Models', () => { describe('AlertRule Model', () => { it('should create alert rule with valid data', async () => { const tenant = await createTestTenant(); - const user = await createTestUser({ tenant_id: tenant.id }); const ruleData = { tenant_id: tenant.id, - user_id: user.id, name: 'Test Rule', drone_type: 2, min_rssi: -70, @@ -425,10 +423,8 @@ describe('Models', () => { it('should have default values', async () => { const tenant = await createTestTenant(); - const user = await createTestUser({ tenant_id: tenant.id }); const rule = await models.AlertRule.create({ tenant_id: tenant.id, - user_id: user.id, name: 'Test Rule' }); @@ -438,12 +434,10 @@ describe('Models', () => { it('should validate priority values', async () => { const tenant = await createTestTenant(); - const user = await createTestUser({ tenant_id: tenant.id }); try { await models.AlertRule.create({ tenant_id: tenant.id, - user_id: user.id, name: 'Test Rule', priority: 'invalid_priority' }); @@ -455,10 +449,8 @@ describe('Models', () => { it('should associate with tenant', async () => { const tenant = await createTestTenant(); - const user = await createTestUser({ tenant_id: tenant.id }); const rule = await models.AlertRule.create({ tenant_id: tenant.id, - user_id: user.id, name: 'Test Rule' }); @@ -565,7 +557,7 @@ describe('Models', () => { describe('Heartbeat Model', () => { it('should create heartbeat with valid data', async () => { const heartbeatData = { - device_key: 'device_123_key', + key: 'device_123_key', device_id: 123, signal_strength: -50, battery_level: 85, @@ -575,14 +567,14 @@ describe('Models', () => { const heartbeat = await models.Heartbeat.create(heartbeatData); expect(heartbeat.id).to.exist; - expect(heartbeat.device_key).to.equal('device_123_key'); + expect(heartbeat.key).to.equal('device_123_key'); expect(heartbeat.device_id).to.equal(123); expect(heartbeat.battery_level).to.equal(85); }); it('should auto-set timestamp', async () => { const heartbeat = await models.Heartbeat.create({ - device_key: 'device_123_key', + key: 'device_123_key', device_id: 123 }); @@ -593,7 +585,7 @@ describe('Models', () => { it('should validate battery level range', async () => { try { await models.Heartbeat.create({ - device_key: 'device_123_key', + key: 'device_123_key', device_id: 123, battery_level: 150 // Invalid range }); @@ -610,7 +602,7 @@ describe('Models', () => { const user = await models.User.create({ username: 'testuser', email: 'test@example.com', - password_hash: '\\\.hash.for.testing.purposes.only', + password: 'hashedpassword', tenant_id: tenant.id });