Fix jwt-token
This commit is contained in:
@@ -265,42 +265,59 @@ describe('AlertService', () => {
|
||||
describe('logAlert', () => {
|
||||
it('should create alert log entry', async () => {
|
||||
const tenant = await createTestTenant();
|
||||
const user = await createTestUser({ tenant_id: tenant.id });
|
||||
const device = await createTestDevice({ tenant_id: tenant.id });
|
||||
const detection = await createTestDetection({ device_id: device.id });
|
||||
|
||||
const alertData = {
|
||||
// Create a test alert rule
|
||||
const rule = await models.AlertRule.create({
|
||||
user_id: user.id,
|
||||
tenant_id: tenant.id,
|
||||
rule_name: 'Test Alert',
|
||||
threat_level: 'high',
|
||||
message: 'Test alert message'
|
||||
};
|
||||
min_rssi: -80,
|
||||
drone_type: 2,
|
||||
alert_channels: ['sms'],
|
||||
sms_phone_number: '+1234567890',
|
||||
is_active: true
|
||||
});
|
||||
|
||||
const logEntry = await alertService.logAlert(detection, alertData);
|
||||
const logEntry = await alertService.logAlert(rule, detection, 'sms', '+1234567890');
|
||||
|
||||
expect(logEntry).to.exist;
|
||||
expect(logEntry.device_id).to.equal(device.id);
|
||||
expect(logEntry.rule_name).to.equal('Test Alert');
|
||||
expect(logEntry.threat_level).to.equal('high');
|
||||
expect(logEntry.alert_rule_id).to.equal(rule.id);
|
||||
expect(logEntry.detection_id).to.equal(detection.id);
|
||||
expect(logEntry.alert_type).to.equal('sms');
|
||||
expect(logEntry.status).to.equal('sent');
|
||||
});
|
||||
|
||||
it('should include detection and threat data in log', async () => {
|
||||
const device = await createTestDevice();
|
||||
const tenant = await createTestTenant();
|
||||
const user = await createTestUser({ tenant_id: tenant.id });
|
||||
const device = await createTestDevice({ tenant_id: tenant.id });
|
||||
const detection = await createTestDetection({
|
||||
device_id: device.id,
|
||||
drone_type: 2,
|
||||
rssi: -50
|
||||
});
|
||||
|
||||
const alertData = {
|
||||
// Create a test alert rule
|
||||
const rule = await models.AlertRule.create({
|
||||
user_id: user.id,
|
||||
tenant_id: tenant.id,
|
||||
rule_name: 'Critical Alert',
|
||||
threat_level: 'critical',
|
||||
message: 'Critical threat detected'
|
||||
};
|
||||
min_rssi: -80,
|
||||
drone_type: 2,
|
||||
alert_channels: ['sms'],
|
||||
sms_phone_number: '+1234567890',
|
||||
is_active: true
|
||||
});
|
||||
|
||||
const logEntry = await alertService.logAlert(detection, alertData);
|
||||
const logEntry = await alertService.logAlert(rule, detection, 'sms', '+1234567890');
|
||||
|
||||
expect(logEntry.drone_type).to.equal(2);
|
||||
expect(logEntry.rssi).to.equal(-50);
|
||||
expect(logEntry.drone_id).to.equal(detection.drone_id);
|
||||
expect(logEntry.alert_rule_id).to.equal(rule.id);
|
||||
expect(logEntry.detection_id).to.equal(detection.id);
|
||||
expect(logEntry.alert_type).to.equal('sms');
|
||||
expect(logEntry.status).to.equal('sent');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user