Fix jwt-token

This commit is contained in:
2025-09-15 12:58:12 +02:00
parent e609cc4541
commit 4f1ccba418
2 changed files with 23 additions and 15 deletions

View File

@@ -23,7 +23,7 @@ describe('Models', () => {
const userData = {
username: 'testuser',
email: 'test@example.com',
password: 'hashedpassword',
password_hash: '$2b$10$example.hash.for.testing.purposes.only',
role: 'admin',
tenant_id: tenant.id
};
@@ -42,7 +42,7 @@ describe('Models', () => {
const userData = {
username: 'testuser',
email: 'test@example.com',
password: 'hashedpassword',
password_hash: '\\\.hash.for.testing.purposes.only',
tenant_id: tenant.id
};
@@ -67,14 +67,14 @@ describe('Models', () => {
const user1 = await models.User.create({
username: 'testuser',
email: 'test1@example.com',
password: 'hashedpassword',
password_hash: '\\\.hash.for.testing.purposes.only',
tenant_id: tenant1.id
});
const user2 = await models.User.create({
username: 'testuser',
email: 'test2@example.com',
password: 'hashedpassword',
password_hash: '\\\.hash.for.testing.purposes.only',
tenant_id: tenant2.id
});
@@ -89,7 +89,7 @@ describe('Models', () => {
await models.User.create({
username: 'testuser',
email: 'invalid-email',
password: 'hashedpassword',
password_hash: '\\\.hash.for.testing.purposes.only',
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: 'hashedpassword',
password_hash: '\\\.hash.for.testing.purposes.only',
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: 'hashedpassword',
password_hash: '\\\.hash.for.testing.purposes.only',
tenant_id: tenant.id
});
@@ -135,7 +135,7 @@ describe('Models', () => {
const user = await models.User.create({
username: 'testuser',
email: 'test@example.com',
password: 'hashedpassword',
password_hash: '\\\.hash.for.testing.purposes.only',
tenant_id: tenant.id
});
@@ -404,8 +404,10 @@ 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,
@@ -423,8 +425,10 @@ 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'
});
@@ -434,10 +438,12 @@ 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'
});
@@ -449,8 +455,10 @@ 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'
});
@@ -557,7 +565,7 @@ describe('Models', () => {
describe('Heartbeat Model', () => {
it('should create heartbeat with valid data', async () => {
const heartbeatData = {
key: 'device_123_key',
device_key: 'device_123_key',
device_id: 123,
signal_strength: -50,
battery_level: 85,
@@ -567,14 +575,14 @@ describe('Models', () => {
const heartbeat = await models.Heartbeat.create(heartbeatData);
expect(heartbeat.id).to.exist;
expect(heartbeat.key).to.equal('device_123_key');
expect(heartbeat.device_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({
key: 'device_123_key',
device_key: 'device_123_key',
device_id: 123
});
@@ -585,7 +593,7 @@ describe('Models', () => {
it('should validate battery level range', async () => {
try {
await models.Heartbeat.create({
key: 'device_123_key',
device_key: 'device_123_key',
device_id: 123,
battery_level: 150 // Invalid range
});
@@ -602,7 +610,7 @@ describe('Models', () => {
const user = await models.User.create({
username: 'testuser',
email: 'test@example.com',
password: 'hashedpassword',
password_hash: '\\\.hash.for.testing.purposes.only',
tenant_id: tenant.id
});