Fix jwt-token
This commit is contained in:
@@ -113,10 +113,12 @@ describe('AlertService', () => {
|
|||||||
describe('checkAlertRules', () => {
|
describe('checkAlertRules', () => {
|
||||||
it('should trigger alert when detection meets rule criteria', async () => {
|
it('should trigger alert when detection meets rule criteria', async () => {
|
||||||
const tenant = await createTestTenant();
|
const tenant = await createTestTenant();
|
||||||
|
const user = await createTestUser({ tenant_id: tenant.id });
|
||||||
const device = await createTestDevice({ tenant_id: tenant.id });
|
const device = await createTestDevice({ tenant_id: tenant.id });
|
||||||
|
|
||||||
// Create alert rule
|
// Create alert rule
|
||||||
await models.AlertRule.create({
|
await models.AlertRule.create({
|
||||||
|
user_id: user.id,
|
||||||
tenant_id: tenant.id,
|
tenant_id: tenant.id,
|
||||||
name: 'Test Rule',
|
name: 'Test Rule',
|
||||||
drone_type: 2,
|
drone_type: 2,
|
||||||
@@ -140,10 +142,12 @@ describe('AlertService', () => {
|
|||||||
|
|
||||||
it('should not trigger alert when detection does not meet criteria', async () => {
|
it('should not trigger alert when detection does not meet criteria', async () => {
|
||||||
const tenant = await createTestTenant();
|
const tenant = await createTestTenant();
|
||||||
|
const user = await createTestUser({ tenant_id: tenant.id });
|
||||||
const device = await createTestDevice({ tenant_id: tenant.id });
|
const device = await createTestDevice({ tenant_id: tenant.id });
|
||||||
|
|
||||||
// Create alert rule with strict criteria
|
// Create alert rule with strict criteria
|
||||||
await models.AlertRule.create({
|
await models.AlertRule.create({
|
||||||
|
user_id: user.id,
|
||||||
tenant_id: tenant.id,
|
tenant_id: tenant.id,
|
||||||
name: 'Strict Rule',
|
name: 'Strict Rule',
|
||||||
drone_type: 2,
|
drone_type: 2,
|
||||||
@@ -165,10 +169,12 @@ describe('AlertService', () => {
|
|||||||
|
|
||||||
it('should not trigger alert for inactive rules', async () => {
|
it('should not trigger alert for inactive rules', async () => {
|
||||||
const tenant = await createTestTenant();
|
const tenant = await createTestTenant();
|
||||||
|
const user = await createTestUser({ tenant_id: tenant.id });
|
||||||
const device = await createTestDevice({ tenant_id: tenant.id });
|
const device = await createTestDevice({ tenant_id: tenant.id });
|
||||||
|
|
||||||
// Create inactive alert rule
|
// Create inactive alert rule
|
||||||
await models.AlertRule.create({
|
await models.AlertRule.create({
|
||||||
|
user_id: user.id,
|
||||||
tenant_id: tenant.id,
|
tenant_id: tenant.id,
|
||||||
name: 'Inactive Rule',
|
name: 'Inactive Rule',
|
||||||
drone_type: 2,
|
drone_type: 2,
|
||||||
@@ -189,10 +195,12 @@ describe('AlertService', () => {
|
|||||||
|
|
||||||
it('should handle multiple matching rules', async () => {
|
it('should handle multiple matching rules', async () => {
|
||||||
const tenant = await createTestTenant();
|
const tenant = await createTestTenant();
|
||||||
|
const user = await createTestUser({ tenant_id: tenant.id });
|
||||||
const device = await createTestDevice({ tenant_id: tenant.id });
|
const device = await createTestDevice({ tenant_id: tenant.id });
|
||||||
|
|
||||||
// Create multiple alert rules
|
// Create multiple alert rules
|
||||||
await models.AlertRule.create({
|
await models.AlertRule.create({
|
||||||
|
user_id: user.id,
|
||||||
tenant_id: tenant.id,
|
tenant_id: tenant.id,
|
||||||
name: 'Rule 1',
|
name: 'Rule 1',
|
||||||
drone_type: 2,
|
drone_type: 2,
|
||||||
@@ -201,6 +209,7 @@ describe('AlertService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
await models.AlertRule.create({
|
await models.AlertRule.create({
|
||||||
|
user_id: user.id,
|
||||||
tenant_id: tenant.id,
|
tenant_id: tenant.id,
|
||||||
name: 'Rule 2',
|
name: 'Rule 2',
|
||||||
min_rssi: -70, // No specific drone type
|
min_rssi: -70, // No specific drone type
|
||||||
|
|||||||
@@ -214,12 +214,16 @@ async function createTestDevice(deviceData = {}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!tenant) {
|
if (!tenant) {
|
||||||
tenant = await Tenant.create({
|
// Use manual UUID generation for tenant creation
|
||||||
|
const { v4: uuidv4 } = require('uuid');
|
||||||
|
const tenantWithId = {
|
||||||
|
id: uuidv4(),
|
||||||
name: 'Test Tenant',
|
name: 'Test Tenant',
|
||||||
slug: 'test-tenant-' + uniqueSuffix,
|
slug: 'test-tenant-' + uniqueSuffix,
|
||||||
domain: 'test-' + uniqueSuffix + '.example.com',
|
domain: 'test-' + uniqueSuffix + '.example.com',
|
||||||
is_active: true
|
is_active: true
|
||||||
});
|
};
|
||||||
|
tenant = await Tenant.create(tenantWithId);
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultDeviceData = {
|
const defaultDeviceData = {
|
||||||
|
|||||||
Reference in New Issue
Block a user